Excel의 스프레드 시트에서 셀의 배경색을 가져 오려고합니다. Open XML 2.0 SDK를 사용하고 있으며 * .xlsx 파일을 열고 셀 값을 가져올 수 있습니다. 단지 자연수 PatternFill.BackgroundColor
반환, 나는 그것이 스타일의 ID의 생각, 여기Open XML 2.0을 사용하여 Excel에서 cell-backgroundcolor 가져 오기
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;
}
내 문제 : 배경색을 얻기를위한 내 코드는 다음과 같다. 아닌 자기가 정의 - 내 문제는 Stylesheet.Colors
가 null
때문에 나는 Excel에서 색 "내장"사용하기 때문에 코드 오류와
DocumentFormat.OpenXml.Spreadsheet.Color c = (DocumentFormat.OpenXml.Spreadsheet.Color)styles.Stylesheet.Colors.ChildElements[Int32.Parse(backGroundColor.InnerText)];
반환 라인이 ... ... 어쩌면이 있다고한다 색깔?!
"backGroundColor-Value"에서 실제 색상 수를 "계산할"수있는 아이디어가 있습니까?
클래스 SpreadsheetReader가 아닌 좋은 답변을 주셔서 감사합니다 OpenXML을 2.5 – Elmue