Search code examples
excelopenxmlxlsxopenxml-sdk

Excel ignors border in Excel Open XML style sheet


I create simple xlsx files for excel by manual coding. I create the minimal required parts put it to a zip file names it as xlsx and evering works fine. Except of the borders!! Excel ignores all of my borders-advices and I don't know why.

Here is my styles.xml:

<?xml version="1.0" encoding="UTF-8"?>
<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
  <fonts count="4">
    <font>
      <name val="Calibri"/>
      <sz val="14"/>
      <b/>
      <color rgb="FF000000"/>
    </font>
    <font>
      <name val="Calibri"/>
      <sz val="10"/>
      <color rgb="FF000000"/>
    </font>
    <font>
      <name val="Calibri"/>
      <sz val="10"/>
      <b/>
      <color rgb="FF000000"/>
    </font>
    <font>
      <name val="Calibri"/>
      <sz val="6"/>
      <b/>
      <color rgb="FF000000"/>
    </font>
  </fonts>
  <fills count="2">
    <fill>
      <patternFill patternType="none"/>
    </fill>
    <fill>
      <patternFill patternType="gray125"/>
    </fill>
  </fills>
  <borders count="2">
    <border>
      <left/>
      <right/>
      <top/>
      <bottom/>
      <diagonal/>
    </border>
    <border>
      <left/>
      <right/>
      <top style="thin">
        <color rgb="FF000000"/>
      </top>
      <bottom/>
      <diagonal/>
    </border>
  </borders>
  <cellXfs count="11">
    <xf numFmtId="0" fontId="0" fillId="0" borderID="0">
      <alignment horizontal="left"/>
    </xf>
    <xf numFmtId="0" fontId="1" fillId="0" borderID="0">
      <alignment horizontal="left"/>
    </xf>
    <xf numFmtId="0" fontId="1" fillId="0" borderID="0">
      <alignment horizontal="right"/>
    </xf>
    <xf numFmtId="0" fontId="2" fillId="0" borderID="0">
      <alignment horizontal="left"/>
    </xf>
    <xf numFmtId="0" fontId="2" fillId="0" borderID="0">
      <alignment horizontal="right"/>
    </xf>
    <xf numFmtId="49" fontId="1" fillId="0" borderID="0">
      <alignment horizontal="right"/>
    </xf>
    <xf numFmtId="3" fontId="1" fillId="0" borderID="0">
      <alignment horizontal="right"/>
    </xf>
    <xf numFmtId="4" fontId="1" fillId="0" borderID="0">
      <alignment horizontal="right"/>
    </xf>
    <xf numFmtId="3" fontId="2" fillId="0" borderID="1" applyBorder="1">
      <alignment horizontal="right"/>
    </xf>
    <xf numFmtId="4" fontId="2" fillId="0" borderID="1" applyBorder="1">
      <alignment horizontal="right"/>
    </xf>
    <xf numFmtId="0" fontId="3" fillId="0" borderID="0">
      <alignment horizontal="left"/>
    </xf>
  </cellXfs>
</styleSheet>

The cells with a border in the sheet1.xml defined as follows: That one with s="8" and s="9" should have a top border.

<row r="18">
  <c r="B18" t="inlineStr" s="4">
    <is>
      <t>Summe 2018:</t>
    </is>
  </c>
  <c r="C18" t="n" s="8">
    <v>5618.85</v>
  </c>
  <c r="D18" t="n" s="8">
    <v>16262.68</v>
  </c>
  <c r="E18" t="n" s="9">
    <v>4896.25</v>
  </c>
</row>

Solution

  • Its related to case-sensitivity of borderID="1" attribute in cell format , try to correct it to borderId="1".

    <xf numFmtId="3" fontId="2" fillId="0" borderId="1" applyBorder="1">
        <alignment horizontal="right"/>
    </xf>
    <xf numFmtId="4" fontId="2" fillId="0" borderId="1" applyBorder="1">
        <alignment horizontal="right"/>
    </xf>