NPOI版本:V1.2.4.0
IFont font = WB.CreateFont();
ICellStyle style1 = Sheet.GetRow(0).GetCell(0).CellStyle;
font.Boldweight = (short)NPOI.SS.UserModel.FontBoldWeight.BOLD;
style1.SetFont(font);
本来是想对A1这个单元格加粗,结果执行了之后,所有单元格都加粗了,为什么呢?
同时,就算我只想把某个单元格加边框:style1 = Sheet.GetRow(0).GetCell(0).CellStyle;
style1.BorderBottom = CellBorderType.THIN;
style1.BorderLeft = CellBorderType.THIN;
style1.BorderRight = CellBorderType.THIN;
style1.BorderTop = CellBorderType.THIN;
结果也是整个工作表都加边框了。

解决方案 »

  1.   


    HSSFSheet sheet = hssfworkbook.CreateSheet("new sheet");
     
    // Create a row and put some cells in it. Rows are 0 based.
    HSSFRow row = sheet.CreateRow(1);
    // Create a cell and put a value in it.
    HSSFCell cell = row.CreateCell(1);
    // Style the cell with borders all around.
    HSSFCellStyle style = hssfworkbook.CreateCellStyle();
    style.BorderBottom= HSSFCellStyle.BORDER_THIN;
    style.BorderLeft= HSSFCellStyle.BORDER_THIN;
    style.BorderRight= HSSFCellStyle.BORDER_THIN;
    style.BorderTop = HSSFCellStyle.BORDER_THIN ;
    cell.CellStyle= style;