我正在使用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