public static void batchWriteExcel(String sourceExcelPath, String targetExcelPath) {
InputStream is = null;
//新建一個輸出流
OutputStream os = null;
Workbook workbook = null;
try {
is = ExcelUtils.class.getResourceAsStream(sourceExcelPath);
workbook = WorkbookFactory.create(is);
//得到第2個sheet
Sheet secondSheet = workbook.getSheetAt(1);
List<CellData> cellDatas = ApiUtils.getCellDataList();
for (CellData cellData : cellDatas) {
int rowNo = cellData.getRowNo();//行號
int coloumNo = cellData.getColumnNo();//列號
String content = cellData.getContent();//要寫的內容
//拿到要寫的行
Row currentRow = secondSheet.getRow(rowNo - 1);
//拿到要寫的列
Cell cell = currentRow.getCell(coloumNo - 1, MissingCellPolicy.CREATE_NULL_AS_BLANK);
cell.setCellType(CellType.STRING);
//設定要寫的內容
cell.setCellValue(content);
}
//寫回excel
os = new FileOutputStream(new File(targetExcelPath));
workbook.write(os);
} catch (Exception e) {
e.printStackTrace();
} finally {
close(workbook,os ,is );
}
}

批量寫入檔案的時候,報了獲取該行為空,有沒有大佬可以救一下命
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/131982.html
標籤:Eclipse
上一篇:疑問
