所以我试图复制这个答案使用 Openxml 2.0 在 Excel 中获取单元格背景颜色 https://stackoverflow.com/questions/10756206/getting-cell-backgroundcolor-in-excel-with-open-xml-2-0
但VS却在抱怨SpreadsheetReader
在当前上下文中不存在。我不能ctrl+.
解决问题。
这是(几乎可以工作)代码:
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using DocumentFormat.OpenXml;
public static DocumentFormat.OpenXml.Drawing.PatternFill GetCellPatternFill(Cell theCell, SpreadsheetDocument document)
{
WorkbookStylesPart styles = SpreadsheetReader.GetWorkbookStyles(document);
int cellStyleIndex;
if (theCell.StyleIndex == null) // I think (from testing) if the StyleIndex is null
{ // then this means use cell style index 0.
cellStyleIndex = 0; // However I did not found it in the open xml
} // specification.
else
{
cellStyleIndex = (int)theCell.StyleIndex.Value;
}
CellFormat cellFormat = (CellFormat)styles.Stylesheet.CellFormats.ChildElements[cellStyleIndex];
DocumentFormat.OpenXml.Drawing.Fill fill = (DocumentFormat.OpenXml.Drawing.Fill)styles.Stylesheet.Fills.ChildElements[(int)cellFormat.FillId.Value];
return fill.PatternFill;
}
我使用 DocumentFormat.OpenXml.Extensions 解决了这个问题。
该扩展程序可以从以下位置下载https://simpleooxml.codeplex.com/releases/view/48673 https://simpleooxml.codeplex.com/releases/view/48673
干杯卡雷尔·格鲁斯
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)