Cell formatting lost completely

Topics: Developer Forum
Aug 20, 2011 at 10:49 AM


I have a Excel FIle. I open it using PHPExcel, save it back with a new name, and all cells lose their formatting. No Cell Borders, No Cell Background, Just the text, nothing else.

I created a new excel file in Open Office, bg filled the first cell, put some text, again went through the phpexcel code and again the bg fill vanished.

Here is my code.

$folder = "files/";
$template = "MS2.xls";
$excel_readers = array('excel' => 'Excel5' , 'excel2003' => 'Excel2003XML' , 'excel2007' => 'Excel2007');
$reader = PHPExcel_IOFactory::createReader($excel_readers['excel']);
$excel = $reader->load($folder.$template);

$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel5');
$write_path = "$folder/MS.xls";

I need to preserve all the cell formatting.

Aug 22, 2011 at 12:52 PM

Try removing this line...


Aug 28, 2011 at 4:56 AM

Thanks that worked. But because the Excel sheet is very large it takes more time to generate the file compared to when I manually assign styles. Any solution for that ?