使用Apache POI复制Excel表

时间:2022-03-25 16:38:03

How to copy one entire Excel sheet into another Excel sheet of the same workbook, using Java SE and Apache POI?

如何使用Java SE和Apache POI将整个Excel表复制到同一工作簿的另一个Excel表中?

3 个解决方案

#1


13  

You'll probably want the cloneSheet(sheetNumber) method on the Workbook. See the JavaDocs for details

您可能希望在工作簿上使用cloneSheet(sheetNumber)方法。有关细节,请参见JavaDocs

#2


4  

Did you check the API?

你检查API了吗?

to copy a sheet into the same workbook, use HSSFWorkbook.clonesheet(int sheetIndex)

要将工作表复制到同一工作簿,请使用HSSFWorkbook。clonesheet(int sheetIndex)

Ivan's comment has linked the question for copying across workbooks.

Ivan的评论将这个问题与跨工作簿复制联系了起来。

#3


2  

Yes , this can be...Here my code.

是的,这可以是……我的代码。

            XSSFWorkbook workbook = new XSSFWorkbook(file);
            int totalRecords = 5;
            for (int i = 0; i < totalRecords - 1; i++) {
                workbook.cloneSheet(1);
            }
            for (int i = 1; i <= totalRecords; i++) {
                workbook.setSheetName(i, "S" + i);
            }

#1


13  

You'll probably want the cloneSheet(sheetNumber) method on the Workbook. See the JavaDocs for details

您可能希望在工作簿上使用cloneSheet(sheetNumber)方法。有关细节,请参见JavaDocs

#2


4  

Did you check the API?

你检查API了吗?

to copy a sheet into the same workbook, use HSSFWorkbook.clonesheet(int sheetIndex)

要将工作表复制到同一工作簿,请使用HSSFWorkbook。clonesheet(int sheetIndex)

Ivan's comment has linked the question for copying across workbooks.

Ivan的评论将这个问题与跨工作簿复制联系了起来。

#3


2  

Yes , this can be...Here my code.

是的,这可以是……我的代码。

            XSSFWorkbook workbook = new XSSFWorkbook(file);
            int totalRecords = 5;
            for (int i = 0; i < totalRecords - 1; i++) {
                workbook.cloneSheet(1);
            }
            for (int i = 1; i <= totalRecords; i++) {
                workbook.setSheetName(i, "S" + i);
            }