laravel 自动调整 Excel 列宽

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33270210/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:33:25  来源:igfitidea点击:

Auto size Excel column width

phpexcellaravel

提问by Cihan Küsmez

I'm using Laravel Excel pluginand have a problem with column widths. See the picture below, you can see the mistake:

我正在使用 Laravel Excel 插件并且在列宽方面有问题。看下图,可以看出错误:

enter image description here

在此处输入图片说明

Here is the correct view:

下面是正确的观点:

enter image description here

在此处输入图片说明

I tried $sheet->setAutoSize('true');but it is not working.

我试过了,$sheet->setAutoSize('true');但它不起作用。

How can I auto size column to the maximum content width of any cell in that column?

如何将列自动调整为该列中任何单元格的最大内容宽度?

回答by Eric V.

$sheet->getColumnDimension($column)->setAutoSize(true) ;

Duplicate of PHPExcel auto size column width

PHPExcel自动调整列宽的重复项