It is possible to supply different beans Maps to different Sheets. Use an overloaded "transform" method in ExcelTransformer:
List<String> templateSheetNames = new ArrayList<String>(); List<String> sheetNames = new ArrayList<String>(); List<Map<String, Object>> beansList = new ArrayList<Map<String, Object>>(); // Populate each list here with the same number of objects, before calling "transform". Workbook workbook = transformer.transform(fileIn, templateSheetNames, sheetNames, beansList);
It is also possible to let JETT handle the reading and writing of the Excel files when supplying different beans Maps to different Sheets. Use another overloaded "transform" method in ExcelTransformer:
List<String> templateSheetNames = new ArrayList<String>(); List<String> sheetNames = new ArrayList<String>(); List<Map<String, Object>> beansList = new ArrayList<Map<String, Object>>(); // Populate each list here with the same number of objects, before calling "transform". transformer.transform(inPath, outPath, templateSheetNames, sheetNames, beansList);
It is also possible to specify that a certain sheet in the template spreadsheet should be cloned, with a different Map of beans supplied to each cloned Sheet.
To specify that a Sheet should be cloned, include multiple copies of the same template sheet name in the "templateSheetNames" list, along with unique sheet names in the "sheetNames" list, and separate maps of beans for each Sheet.
This example starts with a template spreadsheet containing only two sheets, "intro" and "sheetToClone", but the resultant spreadsheet contains five sheets, "Introduction", "Q1 2011", "Q2 2011", "Q3 2011", and "Q4 2011".
List<String> templateSheetNames = new ArrayList<String>(); List<String> sheetNames = new ArrayList<String>(); List<Map<String, Object>> beansList = new ArrayList<Map<String, Object>>(); // Populate each list here with the same number of objects. templateSheetNames.add("intro"); sheetNames.add("Introduction"); beansList.add(introBeansMap); templateSheetNames.add("sheetToClone"); sheetNames.add("Q1 2011"); beansList.add(map2011q1); templateSheetNames.add("sheetToClone"); sheetNames.add("Q2 2011"); beansList.add(map2011q2); templateSheetNames.add("sheetToClone"); sheetNames.add("Q3 2011"); beansList.add(map2011q3); templateSheetNames.add("sheetToClone"); sheetNames.add("Q4 2011"); beansList.add(map2011q4); Workbook workbook = transformer.transform(fileIn, templateSheetNames, sheetNames, beansList);
Here is the template spreadsheet, with both sheets:
After transformation, there are now 5 sheets, with the last 4 sheets being copies of the original sheet to clone: