How to set the background of several cells inside a row (or an entire row) in OpenXml?
After reading a few articles:
I still can't get it to work.
At first glance, my task seems to be somewhat simpler and slightly different from what is written in these articles. The textbooks mentioned predominantly show how to create a new document and create it. Although I need to change the style of the existing one.
That is, I have an existing xlsx document (report template). I fill out the report with the necessary values (I managed to do this thanks to SO open xml excel read cell value and MSDN Working with Sheets (Open XML SDK) ). But then I need to mark a few lines, for example, with a red background.
I'm not sure whether to use CellStyle , and if I have to use CellFormat or something else ... This is what I got so far:
SpreadsheetDocument doc = SpreadsheetDocument.Open("ole.xlsx", true); Sheet sheet = (Sheet)doc.WorkbookPart .Workbook .Sheets .FirstOrDefault(); WorksheetPart worksheetPart = (WorksheetPart)doc.WorkbookPart .GetPartById(sheet.Id); Worksheet worksheet = worksheetPart.Worksheet; CellStyle cs = new CellStyle(); cs.Name = StringValue.FromString("Normal"); cs.FormatId = 0; cs.BuiltinId = 0;
In fact, I would really appreciate an easier and simpler example of how to style, say, an A20 cell, or vary from A20 to J20 . Or perhaps a link to another sequential tutorial.
source share