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);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值