我已经应用NPOI生成了excel。到目前为止,一切都很好,除了我想大胆地说一句。
我试过了:
tmpRow.RowStyle = workbook.CreateCellStyle();
tmpRow.RowStyle.SetFont(boldFont);然而,一切都没有改变。
而我可以通过逐个设置来完成:
ICellStyle boldFontCellStyle = workbook.CreateCellStyle();
IFont boldFont = workbook.CreateFont();
boldFont.IsBold = true;
boldFontCellStyle.SetFont(boldFont);
for (int p= 0; p <= 12; p++)
{
tmpRow.GetCell(p).CellStyle = boldFontCellStyle;
}
//tmpRow.RowStyle = workbook.CreateCellStyle();
//tmpRow.RowStyle.SetFont(boldFont);我想知道是否有在NPOI中设置整个行样式的方法?
谢谢。
发布于 2017-07-07 02:03:45
尝试使用此选项设置行样式
XSSFFont defaultFont = (XSSFFont)workbook.CreateFont();
defaultFont.FontHeightInPoints = (short)10;
defaultFont.FontName = "Arial";
defaultFont.Color = IndexedColors.Black.Index;
defaultFont.IsBold = true;
XSSFCellStyle yourCellStyle = (XSSFCellStyle)workbook.CreateCellStyle();
yourCellStyle.SetFont(defaultFont);
var row = sheet.CreateRow(0);
row.RowStyle = yourCellStyle;下面的一个是单元格样式
XSSFFont yourFont = (XSSFFont)workbook.CreateFont();
yourFont.FontHeightInPoints = (short)12;
yourFont.FontName = "Arial";
yourFont.IsBold = true;
yourFont.IsItalic = false;
yourFont.Boldweight = 700;
XSSFCellStyle yourStyle = (XSSFCellStyle)workbook.CreateCellStyle();
yourStyle.SetFont(yourFont);
for (int p= 0; p <= 12; p++)
{
row.Cells[p].CellStyle = yourStyle;
}发布于 2016-12-14 17:30:22
生成样式,设置它,然后将它应用于行。如下所示:
var rowStyle = workbook.CreateCellStyle();
rowStyle.SetFont(boldFont);
tmpRow.RowStyle = rowstyle;https://stackoverflow.com/questions/41138852
复制相似问题