2016年2月14日 星期日

[PHP] PHPExcel auto height not working



foreach($objPHPExcel->getActiveSheet()->getRowDimensions() as $rd) {
    $rd->setRowHeight(-1);
}

自動欄高語法無法執行 , 參考以下內容修改 PHPExcel/Writer/Excel2007/Worksheet.php 程式

加入紅字區段

private function _writeSheetData(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null, $pStringTable = null)
(...)
                    // Row dimensions
                    if ($rowDimension->getRowHeight() >= 0) {
                        $objWriter->writeAttribute('customHeight', '1');
                        $objWriter->writeAttribute('ht', PHPExcel_Shared_String::FormatNumber($rowDimension->getRowHeight()));
                    } else {
                        $objWriter->writeAttribute('customHeight', 'false');
                        $objWriter->writeAttribute('ht', '0');
                    }
(...)




解決方式參考來源
https://phpexcel.codeplex.com/discussions/429322