使用PHP_XLSXWriter设置列宽

时间:2018-09-17 08:35:49

标签: php xls

我不知道如何使用PHP_XLSXWriter设置列宽。

我尝试过:

$widths = array(10,20,30,40,50,60);
$col_options = array('widths'=>$widths);
$writer->writeSheetHeader($sheet, $header, $suppress_header_row = true, $col_options );

和:

$writer->writeSheetHeader($sheet, $header, $suppress_header_row = true, $col_options = ['widths'=>[10,20,30,40,50,60]] );

没有人在工作。我在做什么错了?

顺便说一句,如果有一种方法可以自动将列的宽度调整为数据长度,那就太好了!

2 个答案:

答案 0 :(得分:2)

在选项数组中移动prevent_row选项:

$writer->writeSheetHeader($sheet, $header, $col_options = ['widths'=>[10,20,30,40,50,60], 'suppress_row'=>true] );

答案 1 :(得分:1)

尝试不使用$ supress_header_row参数:

$widths = array(10,20,30,40,50,60);
$writer->writeSheetHeader($sheet, $header, $col_options = ['widths'=>[10,20,30,40,50,60]] );

更新: 相当确定要取消将您现在添加到col_options的第一行:

$writer->writeSheetHeader($sheet, $header, $col_options = ['widths'=>[10,20,30,40,50,60], 'suppress_row' => 1] );