WritableWorkbook outWorkBook = Workbook.createWorkbook(new File("C://temp//txtorexcel//out//out.xls"));
WritableSheet outSheet = outWorkBook.createSheet("Results", 0);
try {
Workbook inWorkbook = Workbook.getWorkbook(new File("C://temp//txtorexcel//in//in.xls"));
Sheet inSheet = inWorkbook.getSheet(1);
int rowCount = 345;//need to change
int colCount = 20;//need to change
int targetRow=0;
int targetCol=0;
for (int row = 109; row<rowCount; row++, targetRow++){
targetCol=0;
for (int col = 4; col<colCount; col++, targetCol++){
Cell cell = inSheet.getCell(col,row);
if ( cell.getContents().trim() == ""){
outSheet.addCell(new Label(targetCol, targetRow, "NA"));
} else {
outSheet.addCell(new Label(targetCol, targetRow, cell.getContents()));
}
}
}
outWorkBook.write();
outWorkBook.close();
inWorkbook.close();
} catch (Exception e) {
e.printStackTrace();
}
同事的代码
最新推荐文章于 2023-06-13 23:45:00 发布