1. 程式人生 > >POI 導出文檔整理

POI 導出文檔整理

== get TE file cat inpu vat row nonnull

1 通過模板獲取workbook

public static Workbook getWorkBook(String templatePath) {
try {
InputStream in = new FileInputStream(templatePath);
return new HSSFWorkbook(in);
} catch (IOException e) {
L.printException(e);
return null;
}
}

mSheet = workBook.getSheetAt(i);

2 sheet row

public static Row getCreateRow(Sheet sheet, int rowIndex) {
Row rowNew = sheet.getRow(rowIndex);
if (rowNew == null) {
rowNew = sheet.createRow(rowIndex);
}
return rowNew;
}

3 row -->cell

private static Cell getCreateCell(@NonNull Row rowNew, int m) {
Cell cell = rowNew.getCell(m);
if (cell == null) {
cell = rowNew.createCell(m);
}
return cell;
}

5cell- value

public static int fillCell(Row rowNew, int m, String value) {
Cell cell = getCreateCell(rowNew, m);
cell.setCellValue(value);
m++;
return m;
}

POI 導出文檔整理