Skip to content

Issue #700: Fixed parsing of horizontal alignment in XmlStylesReader#702

Merged
appel1 merged 1 commit into
ExcelDataReader:developfrom
msjoblad:issue700_horizontal_alignment
Apr 19, 2025
Merged

Issue #700: Fixed parsing of horizontal alignment in XmlStylesReader#702
appel1 merged 1 commit into
ExcelDataReader:developfrom
msjoblad:issue700_horizontal_alignment

Conversation

@msjoblad

Copy link
Copy Markdown
Contributor

Fixes #700

Comment I wrote in the issue:

I was looking into this and I think the enum value "Centered" may be incorrect - it should be "Center".

I tried various different Excel files from different Excel versions and I was able to reproduce the issue in any file where is center any cell horizontally. If someone has a file where they have a horizontally centered cell and where this issue does not happen, I'd be interested in seeing it for further testing.

The HorizontalAlignment enum was added in c3ae45e by @ andersnm, do you know if there is a reason to use Centered here?

I tested this locally and changed the enum value to Center and added a null check -> all files open without exceptions and all tests pass.

Solution

  • Changed the enum from CellStyle.Centered to CellStyle.Center
  • Added a null check to not attempt to parse empty values
  • Changed the logic to use Enum.TryParse() instead of Enum.Parse() to avoid unncesessary exceptions
  • Added a new test for checking that the alignment values are appropriately parsed

@appel1 appel1 merged commit f258ea6 into ExcelDataReader:develop Apr 19, 2025
@OwnageIsMagic OwnageIsMagic mentioned this pull request Sep 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XmlStylesReader - ReadAlignment disregards HorizontalAlignment 'center' and throws ignored Exception

2 participants