1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| /**
* Get the excel data.
*
* @param key key
* @param exportList contact list
* @param templateFilePath template file path
* @return the excel data
* @throws NotSerializableException thrown if the input list of objects to be exported do not implement java.io.Serializable
*/
public final ByteArrayOutputStream getExcelData(String key, String templateFilePath, List<Serializable> exportList) throws NotSerializableException {
if(!(exportList instanceof java.io.Serializable) ){
throw new NotSerializableException(exportList.getClass().getName());
}
Map<String, List<Serializable>> beans = new HashMap<String, List<Serializable>>();
beans.put(key, exportList);
InputStream templateXsl = ExportService.class.getClassLoader().getResourceAsStream(templateFilePath);
if (templateXsl == null) {
return null;
}
return getExcelData(beans, templateXsl);
}
/**
* Get the excel data.
*
* @param beans object that will be processed : must implement java.io.Serializable
* @param templateXsl template xsl
* @return the excel data
* @throws NotSerializableException
*/
private final ByteArrayOutputStream getExcelData(Map<String, List<Serializable>> beans, InputStream templateXsl) throws NotSerializableException {
if(!(beans instanceof java.io.Serializable) ){
throw new NotSerializableException(beans.getClass().getName());
}
XLSTransformer transformer = new XLSTransformer();
HSSFWorkbook temp = transformer.transformXLS(templateXsl, beans);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
temp.write(bos);
} catch (Exception e) {
logger.error("Error while exporting the excel data", e);
}
return bos;
} |
Partager