Cell comments ignored in Excel5 writer

Topics: Developer Forum, User Forum
Nov 27, 2009 at 2:44 PM

Hello !

I have been trying to write comments in a simple sheet but they don't seem to be written in the file by Excel5_Writer.

$workbook = new PHPExcel();
	
$workbook->setActiveSheetIndex(0);
	
$workbook->getActiveSheet()->setCellValue('A1' , 'a' );
$workbook->getActiveSheet()->setCellValue('A2' , 'b' );
$workbook->getActiveSheet()->setCellValue('A3' , 'c' );
$workbook->getActiveSheet()->setCellValue('B1' , 'd' );
$workbook->getActiveSheet()->setCellValue('B2' , 'e' );
$workbook->getActiveSheet()->setCellValue('B3' , 'f' );
$workbook->getActiveSheet()->setCellValue('C1' , 'g' );
$workbook->getActiveSheet()->setCellValue('C2' , 'h' );
$workbook->getActiveSheet()->setCellValue('C3' , 'i' );
	
$workbook->getActiveSheet()->getComment('B2')->setAuthor('me');
$workbook->getActiveSheet()->getComment('B2')->setVisible('true');
$workbook->getActiveSheet()->getComment('B2')->getText()->createTextRun('TEST COMMENT');
	
$writer = new PHPExcel_Writer_Excel5( $workbook );	
$writer->save('test.xls');

I took a look in the code and I saw that a private method _writeNote() does exist but is never called. I tried to call it when writing data to the tmp file but did not succeed in creating a comment.

If somebody managed to include comments on cells in a XLS file, I would be very interested in knowing how to do it.

Developer
Jan 22, 2010 at 6:09 AM

You are right that comments are not yet supported in Excel5 writer.

The _writeNote() method is a left over method from the original PEAR::Spreadsheet_Excel_Writer which did support notes, but only for BIFF5 (Excel 5.0 / Excel 95) files which is not so useful.

Problem with BIFF8 (Excel 97 / XP / 2003) is that Microsoft changed the way notes were stored so it got way more complicated. PHPExcel always saves as BIFF8.

PEAR::Spreadsheet_Excel_Writer allows you to save as BIFF8 via the setVersion(8) method (without support for comments/notes), but that mode is unfortunately very buggy.

I hope we can one day add support for notes in PHPExcel for xls files, but it is not so easy.

Jun 4, 2010 at 9:31 PM
Edited Jun 8, 2010 at 3:57 AM

Does anyone know how to read a comment from a cell?