Repository navigation
Apply date and time number formats only to numeric cells - #1043
michelebastione merged 1 commit into
Conversation
Text cells (t="s", "str" and "inlineStr") with a date or time number format were converted to DateTime/TimeSpan whenever their text parsed as a double, with a result that depended on the current culture. Excel never applies a number format to text. ConvertCellValue yields a double only for numeric cells, so ConvertValueByStyleFormat now returns any other value unchanged and converts the double directly instead of round-tripping it through ToString and double.TryParse. Fixes mini-software#1041
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Fixes #1041
Master counterpart of #1042.
ConvertValueByStyleFormatconverted any value whose text parsed as adouble, so text cells (t="s",t="str"andt="inlineStr") with a date or time number format came back asDateTime/TimeSpan, with a result that depended on the current culture.ConvertCellValueyields adoubleonly for numeric cells, so the method now returns any other value unchanged and converts thedoubledirectly.OpenXmlStyles.ConvertValueByStyleFormat: early return for values that are not adouble. Thedoubleis used as is, instead of going throughdouble.TryParse(value?.ToString(), ...). This covers the three callers: the row reader inOpenXmlReader, the cell reader inOpenXmlReader.CellsandOpenXmlMappingReader.MiniExcelGithubIssuesTests.QueryReturnsTextCellsWithDateOrTimeFormatAsString: one row with a numeric cell andt="s",t="str"andt="inlineStr"cells sharing a date format, plus a numeric cell and at="s"cell sharing a time format. The numeric cells still come back asDateTime/TimeSpanand the text cells asstring. It fails without the fix.SheetHelper.ReplaceSharedStringsXml: test helper mirroringReplaceStylesXml.Tested locally on net10.0 only, since this machine has no .NET 11 SDK:
MiniExcel.OpenXml.Tests545/545.Summary by CodeRabbit