4

PHPExcel 页面边距设置

 1 year ago
source link: http://abcdxyzk.github.io/blog/2022/12/29/lang-php-margin/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

PHPExcel 页面边距设置

2022-12-29 16:52:00

phpexcel 官网上找到了以下设置边距的代码,且测试成功.

$excel = new PHPExcel(); 
$sheet = $excel->getActiveSheet(); 
$pageMargins = $sheet->getPageMargins(); 

// 设置边距为0.5厘米

(1英寸 = 2.54厘米)

$margin = 0.5 / 2.54; //phpexcel 中是按英寸来计算的,所以这里换算了一下 

$pageMargins->setTop($margin);       //上边距 
$pageMargins->setBottom($margin);    //下 
$pageMargins->setLeft($margin);      //左 
$pageMargins->setRight($margin);     //右 

$sheet->getPageSetup()->setFitToWidth('1');//自动填充到页面的宽度 
//$sheet->getPageSetup()->setFitToHeight('1');//自动填充到页面的高度 

$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel5'); //生成一个新的xls文件 
$writer->save('test.xls'); 

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK