I want to set style to a range. All works, but the border is override by the color.
How to only color the foreground, but keep the border lines?
Range rng = ws_risk.Cells.CreateRange(“A1:L1”);
rng.SetOutlineBorders(CellBorderType.Medium,Color.Black);
Aspose.Cells.Style st = wb.CreateStyle();
st.HorizontalAlignment = TextAlignmentType.Center;
st.VerticalAlignment = TextAlignmentType.Center;
@ibox
If you set StyleFlag.All to true, all style related settings will be replaced. You just need to set the parts that need to be replaced to true. Please refer to the following sample code.
The sample code as follows:
Workbook wb = new Workbook();
Worksheet ws_risk = wb.Worksheets[0];
Range rng = ws_risk.Cells.CreateRange("A1", "L1");
rng.SetOutlineBorders(CellBorderType.Medium, Color.Black);
Aspose.Cells.Style st = wb.CreateStyle();
st.HorizontalAlignment = TextAlignmentType.Center;
st.VerticalAlignment = TextAlignmentType.Center;
Color color = Color.FromArgb(240, 236, 236);
st.Pattern = BackgroundType.Solid;
st.ForegroundColor = color;
st.Font.Color = Color.Black;
st.Font.IsBold = true;
st.Font.Name = "Calibri";
st.Font.Size = 10;
StyleFlag flag = new StyleFlag();
flag.Alignments = true;
flag.FontBold = true;
flag.FontColor = true;
flag.Font = true;
flag.CellShading = true;
//comment this line
//flag.All = true;
rng.ApplyStyle(st, flag);
wb.Save(filePath + "out_net.xlsx");
About how to format a range, please refer to the following documents.