aVadim483 / fast-excel-writer

Lightweight and very fast XLSX Excel Spreadsheet Writer in PHP
MIT License
177 stars 31 forks source link

Center on Page and Page Margins #89

Open l205306 opened 1 month ago

l205306 commented 1 month ago

Screenshot 2024-10-28 143242

  1. How to set Top Margin to 0.6 and Left Margin to 0.4 ? As far as I know, the ratio between value and Excel is about ~2.5.
$sheet
  ->pageMargins([
      'header' => 0.5, // 1.3 in Excel
      'footer' => 0.2, // 0.5 in Excel
      'bottom' => 0,
      'right' => 0,
      'top' => 0.25, // 0.8 in Excel
      'left' => 0.15 // 0.5 in Excel
  ])
  ->pagePaperSize(Excel::PAPERSIZE_A3)
  ->pageLandscape();
  1. How to set Center on Page to Horizontally ? I switched from PHPSpreadsheet and it is allowed to set via $spreadsheet->getActiveSheet()->getPageSetup()->setHorizontalCentered(true); https://phpspreadsheet.readthedocs.io/en/latest/topics/recipes/#center-a-page-horizontallyvertically
aVadim483 commented 1 month ago
  1. By default, the fields are set in inches, 1 inch = 2.54 cm. But you can explicitly set the units in millimeters or centimeters.
    
    $sheet1->pageMargins([
        'left' => '0.5',
        'right' => '0.5mm',
        'top' => '1.0cm',
        // ...
    ]);

$sheet1->pageMarginLeft(0.5); // set left margin 0.5 inch $sheet1->pageMarginLeft('0.5cm'); // set left margin 0.5 centimeters $sheet1->pageMarginLeft('0.5mm'); // set left margin 0.5 millimeters



2. See https://github.com/aVadim483/fast-excel-writer/blob/master/docs/02-sheets.md#print-settings since v.6.2
l205306 commented 4 weeks ago

The values are still differing even when I explicitly set the units to millimeters...

$sheet
  ->pageMargins([
      'header' => '1.3cm',
      'footer' => '0.5cm',
      'bottom' => '0cm',
      'right' => '0cm',
      'top' => '0.6cm',
      'left' => '0.4cm'
  ])
  ->pagePaperSize(Excel::PAPERSIZE_A3)
  ->pageLandscape()
  ->setPrintHorizontalCentered()
  ->pagePaperWidth('29.7cm')
  ->pagePaperHeight('42cm');

image image