How to formatting Excel Sheet cells using PHP - php

Please help me about my doubts on excel and php. I need to do the following process on excel report generation using php
to change cell's font styles
to change cell's BG color
to change cell's width

Try PHPExcel. I started using it few days ago and it works very good.

With PHPExcel
http://phpexcel.codeplex.com/wikipage?title=Features
http://phpexcel.codeplex.com/wikipage?title=Examples
With PEAR Spreadsheet Excel Writer
Format::setBgColor – Sets the cell's background color
Format::setFontFamily – Sets the font family.
Worksheet::setColumn – Set the width of a single column or a range of columns.

I'd definitely recommend PHPExcel as well, and it may well supercede the SEW within the PEAR repository

Related

PHPExcel - How can i change color, border and background of chart using phpexcel library?

I am working with PHPExcel library, I am not able to change the color of the graph.
let me know if anyone have a solution to it?
Check in this screen I want to change colors which are blue, red and green:
The current release of PHPExcel does not support to do so.
Take a loot at this question, there are a few workarounds mentioned.

Can PHPExcel add a sheet chart (as opposed to embedded chart)?

At the moment of this writing the current version of PHPExcel is version 1.8.0. I know how to make a chart and embed it in a worksheet, I basically followed the provided example.
Excel allows to either embed a chart into a worksheet or otherwise make a chart sheet. A chart sheet has it's own 'tab' in Excel and Excel keeps the chart scaled to the available size in the window.
Now what I would like to know is: how to add a chart sheet with PHPExcel? Is this possible with PHPExcel 1.8.0 using the 'Excel2007' writer?
As stated by #MarkBaker in the comments, the answer is simply "No" (at least not in version 1.8.1).
In my use case I was using PHP to generate an Excel workbook based on some processed data from different sources. What I did is to add VBA in Sub Workbook_Open() on the generated workbook to move the chart from a worksheet to it's own chart sheet. Then I used PHPExcel->getMacrosCode() to export the binary string of macro code to some file.
Now when generating files I add that binary string with PHPExcel->getMacrosCode(String) and save it as .xlsm instead of .xlsx. It is a bit of a hassle, but this is how I work around this problem for me.
Note that depending on your use case you might also need to generate a certificate to sign the code, to allow your user to always trust macros.

Is it possible to set the width of one cell alone without affecting other cells in phpExcel?

Is it possible to set the width of one cell alone without affecting other cells?
I am generating a pdf file using phpexcel.
I need to set the width of cell A1 to 40.
Tried this
$objPHPExcel->getActiveSheet()
->getColumnDimension('A')
->setWidth(40);
It does affect the entire column .
No you can't, in exactly the same way that you can't in MS Excel, Open/Libre Office Calc, or in Gnumeric.... PHPExcel tries to replicate the functionality of these spreadsheet packages, not the tables in Word.
You can, perhaps, merge cells to achieve what you want
it seems you cannot change individual cell see https://phpexcel.codeplex.com/discussions/448594
not sure if it fits your need , anyway you can remove the right border from cell so that two adiacent cells looks like one, as shown in this code

How can i format the excel report though php application

How can i format the excel report though php application
I am able to generate the excel report in php but how can i do the formatting changes in the excel.
eg. I have to add image in excel.
Red borders to columns.
some background color to excel
Change the font color
Help appriciated
I don't think it is directly possible without any libraries.
Have a look at PHPExcel, You will be able to do what you are looking for.
Credits to Mark Baker.
Tougher Way
You will need to generate XHTML from your Excel document, After that you need to search and parse for tags and do your formatting and stuff.

php generate image from excel cell range

I have an excel sheet. Its Cells can contain data and graph. I need to generate an image from the cells between a fixed range(for example: A1 to K19).
I found one solution to this problem with ASP.NET: Microsoft.Office.Interop.Excel. It provides method Range.CopyPicture() and Chart.Paste(). I need to implement this using PHP. Any solution, suggestion or direction will be appreciated.
For range A1 to B2, image can be like :
I would recommend you look into PHPExcel. It can read xls and xlsx files; after reading them you are able to create images from text just like you did before.

Categories