private static void copySheet(Sheet sourceSheet, Sheet destSheet) {
// 复制Sheet中的行
int rows = sourceSheet.getLastRowNum();
for (int i = 0; i <= rows; i++) {
Row sourceRow = sourceSheet.getRow(i);
Row destRow = destSheet.createRow(i);
if (sourceRow != null) {
// 复制行中的单元格
int cells = sourceRow.getLastCellNum();
for (int j = 0; j < cells; j++) {
Cell sourceCell = sourceRow.getCell(j);
Cell destCell = destRow.createCell(j);
if (sourceCell != null) {
// 复制单元格的值
if(sourceCell.getCellTypeEnum() == CellType.STRING) {
destCell.setCellValue(sourceCell.getStringCellValue());
}else if(sourceCell.getCellTypeEnum() == CellType.NUMERIC) {
destCell.setCellValue(sourceCell.getNumericCellValue());
}else if(sourceCell.getCellTypeEnum() == CellType.NUMERIC) {
destCell.setCellValue(sourceCell.getNumericCellValue());
}
}
}
}
}
}
JAVA 复制Sheet
最新推荐文章于 2024-01-09 20:43:36 发布