PHPExcel设置默认列宽

今天,我对excelphp有一点问题. 我想手动设置列的默认宽度,并且一次只能设置一次.

我在stackoverflow上也找到了一些解决方案,建议更改每个单列的值(例如,在循环中).

但是我想用一个命令来完成它.

解决方案

浏览源代码后,我发现了以下解决方案:

$phpExcelObject->getActiveSheet()->getDefaultColumnDimension()
    ->setWidth($myCustomWidth);

我希望这对其他人有帮助;)

  • 原文

Today I had a little problem with excelphp. I wanted to set the default width of the columns manually and only one single time.

I found a few solutions also here on stackoverflow which suggested to change the value for every single column (e.g. within a loop).

But I wanted to do it with a single command.

解决方案

After browsing the source code I found out the following solution:

$phpExcelObject->getActiveSheet()->getDefaultColumnDimension()
    ->setWidth($myCustomWidth);

I hope that this helps anybody else ;)

以下自己记录:

#设置单元格宽高
$objPHPExcel->getActiveSheet()->getDefaultRowDimension()->setRowHeight(20);#设置单元格行高
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(40);#设置单元格宽度
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(15);

おすすめ

転載: blog.csdn.net/amberom/article/details/121576738