use of jxl.write.biff.JxlWriteException in project janrufmonitor by tbrandt77.
the class XlsFilter method doExport.
public boolean doExport() {
if (m_filename == null || m_filename.length() == 0)
return false;
WritableWorkbook wb = null;
try {
wb = Workbook.createWorkbook(new File(m_filename));
WritableSheet sheet = wb.createSheet("journal", 0);
// get renderers
List renderer = new ArrayList();
String renderer_config = this.getRuntime().getConfigManagerFactory().getConfigManager().getProperty("ui.jface.application.journal.Journal", "renderer");
if (renderer_config != null && renderer_config.length() > 0) {
StringTokenizer s = new StringTokenizer(renderer_config, ",");
while (s.hasMoreTokens()) {
renderer.add(RendererRegistry.getInstance().getRenderer(s.nextToken()));
}
}
ITableCellRenderer t = null;
Label cell = null;
for (int i = 0, j = renderer.size(); i < j; i++) {
t = (ITableCellRenderer) renderer.get(i);
if (t == null) {
this.m_logger.severe("No renderer found for ID: " + (String) renderer.get(i));
this.m_logger.severe("Export to XLS format canceled...");
return false;
}
cell = new Label(i, 0, t.getHeader());
sheet.addCell(cell);
}
int[] widths = new int[renderer.size()];
ICall c = null;
String cellContent = null;
for (int k = 0, i = 0, j = this.m_callList.size(); i < j; i++) {
try {
c = this.m_callList.get(i);
k = 0;
for (int m = renderer.size(); k < m; k++) {
t = (ITableCellRenderer) renderer.get(k);
t.updateData(c);
cellContent = t.renderAsText();
if (cellContent != null && cellContent.length() > 0) {
widths[k] = Math.max(widths[k], cellContent.length());
cell = new Label(k, i + 1, cellContent);
sheet.addCell(cell);
} else {
cellContent = t.renderAsImageID();
if (cellContent != null && cellContent.length() > 0) {
if (cellContent.indexOf(".") > -1)
cellContent = cellContent.substring(0, cellContent.indexOf("."));
widths[k] = Math.max(widths[k], cellContent.length());
cell = new Label(k, i + 1, cellContent);
} else
cell = new Label(k, i + 1, " ");
sheet.addCell(cell);
}
cell = null;
}
} catch (JxlWriteException e) {
this.m_logger.severe(e.getMessage());
this.m_logger.severe("Ignored data [" + (k + 1) + ", " + (i + 1) + "] for Excel export: " + cellContent);
}
}
// calculate width
for (int i = 0, j = renderer.size(); i < j; i++) {
sheet.setColumnView(i, widths[i]);
}
wb.write();
} catch (Exception e) {
this.m_logger.severe(e.getMessage());
return false;
} finally {
try {
if (wb != null)
wb.close();
} catch (WriteException ex) {
this.m_logger.severe(ex.getMessage());
return false;
} catch (IOException ex) {
this.m_logger.severe(ex.getMessage());
return false;
}
}
return true;
}
Aggregations