Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/ExcelDataReader.Tests/ExcelOpenXmlReaderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/ExcelDataReader/CellStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public enum HorizontalAlignment
Left,

/// <summary>
/// Centered.
/// Center.
/// </summary>
Centered,
Center,

/// <summary>
/// Right.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Binary file not shown.