PHPOffice / PhpSpreadsheet

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

PhpSpreadsheet read xlsx file not correctly. Wrong reading empty combined cells #2905

Open Aleksej-Shherbak opened 2 years ago

Aleksej-Shherbak commented 2 years ago

I have the following excel table: enter image description here

and the following code to turn it into html table:

<style>
    table, th, td {
        border: 1px solid black;
    }
</style>

<?php

error_reporting(E_ALL);
require  'vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
use PhpOffice\PhpSpreadsheet\Writer\Html;

$fileExcel = tempnam(sys_get_temp_dir(), 'excel_');
$blob = file_get_contents('./test.xlsx');
file_put_contents($fileExcel, $blob);

$reader = new Xlsx();
$spreadsheet = $reader->load($fileExcel);
unlink($fileExcel);

$writer = new Html($spreadsheet);
$sheetData = $writer->generateSheetData();

echo $sheetData;

The result seems corrupted:

enter image description here

I tried to find some setting on the documentation, but I did not find anything. Any ideas how to fix this behavior?

MarkBaker commented 2 years ago

No idea, although it looks like a problem with merged cells not being recognised as merges; but it's very difficult to diagnose any cause from pictures. Could the problem be in the Xlsx Reader or (probably more likely) in the HTML Writer? Can you provide a sample file?