- Open the file in Excel
- "Save as" the file to a new file, a "deep copy"
Bug in xlsread on linux
6 views (last 30 days)
I am trying to read an XLSX file with xlsread on Linux, but I get an error
>> xlsread('test.xlsx', 'MySheet', 'A:A')
Error using xlsread (line 247)
No right hand side value for assignment.
The XLSX file I have was generated from a Python program and appears to be a valid XLSX file in that I can open it in both LibreOffice Calc and Excel and Python as well as MATLAB on Windows. Following through the code, the error occurs on line 11 of toolbox/matlab/iofun/private/getSheetNames.m
sheetIDs = regexp(workbook_xml_rels, ...
'<Relationship Id="rId(\d+?)" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/.+?.xml"/>', ...
The issue appears to be that the "relationship" file xl/_rels/workbook.xml.rels has an unexpected format. Specifically, the lines look like
<Relationship Id="rId1" Target="worksheets/sheet1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" />
It seems like MATLAB wants the line to be (Id Type Target)|, but the line in the problem files have (Id Target Type). I would like to replace the regex on line 11 of getSheetNames.m with something that will work for both (Id Type Target) and (Id Target Type), but my regex foo is too weak.
Ken Atwell on 16 Jul 2014
xlsread is tested against files created by Excel -- it looks like you found a case that is technically valid but not something Excel would typically create. Can you try:
Can MATLAB open this new file?
Gabriel on 3 Dec 2014
Ken's fix is not enough for me but I managed to get it to work for my file (no idea what application created it) with just two more edits.
2 files to edit:
In getSheetNames.m: replace line 12 with (this is equivalent to Ken's solution):
'<Relationship Id="rId(\d+?)" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/.*\.xml"\s*/>', ...
and line 19 with:
['<sheet name=".*(?<=<sheet name=")(?<sheetName>.+?)(?=" sheetId=".*" r:id="rId' num2str(sheetIDs(i)) '"\s*/>)'], ...
In xlsreadXLSX.m: replace line 196 with:
span = regexp(sheetData, '<dimension\s+ref="(?<start>[A-Z]+\d+)(?<end>:[A-Z]+\d+)?"\s*/>', 'names', 'once');
Note: all these do is add some "\s*" in the regexp to authorize possible space characters before the closing tags "/>". As it is compatible with the original version, I doubt it could introduce more issues.