-
-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"No value associated with key CodingKeys(stringValue: \"cols\", intValue: nil) #12
Comments
Hi @maxvol, many thanks for reporting this. I hope that issues with |
Regarding |
Error Domain=NSXMLParserErrorDomain Code=39 "(null)" UserInfo={NSXMLParserErrorColumn=16328, NSXMLParserErrorLineNumber=2, NSXMLParserErrorMessage=AttValue: " or ' expected Apparently because quotes are escaped like: =" <?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\r\n<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" mc:Ignorable=\"x14ac\" xmlns:x14ac=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac\"><dimension ref=\"A1:E128\"/><sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"/></sheetViews><sheetFormatPr defaultRowHeight=\"15\" x14ac:dyDescent=\"0.25\"/><cols><col min=\"1\" max=\"1\" width=\"26.42578125\" customWidth=\"1\"/><col min=\"2\" max=\"2\" width=\"16.7109375\" customWidth=\"1\"/><col min=\"3\" max=\"3\" width=\"9.140625\" style=\"1\"/><col min=\"4\" max=\"4\" width=\"82\" customWidth=\"1\"/><col min=\"6\" max=\"6\" width=\"16\" customWidth=\"1\"/></cols><sheetData> ...``` |
|
Here it is (without rows within sheetData, due to sensitive data) - <?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\r\n<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" mc:Ignorable=\"x14ac\" xmlns:x14ac=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac\"><dimension ref=\"A1:E128\"/><sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"/></sheetViews><sheetFormatPr defaultRowHeight=\"15\" x14ac:dyDescent=\"0.25\"/><cols><col min=\"1\" max=\"1\" width=\"26.42578125\" customWidth=\"1\"/><col min=\"2\" max=\"2\" width=\"16.7109375\" customWidth=\"1\"/><col min=\"3\" max=\"3\" width=\"9.140625\" style=\"1\"/><col min=\"4\" max=\"4\" width=\"82\" customWidth=\"1\"/><col min=\"6\" max=\"6\" width=\"16\" customWidth=\"1\"/></cols><sheetData></sheetData><conditionalFormatting sqref=\"C56:C1048576 C1:C54\"><cfRule type=\"duplicateValues\" dxfId=\"2\" priority=\"48\"/></conditionalFormatting><conditionalFormatting sqref=\"C1:C1048576\"><cfRule type=\"duplicateValues\" dxfId=\"1\" priority=\"1\"/></conditionalFormatting><conditionalFormatting sqref=\"C2:C54\"><cfRule type=\"duplicateValues\" dxfId=\"0\" priority=\"359\"/></conditionalFormatting><pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/></worksheet> |
Sorry, I'm a bit confused, is that the whole XML without |
Huh? Apparently you cannot see it for some reason, I will check formatting in my previous post. |
Thanks, can see it now, will have a closer look. BTW, if this string was printed from the debugger, the quotes are escaped by default, to print an unescaped string you can use something like |
Aha! Here it is - <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="x14ac" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"><dimension ref="A1:E128"/><sheetViews><sheetView tabSelected="1" workbookViewId="0"/></sheetViews><sheetFormatPr defaultRowHeight="15" x14ac:dyDescent="0.25"/><cols><col min="1" max="1" width="26.42578125" customWidth="1"/><col min="2" max="2" width="16.7109375" customWidth="1"/><col min="3" max="3" width="9.140625" style="1"/><col min="4" max="4" width="82" customWidth="1"/><col min="6" max="6" width="16" customWidth="1"/></cols><sheetData>
</sheetData><conditionalFormatting sqref="C56:C1048576 C1:C54"><cfRule type="duplicateValues" dxfId="2" priority="48"/></conditionalFormatting><conditionalFormatting sqref="C1:C1048576"><cfRule type="duplicateValues" dxfId="1" priority="1"/></conditionalFormatting><conditionalFormatting sqref="C2:C54"><cfRule type="duplicateValues" dxfId="0" priority="359"/></conditionalFormatting><pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/></worksheet> P.S. The entire document printed with |
Many thanks for this @maxvol! I think I've found a source of the issue and this can be parsed now in a separate branch that I'm preparing as a PR. Would you mind if I add this XML as a unit-test to |
Sure, please do! |
A worksheet provided in #12 has a `Column` value without `customWidth` attribute. This attribute is now optional, also types of properties on `Column` were updated according to [documentation from Microsoft](https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.column?view=openxml-2.8.1). A few other types and names were updated accordingly with deprecation warnings added where possible. Worksheet XML that couldn't be parsed previously has been added to `WorksheetTests`. * Update names and types of properties on Worksheet * Update types on Column model and related tests * Increase test coverage for new/deprecated props
Great, thanks again. I've just merged #18 to |
Still crashing with the same error. Why not make most attributes optional? Here's a few more lines from the same sheet - <row r="1" spans="1:5" s="2" customFormat="1" ht="15.75" thickBot="1" x14ac:dyDescent="0.3">
<c r="A1" s="3" t="s">
<row r="3" spans="1:5" x14ac:dyDescent="0.25">
<c r="A3" t="s"> BTW is it possible to modify/save XLSX? |
I've just added these rows and cells to the test and it passes with no modifications in CoreXLSX itself, I highly doubt it has something to do with optionality at this point. When you're saying "with the same error" do you mean this one?
If so, that's most probably caused by unscaped quotes somewhere in Currently there's no API in CoreXLSX for writing to an XLSX file, but in principle it wouldn't be very hard to add as |
Unlikely, XML is valid when pasted into validating editor. Can it be missing 's' and 't' attributes in 'c' element? Error Domain=NSXMLParserErrorDomain Code=39 "(null)" UserInfo={NSXMLParserErrorColumn=16328, NSXMLParserErrorLineNumber=2, NSXMLParserErrorMessage=AttValue: " or ' expected |
Just to be completely sure, I've added this cell with a single It looks like an error is thrown from Looking at
These line and column numbers are already printed in the error. Here it looks like the line number is 2 (I assume line 1 is the XML header) and the column is 16328. I don't know an easy way to get a substring from a string by line and column within the debugger, but you could unzip the XLSX file (e.g. with Another approach could to be to reformat |
(attributeNotStartedError = 39) Error Domain=NSXMLParserErrorDomain Code=39 "(null)" UserInfo={NSXMLParserErrorColumn=16328, NSXMLParserErrorLineNumber=2, NSXMLParserErrorMessage=AttValue: " or ' expected |
Thanks, this gives the same info though, the error is coming from Apple's |
Aha, the reason is whitespace characters (newline, spaces) between equal sign and first quote: </row><row r=
"78" spans="1:5" x14ac:dyDescent="0.25"> |
So, do you think you can fix it? Because that break occurs automatically, I have no control over it. |
I've added this snippet and a few other similar variations to the test suite with a newline and also If you're getting these files some other system or app, would it be possible to generate a file with fake data that could be shared so that I would be able to reproduce it on my side? Or maybe you could delete all cells except the offending cell, which I hope wouldn't leave any sensitive data and it could be shared? That would tremendously help in diagnosing the issue. Thanks! |
Still the same error. Here's the snippet including the offending row - <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="x14ac" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"><dimension ref="A1:E128"/><sheetViews><sheetView tabSelected="1" workbookViewId="0"/></sheetViews><sheetFormatPr defaultRowHeight="15" x14ac:dyDescent="0.25"/><cols><col min="1" max="1" width="26.42578125" customWidth="1"/><col min="2" max="2" width="16.7109375" customWidth="1"/><col min="3" max="3" width="9.140625" style="1"/><col min="4" max="4" width="82" customWidth="1"/><col min="6" max="6" width="16" customWidth="1"/></cols><sheetData><row r=
"78" spans="1:5" x14ac:dyDescent="0.25"><c r="A78" t="s"><v>3</v></c><c r="B78" t="s"><v>4</v></c><c r="C78" s="1"><v>421</v></c><c r="D78" t="s"><v>56</v></c><c r="E78"><v>57</v></c></row></sheetData><conditionalFormatting sqref="C56:C1048576 C1:C54"><cfRule type="duplicateValues" dxfId="2" priority="48"/></conditionalFormatting><conditionalFormatting sqref="C1:C1048576"><cfRule type="duplicateValues" dxfId="1" priority="1"/></conditionalFormatting><conditionalFormatting sqref="C2:C54"><cfRule type="duplicateValues" dxfId="0" priority="359"/></conditionalFormatting><pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/></worksheet> |
I've added the complete snippet to the test suite here, it is parsed successfully with all cells. If you unzip the file, remove all cells except the offending row and zip it back again, is the error still reproducible? Or maybe you could open the file in Microsoft Excel or Apple Numbers, delete all rows except row 78 and save a new version, would that version cause any issues in CoreXLSX? I suspect there might be something going on with encoding or compression that's lost when testing isolated XML snippets, so I hope testing a complete XLSX file end-to-end on my side would help. |
Hi @MaxDesiatov , I have a similar problem |
Hi @nIgect, could you please share the file that causes this issue? This would allow me to reproduce the problem on my side, find the cause and fix it. Thank you! |
As reported in CoreOffice/CoreXLSX#12 there are multiple issues where it's hard to understand why parsing of a certain XML has failed. `XMLCoder` should be able to report a snippet of a given XML of specified length around the position where the error has happened. This should be an property of type `UInt` named `errorContextLength` on `XMLDecoder` instance. An error thrown from XML parser that has line/column location should be repackaged having a context around that location of specified length. For example, if an error was thrown indicating that there's an unexpected character at line 3, column 15 with `errorContextLength` set to `10`, a new error type should be rethrown containing 5 characters before column 15 and 5 characters after, all on line 3. Line wrapping should be handled correctly too as the context can span more than a few lines. Also, currently there's a single use of `print` in the codebase for printing an error in `XMLStackParser.swift`. This has been removed. * Add ErrorHandleTest * Fix ErrorContextTest and formatting
Hi folks, sorry for the delay. I hope you could try the latest 0.4.0 version and pass a sufficiently large value (10, maybe 20 for example) as |
Hi everyone, if you've previously had issues, please try the latest 0.4.0 version or if those persist – the Thanks for understanding! |
(lldb) po file.parseWorksheetPaths()
▿ 3 elements
(lldb) po file.parseWorksheet(at: "xl/worksheets/sheet3.xml")
▿ DecodingError
▿ keyNotFound : 2 elements
- .0 : CodingKeys(stringValue: "cols", intValue: nil)
▿ .1 : Context
- codingPath : 0 elements
- debugDescription : "No value associated with key CodingKeys(stringValue: "cols", intValue: nil) ("cols")."
- underlyingError : nil
(lldb) po file.parseWorksheet(at: "xl/worksheets/sheet2.xml")
▿ DecodingError
▿ keyNotFound : 2 elements
- .0 : CodingKeys(stringValue: "cols", intValue: nil)
▿ .1 : Context
- codingPath : 0 elements
- debugDescription : "No value associated with key CodingKeys(stringValue: "cols", intValue: nil) ("cols")."
- underlyingError : nil
(lldb) po file.parseWorksheet(at: "xl/worksheets/sheet1.xml")
Error Domain=NSXMLParserErrorDomain Code=39 "(null)" UserInfo={NSXMLParserErrorColumn=16328, NSXMLParserErrorLineNumber=2, NSXMLParserErrorMessage=AttValue: " or ' expected
}
▿ DecodingError
▿ dataCorrupted : Context
- codingPath : 0 elements
- debugDescription : "The given data was not valid XML."
▿ underlyingError : Optional
- some : Error Domain=NSXMLParserErrorDomain Code=111 "(null)"
The text was updated successfully, but these errors were encountered: