Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用openXml向特定单元格添加颜色?_C#_Openxml - Fatal编程技术网

C# 如何使用openXml向特定单元格添加颜色?

C# 如何使用openXml向特定单元格添加颜色?,c#,openxml,C#,Openxml,我创建了这样的行和单元格= 行Row1=新行(){RowIndex=1} Row1.AppendChild(new Cell() { CellReference = "A1", DataType = CellValues.String, CellValue = new CellValue("Color this")

我创建了这样的行和单元格=

行Row1=新行(){RowIndex=1}

            Row1.AppendChild(new Cell()
            {
                CellReference = "A1",
                DataType = CellValues.String,
                CellValue = new CellValue("Color this")
            });
谁能告诉我如何在C#中使用openXml为这个特定的单元格着色?我不想给所有的细胞上色,只想给这个特定的细胞上色

找到解决方案=

您需要为此创建一个新的解决方案,并设置其背景色或前底色。然后需要创建一个引用该填充图案的填充。然后将单元格的样式索引设置为该单元格格式索引


在OpenXML中处理样式是一件非常痛苦的事情。除非您有很好的理由坚持使用OpenXML,否则我的建议是切换到类似的方式。

以下是您的操作和实现。它包含如何创建字体、填充、单元格格式等。非常感谢。我应该只使用OpenXML。我找到了解决方案,并将其添加到我的问题中。但是给你一个投票权:)