Losing Style-Information when creating more than 1 XLS-File

Topics: Developer Forum, User Forum
May 20, 2009 at 2:02 PM
Edited May 20, 2009 at 5:42 PM

Hello !

First of all: PHPExcel is a great class!
But I think I have found an error. Everytime when I want to create more than 1 xls-File my Cells losing their Style-Attributes!

The cell A1 in first file (FileNr1.xls) has the given Style (Tahoma, 18, bold) but the second File (FileNr2.xls) has the default Style (Calibri, 10).

How can I fix this? Is it an error?

I tried $XLS = NULL and unset($XLS) but nothing worked...

Please help me, Thank you!

==============
This is my code with PHPExcel Version 1.6.7

<?php
include("/php_www/Backend/__globals/_extPHP/phpexcel/PHPExcel.php");
include("/php_www/Backend/__globals/_extPHP/phpexcel/PHPExcel/Writer/Excel5.php");

$XLS = new PHPExcel();
$Sheet = $XLS->getActiveSheet();
$Sheet->setCellValue('A1', "File Nr 1");
$Sheet->getStyle('A1')->getFont()->setName("Tahoma");
$Sheet->getStyle('A1')->getFont()->setsize(18);
$Sheet->getStyle('A1')->getFont()->setBold(true);
$Writer = new PHPExcel_Writer_Excel5($XLS);
$Writer->save("FileNr1.xls");

$XLS = new PHPExcel();
$Sheet = $XLS->getActiveSheet();
$Sheet->setCellValue('A1', "File Nr 2");
$Sheet->getStyle('A1')->getFont()->setName("Tahoma");
$Sheet->getStyle('A1')->getFont()->setsize(18);
$Sheet->getStyle('A1')->getFont()->setBold(true);
$Writer = new PHPExcel_Writer_Excel5($XLS);
$Writer->save("FileNr2.xls");
?>

I think, the same bug (from another user) is here described: http://phpexcel.codeplex.com/WorkItem/View.aspx?WorkItemId=8787

Developer
May 20, 2009 at 7:15 PM

I just tested your script, you are indeed right that this is happening with PHPExcel 1.6.7.

Since PHPExcel 1.6.7 changes have been made how styles are treated in the library. So this is no longer happening with latest source code. You can download latest source code from here:
http://phpexcel.codeplex.com/SourceControl/ListDownloadableCommits.aspx

 

May 21, 2009 at 10:23 AM

Thank you!

With the latest SourceCode my script runs perfect!