- WritableFont headFont = new WritableFont(WritableFont.TIMES, 14,WritableFont.BOLD);
- //設置標題,字號14,加粗
- <P>WritableFont countents = new WritableFont(WritableFont.TIMES,12); // 設置單元格內容,字號12
- WritableCellFormat cell = new WritableCellFormat(contentFont);
- cell.setAlignment(jxl.format.Alignment.CENTRE);// 單元格內容水平居中
- cell.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);// 單元格內容垂直居中
- cell.setBorder(Border.ALL, BorderLineStyle.THIN,jxl.format.Colour.BLACK); // 邊框
- // Border.ALL:上下左右都設置邊框; BorderLineStyle.THIN: 細邊框; jxl.format.Colour.BLACK: 黑顏色
- cell.setWrap(true);//是否換行
- WritableSheet sheet = book.createSheet("公文檢索", 0); //創建一個新sheet
- sheet.setColumnView(0, 80); //第1列寬
- sheet.setColumnView(1, 80); //第2列寬
- sheet.setRowView(i+1, 400);//某行的行高,一般用在循環中
- //合並單元格
- sheet.mergeCells(3,0,4,0);//(列,行,列,行)
- //設置頁邊距(0.1d=0.26cm)
- sheet.getSettings().setBottomMargin(0.7d);
- sheet.getSettings().setTopMargin(0.7d);
- sheet.getSettings().setLeftMargin(0.75d);
- sheet.getSettings().setRightMargin(0.75d);
- //設置打印方向為 橫向,不設置為縱向
- sheet.setPageSetup(PageOrientation.LANDSCAPE.LANDSCAPE,PaperSize.A4,0.5d,0.5d);
- //設置頁碼,3個參數位置分別對應:左邊、中間、右邊
- sheet.setFooter("", "&P", "");
- //設置凍結單元格,下拉時第一列固定
- sheet.getSettings().setVerticalFreeze(1);
- //設置是否顯示行數列數編號
- sheet.getSettings().setPrintHeaders(true);
注:轉載自https://xqqing79.iteye.com/blog/1454326