//設置頁眉頁腳 tempSheet.Header.Center = "2017-04-27"; tempSheet.Footer.Center = "√" + " 正常 " + "×" + " 故障 " + "○" + " 其他 "; //設置單元格邊線ICellStyle style = wb1 ...
//設置頁眉頁腳
tempSheet.Header.Center = "2017-04-27";
tempSheet.Footer.Center = "√" + " 正常 " + "×" + " 故障 " + "○" + " 其他 ";
//設置單元格邊線
ICellStyle style = wb1.CreateCellStyle();
style.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
style.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
style.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
style.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
//文字水平和垂直對齊方式
style2.Alignment = HorizontalAlignment.Center;
style2.VerticalAlignment = VerticalAlignment.Center;
style2.ShrinkToFit = true;
//設置excel單元格中的內容換行
cellStyle.setWrapText(true);其中cellStyle是WorkBook創建的CellStyle對象,然後將cellStyle設置到要換行的Cell對象,最後在要換行的對象(一般為字元串)加入"/r/n"。如
topTile.append("/r/n" +"cellContent");
//單元格的合併
sheet.addMergedRegion(new CellRangeAddress(0, 4, 0, 2));本示例為合併4行2列
//設置頁眉和頁腳的頁數
HSSFHeader header = sheet.getHeader();
header.setCenter("Center Header");
header.setLeft("Left Header");
header.setRight(HSSFHeader.font("Stencil-Normal", "Italic") +
HSSFHeader.fontSize((short) 16) + "Right w/ Stencil-Normal Italic font and size 16");
HSSFFooter footer = (HSSFFooter )sheet.getFooter()
footer.setRight( "Page " + HSSFFooter.page() + " of " + HSSFFooter.numPages() );
//使得一個Sheet適合一頁
sheet.setAutobreaks(true);
//設置放大屬性(Zoom被明確為一個分數,例如下麵的75%使用3作為分子,4作為分母)
sheet.setZoom(3,4);
//設置列印
HSSFPrintSetup print = (HSSFPrintSetup) sheet.getPrintSetup();
print.setLandscape(true);//設置橫向列印
print.setScale((short) 70);//設置列印縮放70%
print.setPaperSize(HSSFPrintSetup.A4_PAPERSIZE);//設置為A4紙張
print.setLeftToRight(true);//設置列印順序先行後列,預設為先列行
print.setFitHeight((short) 10);設置縮放調整為10頁高
print.setFitWidth((short) 10);設置縮放調整為寬高
sheet.setAutobreaks(false);
if (i != 0 && i % 30 == 0)
sheet.setRowBreak(i);//設置每30行分頁列印
//反覆的行和列(設置列印標題)
HSSFWorkbook wb = new HSSFWorkbook();
wb.setRepeatingRowsAndColumns(0, 0, 12, 1, 6);//設置1到12列,行1到6每一頁重覆列印
//調整單元格寬度
sheet.setAutobreaks(true);
sheet.setColumnWidth((short)i,colsWidth[i]); //設定單元格長度
sheet.autoSizeColumn((short) i);//自動根據長度調整單元格長度