I wanna set style such as font color and font size for the first column, and also wanna set backgroundcolor for row alternate white and gray. it looks like only the style set last can apply.
Hi,
Yes, it is possible. You need to use Cell.SetStyle(Style,Boolean) method.
Please see the code below. It loads a source file that contains a cell with foreground color red, it updates the cell fill color with yellow without modifying the existing style.
Please also see the input file and the output file attached by me. I have also provided a screenshot for your reference.
C#
string filePath = @“F:\Shak-Data-RW\Downloads\source.xlsx”;
Workbook workbook = new Workbook(filePath);
Worksheet worksheet = workbook.Worksheets[0];
//The cell’s font color is alread red
Cell cell = worksheet.Cells[“A1”];
//Now apply forground color to yellow on cell without changing its existing style.
Style st = workbook.CreateStyle();
st.Pattern = BackgroundType.Solid;
st.ForegroundColor = Color.Yellow;
cell.SetStyle(st, true);
workbook.Save(filePath + “.out.xlsx”);
Screenshot:
Thanks. Got it.