Modify cell = style erased

Topics: Developer Forum, User Forum
Jun 13, 2012 at 1:31 PM
Edited Jun 13, 2012 at 3:15 PM


When I modify a value of cellule, my style (borders, alignments...) is erased.

So I have to remake the style with phpExcel but there isn't another solution ?


Jun 13, 2012 at 8:08 PM

This shouldn't occur, and I have been unable to replicate it. Can you please generate a simple script that will demonstrate this problem so that I can investigate. Thanks.

Jun 14, 2012 at 1:06 PM
Edited Jun 14, 2012 at 1:10 PM

There are borders (for example) around cell k9 but after modifications, all styles are removed (font size, font style, borders...).

This my script simplified :


// Création de l'objet Reader pour un fichier Excel 2007
$objReader = new PHPExcel_Reader_Excel5();

// Lecture du fichier.
$objPHPExcel = $objReader->load("../originaux/original_notice.xls");

'name'      =>  'Times News Roman',
'size'      =>  12,
'bold'      => false)));

// Modification

$objPHPExcel->getActiveSheet()->setCellValue('k9', 'test');

$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);

Jun 14, 2012 at 2:32 PM

I still can't replicate this unless I set readDataOnly to true... when I would expect styling to be lost because I'm telling the reader to ignore styling.

Unfortunately, if I can't replicate a problem, it's almost impossible to fix because it becomes a case of guessing.

Jun 14, 2012 at 3:15 PM
Edited Jun 14, 2012 at 3:15 PM


So, to reset my borders i write :


Is there another faster method ?

Jun 14, 2012 at 6:00 PM

I've not worked with formatting Excel 5 files but don't quite understand why your styles are being lost. If you remove the lines writing data are your styles preserved? What about removing the lines to set the default style. Anyway, something like:

    'borders' => array(
      'bottom' => array('style' => PHPExcel_Style_Border::BORDER_THIN),
      'left' => array('style' => PHPExcel_Style_Border::BORDER_THIN),
      'right' => array('style' => PHPExcel_Style_Border::BORDER_HAIR),
      'top' => array('style' => PHPExcel_Style_Border::BORDER_HAIR),

should be be a faster way to set styles. Faster still if you operate on the range of cells that you want to reset instead of individually (there are also 'vertical' and 'horizontal' border types to make use of for the internal borders)

Jun 14, 2012 at 8:25 PM

If I remove the lines writing data, my styles are preserved... I don't understand :(