我正在使用PHPExcel導出數據以供下載。打開下載的文件時,如果單元格數量很大,則會顯示「#######」而不是數值。我試過setAutoSize()
每列,然後調用$sheet->calculateColumnWidths()
但它仍然沒有改變。我看到calculateColumnWidths()at here,@Mark Baker說「calculateColumnWidths()增加了大概5%的值,以確保整列適合」。如果細胞數長度超過5%,似乎DOEN的解決了這個問題如何PHPExcel設置自動列寬度
UPDATE 這是我的功能,自動調整大小列:
function autoFitColumnWidthToContent($sheet, $fromCol, $toCol) {
if (empty($toCol)) {//not defined the last column, set it the max one
$toCol = $sheet->getColumnDimension($sheet->getHighestColumn())->getColumnIndex();
}
for($i = $fromCol; $i <= $toCol; $i++) {
$sheet->getColumnDimension($i)->setAutoSize(true);
}
$sheet->calculateColumnWidths();
}
您應用哪種自動調整方法計算?大約還是精確?你在使用任何特定的字體嗎?或大膽/斜體樣式?這個數字有多遠?也許增加10%會好於5%。 –
@MarkBaker我已經更新了我的問題的示例代碼。我使用ColumnDimension類的setAutoSize()。 – Davuz