php PHPExcel 设置列宽
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12041844/
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
PHPExcel set column width
提问by Amna Ahmed
I am setting column width for a .csv file using
我正在使用 .csv 文件设置列宽
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(50);
But i cannot see any change in column A's width, what am i doing wrong?
但是我看不到 A 列的宽度有任何变化,我做错了什么?
回答by Rolland
First, disable autosize:
首先,禁用自动调整大小:
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setAutoSize(false);
Now, you can set:
现在,您可以设置:
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth("50");
回答by Mark Baker
Assuming you're using the CSV Writer.
假设您使用的是 CSV Writer。
CSV files do not support anyformatting, just data, so column width (which is formatting) cannot be applied when you write a CSV file
CSV 文件不支持任何格式,仅支持数据,因此在编写 CSV 文件时无法应用列宽(即格式化)

