I have Excel 2003 and 2010 installed, but xlsread fails to import a simple ".xlsx" file

3 views (last 30 days)
Running / Installed Software: - Windows 7 Enterprise (64-bit) - MATLAB R2013a (win64) - Excel 2003 (32-bit) - Excel 2010 (32-bit)
I need to have both versions of Excel installed on my system for work, 2010 for new products and 2003 for some old legacy spreadsheets are still used for existing products.
I have two spreadsheets with the same contents, one is "book.xlsx" and the other is a "book.xls". Nothing fancy in there:
1
2
3
Here are the results of me xlsread on each:
>> xls = xlsread('book.xls')
xls =
1
2
3
>> xlsx = xlsread('book.xlsx')
Error using xlsread (line 247)
File
C:\<path>\book.xlsx
not in Microsoft Excel Format.
My guess is that MATLAB is using Excel 2003 code for xlsread and that's why it cannot open the .xlsx file. But honestly I can't tell.
Is there an OS or MATLAB setting I could modify to allow xlsread to open .xlsx files?

Answers (1)

Image Analyst
Image Analyst on 18 Sep 2013
Here's a snippet of mine you might want to look at:
% Prepare proper filename extension.
% Get the Excel version because if it's version 11 (Excel 2003) the file extension should be .xls,
% but if it's 12.0 (Excel 2007) then we'll need to use an extension of .xlsx to avoid nag messages.
excelVersion = str2double(Excel.Version);
if excelVersion < 12
excelExtension = '.xls';
else
excelExtension = '.xlsx';
end
% Determine the proper format to save the files in. It depends on the extension (Excel version).
switch excelExtension
case '.xls' %xlExcel8 or xlWorkbookNormal
xlFormat = -4143;
case '.xlsb' %xlExcel12
xlFormat = 50;
case '.xlsx' %xlOpenXMLWorkbook
xlFormat = 51;
case '.xlsm' %xlOpenXMLWorkbookMacroEnabled
xlFormat = 52;
otherwise
xlFormat = -4143;
end
Then, later....
% Save this workbook we just created.
ExcelWorkbook.SaveAs(fullFileName, xlFormat);

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!