Created attachment 29185 [details] Excel file passed in argument When cloning a sheet with checkboxes in it (control form type), the resulting file is corrupted. Step to reproduce : use this with the file attached public static void main(String[] args) throws FileNotFoundException, IOException { Workbook wb = new XSSFWorkbook(new FileInputStream(args[0])); wb.cloneSheet(0); FileOutputStream fileOut = new FileOutputStream(args[0].replace(".xlsx", "-edited.xlsx")); wb.write(fileOut); fileOut.flush(); fileOut.close(); } result : the second sheet is corrupted and do not have the checkbox
Created attachment 30027 [details] The original file with Form Control This is the original file. The first sheet has conditional formatting, some VB code, a macro and a Form Control Button.
Created attachment 30028 [details] The Cloned Document This is the newly created file with the first sheet cloned.
I believe this condition exists with any Form Control. I have attached a workbook where the first sheet has a form control button on it. If you clone that sheet, the generated sheet has errors in it. If you remove the form control, the sheet clones just fine (even with conditional formatting). I used the following program to clone the original: public class ReadWriteTest { public ReadWriteTest(String input, String output) { try { File inputFile = new File(input); if (inputFile.exists()) { Workbook excel = new XSSFWorkbook(new FileInputStream(inputFile)); Sheet newSheet = excel.cloneSheet(0); excel.setSheetName(excel.getSheetIndex(newSheet), "Clone"); File outputFile = new File(output); boolean create = ! outputFile.exists(); if (! create) { create = (JOptionPane.showConfirmDialog(null, "File exists, do you want to overwrite?") == JOptionPane.OK_OPTION); } if (create) { excel.write(new FileOutputStream(outputFile)); } System.exit(0); } else { System.out.println("Input file " + input + " not found."); System.exit(1); } } catch(Exception ex) { ex.printStackTrace(); System.exit(1); } } public static void main(String[] args) { if (args.length == 2) { new ReadWriteTest(args[0], args[1]); } else { System.out.println("USAGE: ReadWriteTest <input_file_name> <output_file_name>"); System.exit(1); } } }