Skip to content

Fix XLSX vertical alignment being set to top when only horizontal alignment is set#32

Closed
gtbuchanan wants to merge 1 commit into
nissl-lab:masterfrom
energyworldnet:xssf-vertical-alignment-fix
Closed

Fix XLSX vertical alignment being set to top when only horizontal alignment is set#32
gtbuchanan wants to merge 1 commit into
nissl-lab:masterfrom
energyworldnet:xssf-vertical-alignment-fix

Conversation

@gtbuchanan
Copy link
Copy Markdown
Contributor

I am using an existing XLSX file as a template. On some cells, only the horizontal alignment is set to something other than the default. When this is the case, an "alignment" node exists in the XML. The CT_CellAlignment class is currently setting the vertical alignment to top when a "vertical" attribute does not even exist on the "alignment" node. The default vertical value in Excel is bottom align, so most of my cell alignment is being overridden with top when I write to the file.

@gtbuchanan gtbuchanan changed the title Fix XSSF vertical alignment being set to top when only horizontal alignment is set Fix XLSX vertical alignment being set to top when only horizontal alignment is set Dec 5, 2014
@tonyqus
Copy link
Copy Markdown
Member

tonyqus commented Dec 24, 2014

general is available value for horizontal but not for vertical in Excel. The default value of vertical should be center as Excel UI shows. According to my test, vertical attribute is always set by Excel. The only difference is that the default value is center instead of top.

@tonyqus
Copy link
Copy Markdown
Member

tonyqus commented Dec 24, 2014

I'll set the default value of vertical attribute to center.

@tonyqus tonyqus closed this Dec 24, 2014
@gtbuchanan
Copy link
Copy Markdown
Contributor Author

I disagree with your decision.

"general" is not an actual XML value for either alignment. It is simply used to mean the attribute does not exist. "ST_HorizontalAlignment.general" is only used in one place in code to determine if the XML attribute should be written back to the file at all.

if(this.horizontal != ST_HorizontalAlignment.general)
    XmlHelper.WriteAttribute(sw, "horizontal", this.horizontal.ToString());

I created a enumeration called "ST_VerticalAlignment.general" and used the exact same logic currently used for horizontal alignment. I think the name "general" is horrible, but I used it to keep the code consistent.

As you can see below, the default vertical alignment is bottom; not center as you suggest. And by default, there is no alignment attribute written to the file at all.

image

<cellXfs count="1">
    <xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/>
</cellXfs>

However, the attribute is written to the file when I change the vertical alignment to top.

<cellXfs count="2">
    <xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/>
    <xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0" applyAlignment="1">
        <alignment vertical="top"/>
    </xf>
</cellXfs>

My proposed changes mimic this behavior.

@gtbuchanan gtbuchanan deleted the xssf-vertical-alignment-fix branch January 13, 2015 15:33
antony-liu added a commit to antony-liu/npoi that referenced this pull request Apr 10, 2025
….pow() with multiplication. Thanks to Daniel Kuan! This closes nissl-lab#32.
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.

2 participants