HSSFWorkbook workbook = null;
InputStream fis = new FileInputStream(filePath);
workbook = new HSSFWorkbook(fis);
for (int i = 0; i < 3; i++) {
HSSFSheet newsheet = null;
HSSFSheet fromsheet = workbook.getSheet("sheet1");
newsheet = workbook
.createSheet("tt_" + (String.valueOf(i + 1)));
copyRows(workbook, fromsheet, newsheet, fromsheet
.getFirstRowNum(), fromsheet.getLastRowNum());
}
@SuppressWarnings("deprecation")private static void copyRows(HSSFWorkbook workbook, HSSFSheet fromsheet, HSSFSheet newsheet, int firstrow, int lastrow){if ((firstrow == -1) || (lastrow == -1) || lastrow < firstrow){return;}// 拷贝合并的单元格Region region = null;for (int i = 0; i < fromsheet.getNumMergedRegions(); i++){region = fromsheet.getMergedRegionAt(i);if ((region.getRowFrom() >= firstrow) && (region.getRowTo() <= lastrow)){newsheet.addMergedRegion(region);}}HSSFRow fromRow = null;HSSFRow newRow = null;HSSFCell newCell = null;HSSFCell fromCell = null;// 设置列宽for (int i = firstrow; i <= lastrow; i++){fromRow = fromsheet.getRow(i);if (fromRow != null){for (int j = fromRow.getLastCellNum(); j >= fromRow.getFirstCellNum(); j--){int colnum = fromsheet.getColumnWidth((short) j);if (colnum > 100){newsheet.setColumnWidth((short) j, (short) colnum);}if (colnum == 0){newsheet.setColumnHidden((short) j, true);}else{newsheet.setColumnHidden((short) j, false);}}break;}}// 拷贝行并填充数据for (int i = 0; i <= lastrow; i++){fromRow = fromsheet.getRow(i);if (fromRow == null){continue;}newRow = newsheet.createRow(i - firstrow);newRow.setHeight(fromRow.getHeight());for (int j = fromRow.getFirstCellNum(); j < fromRow.getPhysicalNumberOfCells
}