templateStream = getClass().getResourceAsStream(urlString);
} else {
templateStream = new URL(urlString).openStream();
}
} catch (Exception e) {
throw new ExcelWorkbookException(
"Could not handle template URI", e);
}
}
WorkbookSettings workbookSettings = null;
if (uiWorkbook.hasSettings()) {
workbookSettings = jxlHelper.createWorkbookSettings(uiWorkbook);
}
if (log.isDebugEnabled()) {
log.debug("Creating workbook with creation type #0", uiWorkbook
.getCreationType());
}
// The joys of multiple constructors and no setters...
try {
switch (uiWorkbook.getCreationType()) {
case WITH_SETTNGS_AND_TEMPLATE:
workbook = Workbook.createWorkbook(byteStream, Workbook
.getWorkbook(templateStream), workbookSettings);
break;
case WITH_SETTINGS_WITHOUT_TEMPLATE:
workbook = Workbook
.createWorkbook(byteStream, workbookSettings);
break;
case WITHOUT_SETTINGS_WITH_TEMPLATE:
workbook = Workbook.createWorkbook(byteStream, Workbook
.getWorkbook(templateStream));
break;
case WITHOUT_SETTINGS_OR_TEMPLATE:
workbook = Workbook.createWorkbook(byteStream);
break;
}
} catch (Exception e) {
throw new ExcelWorkbookException("Could not create workbook", e);
}
if (uiWorkbook.getWorkbookProtected() != null) {
workbook.setProtected(uiWorkbook.getWorkbookProtected());
}
currentWorksheetIndex = workbook.getNumberOfSheets();