c# - 如何使用 openXml 为特定单元格添加颜色?
问题描述
我创建了这样的行和单元格=
行 Row1 = new Row() { RowIndex = 1 };
Row1.AppendChild(new Cell()
{
CellReference = "A1",
DataType = CellValues.String,
CellValue = new CellValue("Color this")
});
谁能告诉我如何在 C# 中使用 openXml 为这个特定的单元格着色?我不想给所有的单元格上色,只给这个特定的单元格上色。
解决方案
您需要为此创建一个PatternFill并设置其背景色或前景色。然后您将需要创建一个引用该PatternFill的 CellFormat。然后将单元格的 StyleIndex 设置为该 CellFormat-index。
在 OpenXML 中处理样式是一件非常痛苦的事情。除非您有充分的理由坚持使用 OpenXML,否则我的建议是改用ClosedXML之类的东西。
推荐阅读
- inno-setup - 使用 Inno Setup 进行条件签名
- javascript - 将 CSV 转换为 JSON 并使用 JS 将 JSON 放入 html 表中
- apache-flex - 相当于来自 flex 的父 parentDocument
- php - laravel 作业未执行 - 尝试次数过多或运行时间过长
- mongodb - 我正在 Meteor 中做一些项目,并想在 mongodb 中插入一些图像以及其他信息,如流派、固定评级等
- mysql - MySQL在不使用表列的情况下选择两列之间的范围日期
- c# - 如何防止第三方应用检测到用户空闲?
- laravel - Laravel live wire 手风琴在输入更改时崩溃
- angular - 正确使用 Angular Material 和 mat-tables 的虚拟滚动?
- javascript - 我可以在 bitmovin 视频播放器的视频元素中添加标题属性吗?