我正在使用PHPExcel导出数据进行下载。当打开具有大数字的单元格时,它会显示“#######”而不是数值。我尝试了对每一列使用
setAutoSize()
,然后调用$sheet->calculateColumnWidths()
,但仍然没有改变。我在这里看到calculateColumnWidths(),@Mark Baker说“calculateColumnWidths()增加5%的值,以确保整个列都适合”。如果单元格中数字的长度超过5%,则似乎无法解决问题。
更新:
这是我的自动调整列宽函数: 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();
}