how to change XLS file into xlsx?

Topics: Developer Forum, Project Management Forum, User Forum
Oct 5, 2011 at 1:21 PM

I'm looking for a simple code to take a file with ending XLS and resave it as xlsx type.

I don't want to get a new file, or open excel. just save as.. and give it a different type.

that's what I tried so far but it's creating a new file and the data is all messed up in it, everything is shifted into 1 column..

require_once 'Classes/PHPExcel.php';
if(file_exists("myfile.XLS")) {
 $objPHPExcel = new PHPExcel();
 $objPHPExcel = PHPExcel_IOFactory::load("myfile.XLS");
 $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
 $objWriter->save(str_replace('XLSchange.php', 'myfile.xlsx', __FILE__));

PHPExcel version    1.7.6, 2011-02-27



thank you.

Oct 12, 2011 at 10:31 AM


can anybody help please? I really need this!

Oct 12, 2011 at 10:54 AM

I don't understand your problem. You say that you want to create a new file, namely an xlsx (office open xml) file containing the data from an xls file (biff). But you also say you don't want a new file! Which is it? ;)


Your code seems sound to me though. Allthough I don't understand why you do " $objPHPExcel = new PHPExcel();" You overwrite the assigned variable a moment later anyway.


Maybe it is an idea to check if the opening of the initial xls file doesn't fail in some way. Try to read the data to see if it is ok, before writing it to the xlsx file.

Oct 22, 2011 at 5:37 PM

I want to take file Y.XLS and to make it Y.xlsx

I don't want new file to be added to the folder. cuz this line $objWriter->save(str_replace('XLSchange.php', 'myfile.xlsx', __FILE__));
creates a new php file and renames it to xlsx.. so if I could just take the original file and save it as xlsx...that's what I want

 but IF there's no way to do so, I'd rather get a new xlsx file added than nothing at all.

I hope I was clear this time..I don't really understand the code I just take pieces from examples that do what I need to be done and use them..if there's an example for changing the file's type let me know, I couldn't find one, they all create new files and the original file is not XLS..

Oct 24, 2011 at 1:45 PM

It's technically a new file as the format is totally different, same with Excel. Maybe delete or rename the old file, then write the XLSX.