我正在尝试在特定单元格上使文本变粗体,但不能。这是我正在使用的代码:
Style boldStyle = workBook.CreateStyle();
boldStyle.BackgroundColor = Color.Red;
StyleFlag boldStyleFlag = new StyleFlag();
boldStyleFlag.HorizontalAlignment =true ;
boldStyleFlag.FontBold = true;
Cell c = workSheetIntroduction.Cells["B1"];
c.SetStyle(boldStyle, boldStyleFlag);
Workbook workBook = new Workbook();
Worksheet workSheetIntroduction = workBook.Worksheets[0];
//This Style object will make the fill color Red and font Bold
Style boldStyle = workBook.CreateStyle();
boldStyle.ForegroundColor = Color.Red;
boldStyle.Pattern = BackgroundType.Solid;
boldStyle.Font.IsBold = true;
//Bold style flag options
StyleFlag boldStyleFlag = new StyleFlag();
boldStyleFlag.HorizontalAlignment = true;
boldStyleFlag.FontBold = true;
//Apply this style to row 1
Row row1 = workBook.Worksheets[0].Cells.Rows[0];
row1.ApplyStyle(boldStyle, boldStyleFlag);
//Now set the style of indvidual cell
Cell c = workSheetIntroduction.Cells["B1"];
Style s = c.GetStyle();
s.ForegroundColor = Color.Red;
s.Pattern = BackgroundType.Solid;
s.Font.IsBold = true;
c.SetStyle(s);
//Save the workbook
workBook.Save("output.xlsx");
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句