is there AAAAAAAAAAAANY way to take an xls file and convert it to xlsx using a php code?
I've googled but I see not many people asked this and those who had similar problems found no solution.
I've tried using PHPExcel but I can't figure out how to do it and even if there is such possibility..

any suggestion would be appreciated!

Dani AI

Generated

As suggested, first ask whether a conversion is actually needed — Excel itself will open .xls files. For automated conversion from PHP there are three practical paths, depending on server OS and how faithful the output must be: a maintained PHP library, a headless LibreOffice conversion, or using Excel via COM on Windows. For who saw “messed up” data when copying, the notes below include common causes and fixes.

Use a modern PHP library (recommended for most web servers). Install and call the reader for BIFF (.xls) and write the OOXML (.xlsx). Example flow:

use PhpOffice\PhpSpreadsheet\IOFactory;

$reader = IOFactory::createReader('Xls');
$spreadsheet = $reader->load('input.xls');
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save('output.xlsx');

Composer and native extensions (zip, xml) are required. See the official docs here: PhpSpreadsheet docs. If only values are needed, use a “read data only” mode to reduce complexity.

If the workbook uses charts, pivot tables, complex formatting or macros, a headless LibreOffice conversion often preserves those things better:

soffice --headless --convert-to xlsx --outdir /out /path/input.xls

Tools like unoconv wrap this and are suitable on Linux servers.

On Windows with Excel installed, COM automation yields the highest fidelity. Typical PHP COM SaveAs uses file format code 51 (OpenXML workbook):

$excel = new COM("Excel.Application");
$wb = $excel->Workbooks->Open(realpath('input.xls'));
$wb->SaveAs(realpath('output.xlsx'), 51);
$wb->Close(false);
$excel->Quit();

Reference: Workbook.SaveAs docs.

Troubleshooting tips: check for macros (xlsm is needed to keep macros), inspect date/locale parsing, compare formulas vs. values, try small test files, and increase memory/time limits when using the PHP library. If one method corrupts specific cells, try the next method — headless LibreOffice or real Excel will usually give the best fidelity.

Recommended Answers

All 3 Replies

Hello,

Try this site:

The boast being able to convert between the two formats among other things/

I already got the phpExcel but I didn't find how to convert xls to xlsx..
I can create a new xlsx file and copy all the data there, but it messes up the data, so I'm looking for a way to do it without copying the files/data

Can i ask what it is you are really trying to do. Excel 2007 or 2010 will both read the xls file without problems. Are you trying to read it with another app that requires xlsx instead?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.