0

I'm using Apache Poi in java to copy an excel sheet to the same workbook This way :

    FileInputStream file = new FileInputStream(new File("exemple.xlsx"));
            
    XSSFWorkbook workbook = new XSSFWorkbook(file);
             
            
    XSSFSheet sheet_copy =   workbook.cloneSheet(0);
            
    int num = workbook.getSheetIndex(sheet_copy);
            
    workbook.setSheetName(num, "copy_file");


    FileOutputStream outputStream = new FileOutputStream("exemple.xlsx");

    workbook.write(outputStream);
    

the file "sheet_copy" is created as well , but it doesn't have the same scale as the first one , The first one has 59% and the second one 100% when i try to save it as pdf it's too much big, how to solve that in code ? i mean that sheet_copy gets the same format as the original one , i don't want to do it manually .

dEs12ZER
  • 788
  • 4
  • 24
  • 51
  • See if [this](https://stackoverflow.com/questions/60953193/sxssfworkbook-write-to-fileoutputstream-writes-huge-files) will work for you. You may have to change your workboot format and try the answer and code suggested. – Alias Cartellano Sep 16 '21 at 18:43
  • @AliasCartellano Thank's for your help; i tried to do the same, changed my workbook format and everything but now i'm stuck im getting exception about cloneSheet : Not Implemented at org.apache.poi.xssf.streaming.SXSSFWorkbook.cloneSheet , don't know what to do .. – dEs12ZER Sep 16 '21 at 23:16
  • I see in the docs clonesheet is not implemented in SXSSF, might have to find another way around. – Alias Cartellano Sep 17 '21 at 01:07
  • 1
    If you are open with other api (mean not open source), see this: https://dev.to/eiceblue/copy-and-move-excel-worksheets-in-java-31d6 – Dheeraj Malik Sep 17 '21 at 02:39
  • @AliasCartellano exactly – dEs12ZER Sep 17 '21 at 20:57
  • @DheerajMalik i changed to Spire.XLS as you suggested, the format of the copy file is exactly the same as the original one , Thank you :) , do you have any idea about how to remove the signature of spire.xls when exporting to pdf ? – dEs12ZER Sep 17 '21 at 20:58
  • @dEs12ZER If you are using the paid version, you can request a one month free trial license from [here](https://www.e-iceblue.com/TemLicense.html). – Dheeraj Malik Sep 18 '21 at 01:35

0 Answers0