PHPOffice / PhpSpreadsheet

A pure PHP library for reading and writing spreadsheet files
https://phpspreadsheet.readthedocs.io
MIT License
13.28k stars 3.43k forks source link

setTextRotation on PDF-Writers #1747

Closed FabianKoestring closed 2 years ago

FabianKoestring commented 3 years ago

This is:

- [x] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

setTextRotation() should change the text orientation on PDF-Writers.

What is the current behavior?

If i use setTextRotation(90), the text will be vertically on .xlsx but when i use a PDF-Writer like MPDF or Dompdf the text will be horizontally.

What are the steps to reproduce?

<?php

require __DIR__ . '/vendor/autoload.php';

// Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$worksheet->getStyle('A7')->getAlignment()->setTextRotation(90);
$worksheet->setCellValue('A7', 'Lorem Ipsum');

header('Content-Type: application/pdf');
header('Content-Disposition: attachment;filename="01simple.pdf"');
header('Cache-Control: max-age=0');

$writer = new Dompdf($spreadsheet);
#$writer = new Mpdf($spreadsheet);
$writer->writeAllSheets();
$writer->save('php://output');

Which versions of PhpSpreadsheet and PHP are affected?

"phpoffice/phpspreadsheet": "~1.15.0",
"mpdf/mpdf": "~8.0.0",
"dompdf/dompdf": "~0.8.6"
FabianKoestring commented 3 years ago

The only working way to do it .....

  1. Export Spreadsheet as HTML
  2. Replace Element with new one
  3. use Mpdf and created HTML to generate PDF-File
$writer = new Html($spreadsheet);
$html = $writer->generateHtmlAll();

$html = str_replace(
    '<td class="column0 style4 s style1" rowspan="7">Text</td>',
    '<td class="column0 style4 s style1" rowspan="7" text-rotate="90">Text</td>',
    $html
);

$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML($html);
$mpdf->Output();