PHPExcel:打印页边距和打印自动调整似乎不起作用
PHPExcel: print page margins and print auto fit seems not working
我按这个顺序依次调用这 3 个函数
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',但实际上,我将页边距设置为不同的值,而不是我传递给函数的边距。事实上,我用参数 (1,0.5,0.5,1)
调用了,但我以相同的顺序得到了 2, 0.8, 0.8, 2
。真是奇怪...
另外:我无法工作setFittoWidth(1)
;我希望在一页中看到针对所有列的调整,但是 Excel 告诉我它是在调整 sheet 页面上设置的。
我做错了什么?
已解决:
已更改
public function setPrintFitToWidth()
{
$this->sheet->getPageSetup()->setFitToWidth(1);
}
至
public function setPrintFitToWidth()
{
$this->sheet->getPageSetup()->setFitToWidth(1);
$this->sheet->getPageSetup()->setFitToHeight(0);
}
关于边距:我尝试使用零并且边距得到尊重,所以我得出的结论是 PHPExcel 单元在某种程度上 'scaled down'... 所以,经过一些 'try' 和 'redo' ,我找到了生成正确 magins
的值
我按这个顺序依次调用这 3 个函数
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',但实际上,我将页边距设置为不同的值,而不是我传递给函数的边距。事实上,我用参数 (1,0.5,0.5,1)
调用了,但我以相同的顺序得到了 2, 0.8, 0.8, 2
。真是奇怪...
另外:我无法工作setFittoWidth(1)
;我希望在一页中看到针对所有列的调整,但是 Excel 告诉我它是在调整 sheet 页面上设置的。
我做错了什么?
已解决:
已更改
public function setPrintFitToWidth()
{
$this->sheet->getPageSetup()->setFitToWidth(1);
}
至
public function setPrintFitToWidth()
{
$this->sheet->getPageSetup()->setFitToWidth(1);
$this->sheet->getPageSetup()->setFitToHeight(0);
}
关于边距:我尝试使用零并且边距得到尊重,所以我得出的结论是 PHPExcel 单元在某种程度上 'scaled down'... 所以,经过一些 'try' 和 'redo' ,我找到了生成正确 magins
的值