font of row and column labels

Jul 23, 2009 at 8:13 PM

I'm not sure if this is an intentional change or not, so I wanted to post it here first before entering in an issue into the issue tracker.  I downloaded the latest committed version from SVN today because I'm running into memory issues and wanted to test out the new method of applying styles to columns as a whole rather than cell by cell - but unrelated to that, I noticed that in my generated Excel files, the row and column labels (A, B, C, ... and 1, 2, 3, ...) are printing in Calibri rather than Arial.  The below sample prints the row and column labels in Arial in PHPExcel 1.6.7, but in the latest SVN version, it prints them in Calibri.  Is this an intentional change?  I am running Excel 2003.

$workbook = new PHPExcel;
$workbook->getActiveSheet()->getDefaultStyle()->getFont()->setName('Arial');

$writer = PHPExcel_IOFactory::createWriter($workbook, 'Excel5');
$writer->save('write.xls');

Thanks for your help.

Ryan

Developer
Jul 23, 2009 at 11:27 PM

>> The below sample prints the row and column labels in Arial in PHPExcel 1.6.7,
>> but in the latest SVN version, it prints them in Calibri.  Is this an intentional change?

This was not an intentional change. Will be fixed in tomorrows source code release.

Some remarks:

1.

It is intentional in PHPExcel 1.7.0 that Calibri 11 is used as the default font for (row/column labels and cells) for both the Excel2007 and Excel5 writer. In PHPExcel 1.6.7 Arial 10 was used by Excel5 writer and Calibri 10 was used by Excel2007 writer.

2.

Another change in PHPExcel 1.7.0 compared to 1.6.7 is the default font (used for row/column lables and cells).

In PHPExcel 1.7.0 you set the default font like this:

$workbook->getDefaultStyle()->getFont()->setName('Arial');
$workbook->getDefaultStyle()->getFont()->setSize(10);

In MS Office Excel 2007, this corresponds to Excel Options > Popular > When creating new workbooks > Use this font
http://www.learnthat.com/software/learn/1160/Microsoft_Excel_2007_Tutorial/page/6/

In PHPExcel 1.6.7 there was a default style for each sheet. This concept has been dropped in PHPExcel 1.7.0. The reason for this is that the Excel file format does not support such a default sheet style and it was giving problems during further development of the library. In PHPExcel 1.7.0, when you try to set the default style for any sheet, it will be set for the entire workbook. (Therefore, I suggest that you update your code as shown above)

3.

When you generate Excel files from a template (xls or xlsx) using PHPExcel, default font should of course survive. That means if you for example read an xls template that has Verdana 20 as default workbook font, it will still have that default font after a plain read/write.

Jul 28, 2009 at 2:43 PM

Thanks for your help.  I will update my code going forward to set the default font on the workbook as a whole, rather than a default style per sheet.  I just downloaded the latest source code release 28250, but the row and column labels are still coming up in Calibri rather than Arial.  Should your change be up now?  The script I tried running was:

$workbook = new PHPExcel;
$workbook->getDefaultStyle()->getFont()->setName('Arial');
$workbook->getDefaultStyle()->getFont()->setSize(10);

$writer = PHPExcel_IOFactory::createWriter($workbook, 'Excel5');
$writer->save('write.xls');

Developer
Jul 28, 2009 at 5:29 PM

>> but the row and column labels are still coming up in Calibri rather than Arial.

I just tried your test with with latest source code, but it was working ok and showing Arial when I opened the file in Microsoft Office Excel 2007.

Look at this screenshot:
http://img194.imageshack.us/img194/4249/microsoftexcelwritexlsk.png

Do you have any idea what is wrong?

Jul 28, 2009 at 7:24 PM

Sorry, yes, it is working correctly.  I just realized my code was pulling in a different version of PHPExcel I had in my include path rather than the latest code I downloaded this morning.  Thanks again for your help.