Skip to content

Instantly share code, notes, and snippets.

@jecyhw
Last active January 13, 2017 14:20
Show Gist options
  • Save jecyhw/d8838238aab1ee02fc5b5532a7e94301 to your computer and use it in GitHub Desktop.
Save jecyhw/d8838238aab1ee02fc5b5532a7e94301 to your computer and use it in GitHub Desktop.
java jxl excel copy a sheet
private void copyExcelSheet(Sheet sourceSheet, WritableSheet destSheet) {
for (int i = 0; i < sourceSheet.getRows(); ++i) {
for (int j = 0; j < sourceSheet.getColumns(); ++j) {
Cell cell = sourceSheet.getCell(j, i);
Label label = new Label(j, i, cell.getContents().trim());
CellFormat readFormat = cell.getCellFormat();
if (readFormat != null) {
label.setCellFormat( new WritableCellFormat(readFormat));
}
try {
destSheet.addCell(label);
} catch (WriteException e) {
e.printStackTrace();
}
}
}
}
//WritableWorkbook.write();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment