所以我试图复制这个答案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
{ …Run Code Online (Sandbox Code Playgroud)