diff --git a/src/ExcelDataReader.Tests/ExcelOpenXmlReaderTest.cs b/src/ExcelDataReader.Tests/ExcelOpenXmlReaderTest.cs
index 3778b506..8e787f0f 100644
--- a/src/ExcelDataReader.Tests/ExcelOpenXmlReaderTest.cs
+++ b/src/ExcelDataReader.Tests/ExcelOpenXmlReaderTest.cs
@@ -490,6 +490,23 @@ public void GitIssue642_ActiveSheet_SingleWorksheet()
Assert.That(dataSet.Tables[0].TableName, Is.EqualTo("List1"));
}
+ [Test]
+ public void GitIssue700_AlignmentEnumParsing()
+ {
+ using var reader = OpenReader("Test_git_issue_700_CellAlignments");
+ reader.Read();
+
+ var general = reader.GetCellStyle(0);
+ var left = reader.GetCellStyle(1);
+ var center = reader.GetCellStyle(2);
+ var right = reader.GetCellStyle(3);
+
+ Assert.That(general.HorizontalAlignment, Is.EqualTo(HorizontalAlignment.General));
+ Assert.That(left.HorizontalAlignment, Is.EqualTo(HorizontalAlignment.Left));
+ Assert.That(center.HorizontalAlignment, Is.EqualTo(HorizontalAlignment.Center));
+ Assert.That(right.HorizontalAlignment, Is.EqualTo(HorizontalAlignment.Right));
+ }
+
protected override IExcelDataReader OpenReader(Stream stream, ExcelReaderConfiguration configuration = null)
=> ExcelReaderFactory.CreateOpenXmlReader(stream, configuration);
diff --git a/src/ExcelDataReader/CellStyle.cs b/src/ExcelDataReader/CellStyle.cs
index 909d0cac..301a78cb 100644
--- a/src/ExcelDataReader/CellStyle.cs
+++ b/src/ExcelDataReader/CellStyle.cs
@@ -16,9 +16,9 @@ public enum HorizontalAlignment
Left,
///
- /// Centered.
+ /// Center.
///
- Centered,
+ Center,
///
/// Right.
diff --git a/src/ExcelDataReader/Core/OpenXmlFormat/XmlFormat/XmlStylesReader.cs b/src/ExcelDataReader/Core/OpenXmlFormat/XmlFormat/XmlStylesReader.cs
index ac1c6c9c..ef50e495 100644
--- a/src/ExcelDataReader/Core/OpenXmlFormat/XmlFormat/XmlStylesReader.cs
+++ b/src/ExcelDataReader/Core/OpenXmlFormat/XmlFormat/XmlStylesReader.cs
@@ -130,15 +130,11 @@ static void ReadAlignment(XmlReader reader, string nsSpreadsheetMl, out int inde
if (reader.IsStartElement(NAlignment, nsSpreadsheetMl))
{
int.TryParse(reader.GetAttribute(AIndent), NumberStyles.Integer, CultureInfo.InvariantCulture, out indentLevel);
- try
- {
- horizontalAlignment = (HorizontalAlignment)Enum.Parse(typeof(HorizontalAlignment), reader.GetAttribute(AHorizontal), true);
- }
- catch (ArgumentException)
- {
- }
- catch (OverflowException)
+
+ var attrValue = reader.GetAttribute(AHorizontal);
+ if (attrValue is not null)
{
+ Enum.TryParse(attrValue, true, out horizontalAlignment);
}
reader.Skip();
diff --git a/src/TestData/Test_git_issue_700_CellAlignments.xlsx b/src/TestData/Test_git_issue_700_CellAlignments.xlsx
new file mode 100644
index 00000000..2457352f
Binary files /dev/null and b/src/TestData/Test_git_issue_700_CellAlignments.xlsx differ