diff --git a/ClosedXML/Excel/XLWorkbook_Load.cs b/ClosedXML/Excel/XLWorkbook_Load.cs index dd62c22..4ae0459 100644 --- a/ClosedXML/Excel/XLWorkbook_Load.cs +++ b/ClosedXML/Excel/XLWorkbook_Load.cs @@ -1429,6 +1429,7 @@ case CellValues.InlineString: case CellValues.SharedString: + case CellValues.String: xlCell.SetDataTypeFast(XLDataType.Text); break; } @@ -1487,6 +1488,7 @@ case CellValues.InlineString: case CellValues.SharedString: + case CellValues.String: xlCell.SetDataTypeFast(XLDataType.Text); break; } @@ -1529,6 +1531,15 @@ else xlCell.SetInternalCellValueString(String.Empty); } + else if (cell.DataType == CellValues.String) + { + xlCell.SetDataTypeFast(XLDataType.Text); + + if (!String.IsNullOrEmpty(cell.CellValue?.Text)) + xlCell.SetInternalCellValueString(cell.CellValue.Text); + else + xlCell.SetInternalCellValueString(String.Empty); + } else if (cell.DataType == CellValues.Date) { xlCell.SetDataTypeFast(XLDataType.DateTime); diff --git a/ClosedXML_Tests/Excel/Loading/LoadingTests.cs b/ClosedXML_Tests/Excel/Loading/LoadingTests.cs index 11dbfa5..a82dca2 100644 --- a/ClosedXML_Tests/Excel/Loading/LoadingTests.cs +++ b/ClosedXML_Tests/Excel/Loading/LoadingTests.cs @@ -386,12 +386,24 @@ using (var wb = new XLWorkbook(stream)) { var ws = wb.Worksheet(1); - + Assert.AreEqual(8, ws.Style.Font.FontSize); Assert.AreEqual("Arial", ws.Style.Font.FontName); Assert.AreEqual(8, ws.Cell("A1").Style.Font.FontSize); Assert.AreEqual("Arial", ws.Cell("A1").Style.Font.FontName); } } + + [Test] + public void CanCorrectLoadWorkbookCellWithStringDataType() + { + using (var stream = TestHelper.GetStreamFromResource(TestHelper.GetResourcePath(@"Misc\CellWithStringDataType.xlsx"))) + using (var wb = new XLWorkbook(stream)) + { + var cellToCheck = wb.Worksheet(1).Cell("B2"); + Assert.AreEqual(XLDataType.Text, cellToCheck.DataType); + Assert.AreEqual("String with String Data type", cellToCheck.Value); + } + } } } diff --git a/ClosedXML_Tests/Resource/Misc/CellWithStringDataType.xlsx b/ClosedXML_Tests/Resource/Misc/CellWithStringDataType.xlsx new file mode 100644 index 0000000..eeb2e18 --- /dev/null +++ b/ClosedXML_Tests/Resource/Misc/CellWithStringDataType.xlsx Binary files differ