0

I am using PHPExcel to read a template, write and edit some things and then save it using a different name. Some of the rows in the template already have "wrap text" applied to them so that the row can auto adjust its height. The problem arise when I need to insert data to some row and then merge it with another row. From several experiment that I have done, the row seemed to automatically adjust its height based on my data, but then it will revert to its original height when I merge them with another row. Here is the snippet of the code that I use

$reader = PHPExcel_IOFactory::createReader('Excel2007');
$frTemplate = $reader->load("../modern/document/Template/FR-006 
                            Template.xlsx");
$frTemplate->setActiveSheetIndex(1);

$highlightRow = 6+$t;

$frTemplate->getActiveSheet()->setCellValueExplicitByColumnAndRow(8, 6+$t, 
                                $change['reference']);
$frTemplate->getActiveSheet()->setCellValueExplicitByColumnAndRow(9, 6+$t, 
                                substr($change['argument'], 6));

$range = "I".$highlightRow.":"."I".($highlightRow+1);
$frTemplate->getActiveSheet()->mergeCells($range);

$range = "J".$highlightRow.":"."J".($highlightRow+1);
$frTemplate->getActiveSheet()->mergeCells($range);

I try to get the height of the row after auto resize, hoping that maybe I can resize it back after merging it, but I only get -1 as a return value. From what I understand, -1 is assigned to row height so that it can be auto resized.

So, basically I have two questions:

  1. Is the height of a row is reset after it is merged with another row? Or is there anything wrong with my code?
  2. Is there any way to get the height of a row after it is resized automatically?

Thanks

  • have you tried to merge the cells first, and then assign the value? – am05mhz Oct 19 '17 at 07:13
  • @am05mhz I have tried merging the cell beforehand in the template (i.e the cells have already been merged when the template is loaded) but it does not work. I'll try to left it un-merged in template instead and merge the after loading the template. Will be back to you with the result later. Thanks! – Rizky Prasetya Oct 19 '17 at 07:29
  • @am05mhz I have tried your suggestion and it is still not working :( – Rizky Prasetya Oct 19 '17 at 08:13
  • seems like a duplicate of https://stackoverflow.com/questions/13313048/phpexcel-dynamic-row-height-for-merged-cells?rq=1 or https://stackoverflow.com/questions/13644210/phpexcel-row-autoheight-on-merged-cells-w-wraptext?rq=1 – am05mhz Oct 19 '17 at 14:53
  • @am05mhz looks like you're right, I didn't search enough apparently. Thanks! – Rizky Prasetya Oct 23 '17 at 03:50

0 Answers0