Last active
January 13, 2017 14:20
-
-
Save jecyhw/d8838238aab1ee02fc5b5532a7e94301 to your computer and use it in GitHub Desktop.
java jxl excel copy a sheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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