Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPExcel: print page margins and print auto fit seems not working

Tags:

php

phpexcel

I'm calling these 3 functions one after other in this exact order

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

The problem is that, opening resulting Excel file, I've page margin set to 'custom' but, in fact, set to different values instead of margin I passed to my function. In fact I called with argument (1,0.5,0.5,1) but I got, in the same orders, 2, 0.8, 0.8, 2. It's really strange ...

Also: I cannot get working setFittoWidth(1); I expect to see adapted for all column in one page, but Excel tell me It's setup on adapt sheet on a page.

What am I doing wrong?

like image 619
realtebo Avatar asked Jan 14 '16 12:01

realtebo


1 Answers

Resolved:

changed

public function setPrintFitToWidth()
{
    $this->sheet->getPageSetup()->setFitToWidth(1);    
}

to

public function setPrintFitToWidth()
{
    $this->sheet->getPageSetup()->setFitToWidth(1);    
    $this->sheet->getPageSetup()->setFitToHeight(0);    
}

About the margins: I tried with zero and margin are respected, so I concluded than PHPExcel unit are in someway 'scaled down'... So, after some 'try' and 'redo', I found the values that generate the correct magins

like image 72
realtebo Avatar answered Nov 13 '22 06:11

realtebo