Xlsx styles getting wrong fill pattern

给你一囗甜甜゛ 提交于 2019-12-25 02:42:56

问题


I am writing an xlsx file where I want to apply my own styles to cells in a worksheet. I have a case where style 1 and style 2 both specify solid red, but when I open it in excel the first is gray stippled but the second is what I expect. I am stumped.. Here are some bits of xml from the attached file.

In the worksheet, I have 2 cells:

  <x:c t="inlineStr" s="2">
    <x:is>
      <x:t>looks right</x:t>
    </x:is>
  </x:c>
  <x:c t="inlineStr" s="1">
    <x:is>
      <x:t>looks wrong</x:t>
    </x:is>
  </x:c>

In the styles.xml file, I define these cell styles as follows:

<x:cellXfs>
  <x:xf borderId="0" fillId="0" fontId="0" numFmtId="0"/>
  <x:xf fillId="1" applyFill="1"/>
  <x:xf fillId="2" applyFill="1"/>      
</x:cellXfs>

Where the fills are:

<x:fills>
  <x:fill>
    <x:patternFill patternType="none"/>
  </x:fill>
  <x:fill>
    <x:patternFill patternType="solid">
      <x:fgColor rgb="FFFF0000"/>
    </x:patternFill>
  </x:fill>
  <x:fill>
    <x:patternFill patternType="solid">
      <x:fgColor rgb="FFFF0000"/>
    </x:patternFill>
  </x:fill>
</x:fills>

Fills 1 and 2 are both solid red, so cell styles 1 and 2 should be identical, right? But they are not.

Is this an Excel bug? Is there a pre-defined fill style numbered 1 that overrides my definition?

Hmm, I don't see how to attach a file to a question...


回答1:


Turns out that my second guess was right. Fill #1 is hardwired to gray125. Excel ignores the definition of this fill while reading the xml. Would have been nice if this were documented somewhere.



来源:https://stackoverflow.com/questions/19731176/xlsx-styles-getting-wrong-fill-pattern

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!