我按照这个确切的顺序一个接一个地调用这三个函数
public function setPrintFitToWidth()
{
$this->sheet->getPageSetup()->setFitToWidth(1);
}
public function setPrintArea($cell_area)
{
$this->sheet->getPageSetup()->setPrintArea($cell_area);
}
public function setPrintMargins($top, $right, $bottom, $left)
{
$this->sheet->getPageMargins()->setTop($top);
$this->sheet->getPageMargins()->setRight($right);
$this->sheet->getPageMargins()->setLeft($left);
$this->sheet->getPageMargins()->setBottom($bottom);
}
问题是,打开生成的Excel文件,我将页边距设置为' custom'但实际上,设置为不同的值而不是我传递给我的函数的margin。事实上,我使用参数(1,0.5,0.5,1)
进行了调用,但我按照相同的顺序获得了2, 0.8, 0.8, 2
。这很奇怪......
另外:我无法工作setFittoWidth(1)
;我希望在一个页面中看到适用于所有列,但Excel告诉我它在页面上的适应表上进行了设置。
我做错了什么?
答案 0 :(得分:5)
已解决:
已更改
public function setPrintFitToWidth()
{
$this->sheet->getPageSetup()->setFitToWidth(1);
}
到
public function setPrintFitToWidth()
{
$this->sheet->getPageSetup()->setFitToWidth(1);
$this->sheet->getPageSetup()->setFitToHeight(0);
}
关于边距:我尝试使用零和边距得到尊重,所以我得出的结论是,PHPExcel单元在某种程度上“按比例缩小”...所以,经过一些'尝试'和'重做'后,我发现生成的值正确的魔法师