Supplying Beans

The developer supplies a map of bean names to bean values that are used in the transformation process. This map is used as a source of values for evaluating JEXL expressions that are contained in the template spreadsheet. JETT uses the name reference from a JEXL Expression as the bean name and looks up the bean value using the bean name as the key. Please see JEXL Expressions for more information on how JETT uses the beans map when processing Expressions.

Map<String, Object> beans = new HashMap<String,  Object>();
beans.put("beanName", bean);
beans.put("anotherBean", anotherBean);
            

Transformation

After bean creation, the developer supplies beans to an ExcelTransformer which controls the transformation of the template spreadsheet into the resulting spreadsheet. All bean values are available to all sheets found in the template spreadsheet.

FileOutputStream fileOut;
try
{
   fileOut = new FileOutputStream(outPath);
}
catch (IOException e)
{
   System.err.println("IOException opening " + outPath + ": " + e.getMessage();
}
InputStream fileIn = null;
try
{
   fileIn = new BufferedInputStream(new FileInputStream(inPath));
   ExcelTransformer transformer = new ExcelTransformer();
   Workbook workbook = transformer.transform(fileIn, beans);
   workbook.write(fileOut);
   fileOut.close();
}
catch (IOException e)
{
   System.err.println("IOException reading " + inPath + ": " + e.getMessage());
}
catch (InvalidFormatException e)
{
   System.err.println("InvalidFormatException reading " + inPath + ": " + e.getMessage();
}
            

Alternatively, JETT can handle the reading and writing of Excel files, if it is supplied with the input (template) and output (resultant) filenames.

try
{
   ExcelTransformer transformer = new ExcelTransformer();
   transformer.transform(inPath, outPath, beans);
}
catch (IOException e)
{
   System.err.println("IOException reading " + inPath + ": " + e.getMessage());
}
catch (InvalidFormatException e)
{
   System.err.println("InvalidFormatException reading " + inPath + ": " + e.getMessage();
}