使用PHP_XLSXWriter设置列宽

问题描述 投票:1回答:2

我无法弄清楚如何使用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]] );

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

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

php xls
2个回答
2
投票

移动选项数组中的suppress_row选项:

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

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] );
© www.soinside.com 2019 - 2024. All rights reserved.