Cell format changing after deleting row

Topics: Developer Forum, Project Management Forum, User Forum
Dec 2, 2012 at 7:06 PM

Hi All,

I'm having a little problem with a file that is generated using PHPExcel.  The site I am using pulls data from an SQL database and puts it on a spreadsheet.  Some of the data that is pulled are SKU numbers beginning with a 0.  When they are initially written to the sheet, the cells are formatted as text, and they display fine, but when it becomes necessary to delete a row, all the cells below the deleted line change back to default format, and SKU numbers beginning with 0 are no longer displaying correctly.  Below is the code snippet I have used to try to set the cells back to text format instead of numbers:

$objPHPExcel->getActiveSheet()->getStyle('B2:B500')->getNumberFormat()->setFormatCode(PHPExcel_Style_Numberformat::FORMAT_TEXT);
$objPHPExcel->getActiveSheet()->removeRow($cellRM);
$objPHPExcel->getActiveSheet()->getStyle('B2:B500')->getNumberFormat()->setFormatCode(PHPExcel_Style_Numberformat::FORMAT_TEXT);

And here is the snippet I used in a previous file to set the entire sheet to text:

$objPHPExcel->getDefaultStyle()->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);

Can anyone offer a suggestion for what I may be doing wrong, or perhaps if this is a bug?  

Thanks for reading!

Dec 4, 2012 at 2:41 AM

I fixed my problem, if anyone else ever finds themselves in my shoes, and finds this thread, here's what I did:

Change the way the cells are written from regular to rich text.  See the code snippet below:

$objRichText = new PHPExcel_RichText( $objPHPExcel->getActiveSheet()->getCell('B1') );
$objRichText->createText('01234');

Thanks!