use of jxl.write.WritableWorkbook in project cubrid-manager by CUBRID.
the class ExportTableDefinitionProgress method run.
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
// FIXME move this logic to core module
WritableWorkbook wwb = null;
Connection conn = null;
try {
conn = JDBCConnectionManager.getConnection(database.getDatabaseInfo(), true);
List<String> exportTableNames = getExportTables(conn);
List<SchemaInfo> exportSchemaInfoList = getExportSchemaInfoList(conn, exportTableNames);
loadSchemaCommentData(conn);
monitor.beginTask(Messages.exportTableDefinitionProgressTaskWrite, exportTableNames.size() + 1);
WorkbookSettings workbookSettings = new WorkbookSettings();
workbookSettings.setEncoding(fileCharset);
wwb = Workbook.createWorkbook(new File(exlFullPath), workbookSettings);
monitor.subTask(Messages.exportTableDefinitionProgressTaskTableList);
tableDefinitionLayout.generateTableNamesSheet(wwb, exportTableNames);
monitor.worked(1);
tableDefinitionLayout.generateTableDetailSheets(wwb, conn, exportSchemaInfoList, monitor);
wwb.write();
openSuccessDialog(Messages.exportTableDefinitionExportSuccess);
success = true;
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
openErrorDialog(e.getMessage());
} finally {
QueryUtil.freeQuery(conn);
if (wwb != null) {
try {
wwb.close();
} catch (Exception ex) {
LOGGER.error("close excel stream error", ex);
}
}
}
}
use of jxl.write.WritableWorkbook in project cubrid-manager by CUBRID.
the class ExportErrorDataProgress method run.
/* (non-Javadoc)
* @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
*/
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
// FIXME logic code move to core module
WritableWorkbook wwb = null;
try {
WorkbookSettings workbookSettings = new WorkbookSettings();
workbookSettings.setEncoding(charset);
wwb = Workbook.createWorkbook(new File(filePath), workbookSettings);
int index = 0;
for (Entry<String, List<SqlRunnerFailed>> entry : failedListMap.entrySet()) {
WritableSheet ws = wwb.createSheet(entry.getKey(), index++);
WritableCellFormat normalCellStyle = getNormalCell();
WritableCellFormat titleCellStyle = getTitleCell();
jxl.write.Label header = new jxl.write.Label(0, 0, Messages.failedSQLlineNumber, titleCellStyle);
ws.addCell(header);
jxl.write.Label header1 = new jxl.write.Label(1, 0, Messages.failedSQL, titleCellStyle);
ws.addCell(header1);
jxl.write.Label header2 = new jxl.write.Label(2, 0, Messages.failedErrorMessage, titleCellStyle);
ws.addCell(header2);
ws.setColumnView(1, 100);
ws.setColumnView(2, 80);
for (int j = 0; j < entry.getValue().size(); j++) {
SqlRunnerFailed failedInfo = entry.getValue().get(j);
int row = j + 1;
jxl.write.Number lineNmuber = new jxl.write.Number(0, row, failedInfo.getLineIndex(), normalCellStyle);
ws.addCell(lineNmuber);
jxl.write.Label sql = new jxl.write.Label(1, row, failedInfo.getSql(), normalCellStyle);
ws.addCell(sql);
jxl.write.Label errMessage = new jxl.write.Label(2, row, failedInfo.getErrorMessage(), normalCellStyle);
ws.addCell(errMessage);
}
}
wwb.write();
success = true;
} catch (Exception e) {
LOGGER.error("write excel error", e);
errMsg = e.getMessage();
} finally {
if (wwb != null) {
try {
wwb.close();
} catch (Exception e) {
LOGGER.error("close excel error", e);
}
}
}
}
use of jxl.write.WritableWorkbook in project cubrid-manager by CUBRID.
the class DataCompareEditorPart method exportReport.
private boolean exportReport(String basePath, String reportFileName) {
// FIXME logic code move to core module
if (compareList == null || compareList.size() == 0) {
CommonUITool.openErrorBox(Messages.msgNotExistsToExportData);
return false;
}
printToConsole("\n", false);
printToConsole(Messages.msgBeginDataCompareExcel + "\n", true);
String reportFilePath = basePath + File.separatorChar + reportFileName;
String charset = getSourceDB().getCharSet();
File file = new File(reportFilePath);
WorkbookSettings workbookSettings = new WorkbookSettings();
workbookSettings.setEncoding(charset);
WritableWorkbook workbook = null;
try {
workbook = Workbook.createWorkbook(file, workbookSettings);
String sheetName = getSourceDB().getDbName() + "-->" + getTargetDB().getDbName();
WritableSheet sheet = workbook.createSheet(sheetName, 0);
int index = 0;
int total = 0;
sheet.addCell(new jxl.write.Label(index++, total, Messages.lblDataCompareTable));
sheet.addCell(new jxl.write.Label(index++, total, Messages.lblDataCompareRecordSource));
sheet.addCell(new jxl.write.Label(index++, total, Messages.lblDataCompareRecordTarget));
sheet.addCell(new jxl.write.Label(index++, total, Messages.lblDataCompareRecordProgress));
sheet.addCell(new jxl.write.Label(index++, total, Messages.lblDataCompareRecordMatch));
sheet.addCell(new jxl.write.Label(index++, total, Messages.lblDataCompareRecordNoMatch));
sheet.addCell(new jxl.write.Label(index++, total, Messages.lblDataCompareRecordNotExist));
for (DataCompare comp : compareList) {
index = 0;
total++;
sheet.addCell(new jxl.write.Label(index++, total, comp.getTableName()));
sheet.addCell(new jxl.write.Label(index++, total, String.valueOf(comp.getRecordsSource())));
String recordsTarget = comp.getRecordsTarget() == -1 ? Messages.msgTableNotFound : String.valueOf(comp.getRecordsTarget());
sheet.addCell(new jxl.write.Label(index++, total, recordsTarget));
sheet.addCell(new jxl.write.Label(index++, total, String.valueOf(comp.getProgressPosition())));
sheet.addCell(new jxl.write.Label(index++, total, String.valueOf(comp.getMatches())));
sheet.addCell(new jxl.write.Label(index++, total, String.valueOf(comp.getNotMatches())));
sheet.addCell(new jxl.write.Label(index++, total, String.valueOf(comp.getNotExists())));
}
workbook.write();
} catch (Exception e) {
CommonUITool.openErrorBox(Messages.msgToExportExcelError);
printToConsole(e.getMessage(), true);
LOGGER.error(e.getMessage(), e);
return false;
} finally {
try {
workbook.close();
} catch (Exception e) {
noOp();
}
}
String msg = Messages.bind(Messages.msgEndDataCompareExcel, reportFilePath) + "\n";
printToConsole(msg, true);
return true;
}
use of jxl.write.WritableWorkbook in project dhis2-core by dhis2.
the class GridUtils method toXls.
/**
* Writes a XLS (Excel workbook) representation of the given list of Grids to the given OutputStream.
*/
public static void toXls(List<Grid> grids, OutputStream out) throws Exception {
WritableWorkbook workbook = openWorkbook(out);
for (int i = 0; i < grids.size(); i++) {
Grid grid = grids.get(i);
String sheetName = CodecUtils.filenameEncode(StringUtils.defaultIfEmpty(grid.getTitle(), XLS_SHEET_PREFIX + (i + 1)));
toXlsInternal(grid, workbook, sheetName, i);
}
workbook.write();
workbook.close();
}
use of jxl.write.WritableWorkbook in project dhis2-core by dhis2.
the class GridUtils method toXls.
/**
* Writes a XLS (Excel workbook) representation of the given Grid to the given OutputStream.
*/
public static void toXls(Grid grid, OutputStream out) throws Exception {
WritableWorkbook workbook = openWorkbook(out);
String sheetName = CodecUtils.filenameEncode(StringUtils.defaultIfEmpty(grid.getTitle(), XLS_SHEET_PREFIX + 1));
toXlsInternal(grid, workbook, sheetName, 0);
workbook.write();
workbook.close();
}
Aggregations