Apache POI. Copying sheets

后端 未结 2 1855
悲&欢浪女
悲&欢浪女 2020-12-10 08:14

I\'m using apache poi to create an excel document. To create new sheet in workbook I write next code:

Workbook wb = new HSSFWorkbook(); 
Sheet sh = wb.create         


        
2条回答
  •  旧巷少年郎
    2020-12-10 09:07

    You can't just take a Sheet object from one Workbook, and add it to a different Workbook.

    What you'll need to do is to open the old workbook and the new workbooks at the same time, and create the sheet in the new workbook. Next, clone all the styles you used in the old sheet onto the new one (HSSFCellStyle has a method for cloning a style from one workbook to another). Finally, iterate over all the cells and copy them over.

提交回复
热议问题