POI 导出文档整理

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;
}

猜你喜欢

转载自www.cnblogs.com/spps/p/9217683.html