我以确切的顺序依次调用这三个函数
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);
}
Run Code Online (Sandbox Code Playgroud)
问题是,打开生成的Excel文件时,我将页边距设置为“自定义”,但实际上,将其设置为不同的值,而不是传递给函数的边距。实际上,我打电话给(1,0.5,0.5,1)我是在争论,但是我得到了同样的结果2, 0.8, 0.8, 2。真的很奇怪...
另外:我无法上班setFittoWidth(1);我希望在一页中看到适用于所有列的内容,但是Excel告诉我它是在页面上的适应页上设置的。
我究竟做错了什么?
解决:
变了
public function setPrintFitToWidth()
{
$this->sheet->getPageSetup()->setFitToWidth(1);
}
Run Code Online (Sandbox Code Playgroud)
至
public function setPrintFitToWidth()
{
$this->sheet->getPageSetup()->setFitToWidth(1);
$this->sheet->getPageSetup()->setFitToHeight(0);
}
Run Code Online (Sandbox Code Playgroud)
关于边距:我尝试使用零,并且边距得到尊重,因此得出的结论是,PHPExcel单位在某种程度上已经“缩小”了……因此,经过一些“尝试”和“重做”之后,我发现了生成正确洋酒的值