Sto cercando di ottenere il backgroundcolor di una cella in un foglio di calcolo Excel. Sto usando Open XML 2.0 SDK e sono in grado di aprire il file * .xlsx e di ottenere valori di cella per esempio. Il mio codice per ottenere il background-color è la seguente:Ottenere cell-backgroundcolor in Excel con Open XML 2.0
public BackgroundColor GetCellBackColor(Cell theCell, SpreadsheetDocument document)
{
BackgroundColor backGroundColor = null;
WorkbookStylesPart styles = SpreadsheetReader.GetWorkbookStyles(document);
int cellStyleIndex = (int)theCell.StyleIndex.Value;
CellFormat cellFormat = (CellFormat)styles.Stylesheet.CellFormats.ChildElements[cellStyleIndex];
Fill fill = (Fill)styles.Stylesheet.Fills.ChildElements[(int)cellFormat.FillId.Value];
backGroundColor = fill.PatternFill.BackgroundColor;
return backGroundColor;
}
Il mio problema qui è, che PatternFill.BackgroundColor
restituisce solo un numero naturale, penso che sia l'id dello stile. Il mio problema è che la riga di codice
DocumentFormat.OpenXml.Spreadsheet.Color c = (DocumentFormat.OpenXml.Spreadsheet.Color)styles.Stylesheet.Colors.ChildElements[Int32.Parse(backGroundColor.InnerText)];
ritorna con un errore, perché è Stylesheet.Colors
null
... ... forse è perché ho usato un "costruito nel" Colore in Excel - non è un auto-definito colore?!
Qualche idea su come "calcolare" il numero di colore reale da "backGroundColor-Value"?
Lo SpreadsheetReader classe non esiste in OpenXML 2.5 – Elmue