【问题标题】:Setting columns width with PHP_XLSXWriter使用 PHP_XLSXWriter 设置列宽
【发布时间】:2018-09-17 08:35:48
【问题描述】:

我不知道如何使用 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


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      尝试不使用 $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] );
      

      【讨论】:

      • 它有效,但我现在在我的表的第一行有 0 1 2 3 ...?
      • 查看更新后的答案,了解如何在 col_options 中设置 suppress_row。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-12
      • 2020-11-28
      • 2017-05-12
      • 2017-09-13
      相关资源
      最近更新 更多