POI tips

設定橫印

HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet(SHEET_NAME);
HSSFPrintSetup ps = sheet.getPrintSetup();
ps.setLandscape(true);

http://www.iteye.com/problems/7083

Word-warp

Using newlines in cells

http://poi.apache.org/spreadsheet/quick-guide.html

HSSFCellStyle用來設定儲存格格式、字型、顏色、字大小

HSSFWorkbook wb = new HSSFWorkbook();
HSSFCellStyle textHVCentel = wb.createCellStyle();
textHVCentel.setAlignment(HSSFCellStyle.ALIGN_CENTER);
textHVCentel.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);

http://stackoverflow.com/questions/5335285/write-number-in-excel-cell-with-poi

CellReference

CellReference 是用來轉換 Excel 位置與 POI 位置

例如 A1 <> 0,0 B2 <> 1,1

CellReference cr1 = new CellReference(1, 1);
cr1.formatAsString() // will output "B2"

寫入 Excel 公式,不用加 [ = ]

hssfRow.createCell(cellIndex).setCellFormula("SUM(A1:A12)");

http://poi.apache.org/spreadsheet/formula.html

設定列印縮小到一頁

Fit Sheet to One Page - POI Document

Follow 院長與芊比媽 on Google News