excel - C# ArgumentOutOfRangeException while reading ExcelWorksheet -
i'm reading officeopenxml.excelworksheet , getting argumentoufofrangeexception on middle of collection.
i'm reading process.information = sheet.cells[line, i++].text;
. on line i = 22
while sheet.dimension.column = 28
.
when i'm debugging , enumerate collection see exception thrown on method .text
while .value
method showing correct value.
according exception stack trace, exception being thrown system.text.stringbuilder.insert() method
---- edit ---- after accepted answer realized problem not on read. reply same file column (import success or insuccess) , while i'm doing sheet formatation again same error, due method system.text.stringbuilder.insert(). i'm trying autofit column sheet.column(22).autofit()
stack trace
at system.text.stringbuilder.insert(int32 index, char* value, int32 valuecount) @ system.text.stringbuilder.insert(int32 index, char value) @ officeopenxml.style.xmlaccess.excelnumberformatxml.excelformattranslator.tonetformat(string excelformat, boolean forcolwidth) @ officeopenxml.style.xmlaccess.excelnumberformatxml.excelformattranslator..ctor(string format, int32 numfmtid) @ officeopenxml.style.xmlaccess.excelnumberformatxml.get_formattranslator() @ officeopenxml.excelrangebase.getformattedtext(boolean forwidthcalc) @ officeopenxml.excelrangebase.get_textforwidth() @ officeopenxml.excelrangebase.autofitcolumns(double minimumwidth, double maximumwidth) @ officeopenxml.excelrangebase.autofitcolumns(double minimumwidth) @ officeopenxml.excelrangebase.autofitcolumns() @ officeopenxml.excelcolumn.autofit() @ skiptraceapi.models.processosrepository.formatexcel(excelpackage package, boolean addvalidation) in
judging portion of stack trace mentioning style.xmlaccess
, looks ran genuine bug in implementation of officeopenxml
triggered style of cell in question.
since using value.tostring()
works when cell not null
, can work around bug using newly added null conditional syntax:
process.information = sheet.cells[line, i++].value?.tostring(); // ^
another possible work-around using getvalue<t>
:
process.information = sheet.getvalue<string>(line, i++);
edit: looks there style in cell in 22-nd column has non-numeric value library expected numeric string. library tries parse string number, causing exception. can work around changing format of cell, actual fix modify library detect format mismatches without throwing exception.
Comments
Post a Comment