62,615
社区成员
发帖
与我相关
我的任务
分享
WritableWorkbook wwb = null;
try {
String[] fList = new String[] { "1.xls", "2.xls", "3.xls", "4.xls", "5.xls", "6.xls" };
wwb = Workbook.createWorkbook(new File("D:/union.xls"));
for (int i = 0; i < fList.length; i++) {
InputStream is = new FileInputStream(
"D:/" + fList[i]);
Workbook rwb = Workbook.getWorkbook(is);
Sheet st = rwb.getSheet(0);
wwb.importSheet("Sheet" + (i + 1), i, st);
WritableSheet sheet = wwb.getSheet(i);
for (int row = 0; row < st.getRows(); row++) {
for (int col = 0; col < st.getColumns(); col++) {
Label label = new Label(col, row, st.getCell(col, row)
.getContents());
if (st.getCell(col, row).getCellFormat() != null) {
WritableCellFormat format = new WritableCellFormat(
st.getCell(col, row).getCellFormat());
label.setCellFormat(format);
sheet.addCell(label);
}
}
}
rwb.close();
}
wwb.write();
wwb.close();
} catch (IOException e) {
e.printStackTrace();
} catch (BiffException ex) {
ex.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}