I am on the fact-finding part of our project specs and have not found a definitive answer re whether PHPSpreadsheet can convert an .xls
to .xlsx
and preserve formatting, such as table borders.
From this question, I see that there are separate imports for read/write and for file format type. This example demonstrates use of the different modules for read/write file formats:
<?php
require 'vendor\autoload.php';
use \PhpOffice\PhpSpreadsheet\Reader\Xls;
use \PhpOffice\PhpSpreadsheet\Writer\Xlsx;
$xls_file = "Example.xls";
$reader = new Xls();
$spreadsheet = $reader->load($xls_file);
$loadedSheetNames = $spreadsheet->getSheetNames();
$writer = new Xlsx($spreadsheet);
foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) {
$writer->setSheetIndex($sheetIndex);
$writer->save($loadedSheetName.'.xlsx');
}
However, I have not seen if the resultant export preserves formatting, specifically border lines. At the moment, I am unable to write this myself.