贊助商連結

POI tips

by undefined

設定橫印

1
2
3
4
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用來設定儲存格格式、字型、顏色、字大小

1
2
3
4
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

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

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

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

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

設定列印縮小到一頁

Fit Sheet to One Page - POI Document


喜歡我們的文章可以按上面的 LIKE 給我們鼓勵喔!