OpenXML - SpreadsheetReader does not exist in the current context
Asked Answered
M

2

3

So I was trying to replicate this answer Getting cell-backgroundcolor in Excel with Open XML 2.0

but VS is complaining about SpreadsheetReader not existing in the current context. I can't ctrl+. resolve the issue.

Here is the (almost working) code:

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;
}
Messaline answered 23/7, 2015 at 10:35 Comment(0)
G
5

I solved this problem using DocumentFormat.OpenXml.Extensions. This extension can be downloaded from https://simpleooxml.codeplex.com/releases/view/48673

Cheers Karel Groos

Gamophyllous answered 31/7, 2015 at 8:8 Comment(0)
P
3

I by passed simpleOOXML by using

WorkbookStylesPart styles = document.WorkbookPart.WorkbookStylesPart;

instead of

WorkbookStylesPart styles = SpreadsheetReader.GetWorkbookStyles(document);
Prober answered 17/4, 2020 at 19:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.