Search in sources :

Example 11 with WritableWorkbook

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);
            }
        }
    }
}
Also used : WritableWorkbook(jxl.write.WritableWorkbook) Connection(java.sql.Connection) WorkbookSettings(jxl.WorkbookSettings) File(java.io.File) SQLException(java.sql.SQLException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 12 with WritableWorkbook

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);
            }
        }
    }
}
Also used : WorkbookSettings(jxl.WorkbookSettings) WritableSheet(jxl.write.WritableSheet) WritableCellFormat(jxl.write.WritableCellFormat) InvocationTargetException(java.lang.reflect.InvocationTargetException) WriteException(jxl.write.WriteException) WritableWorkbook(jxl.write.WritableWorkbook) SqlRunnerFailed(com.cubrid.common.ui.common.sqlrunner.model.SqlRunnerFailed) List(java.util.List) File(java.io.File)

Example 13 with WritableWorkbook

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;
}
Also used : WritableWorkbook(jxl.write.WritableWorkbook) WorkbookSettings(jxl.WorkbookSettings) WritableSheet(jxl.write.WritableSheet) DataCompare(com.cubrid.common.ui.compare.data.model.DataCompare) File(java.io.File) Constraint(com.cubrid.common.core.common.model.Constraint) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SQLException(java.sql.SQLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 14 with WritableWorkbook

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();
}
Also used : WritableWorkbook(jxl.write.WritableWorkbook) Grid(org.hisp.dhis.common.Grid) JasperPrint(net.sf.jasperreports.engine.JasperPrint)

Example 15 with WritableWorkbook

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();
}
Also used : WritableWorkbook(jxl.write.WritableWorkbook)

Aggregations

WritableWorkbook (jxl.write.WritableWorkbook)15 WorkbookSettings (jxl.WorkbookSettings)10 WritableSheet (jxl.write.WritableSheet)10 WriteException (jxl.write.WriteException)7 WritableCellFormat (jxl.write.WritableCellFormat)6 File (java.io.File)5 IOException (java.io.IOException)5 SQLException (java.sql.SQLException)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 Label (jxl.write.Label)4 Timestamp (java.sql.Timestamp)3 ArrayList (java.util.ArrayList)3 Number (jxl.write.Number)3 WritableFont (jxl.write.WritableFont)3 ExportDataFailedOneTableEvent (com.cubrid.common.ui.cubrid.table.event.ExportDataFailedOneTableEvent)2 ExportDataSuccessEvent (com.cubrid.common.ui.cubrid.table.event.ExportDataSuccessEvent)2 CUBRIDResultSetMetaDataProxy (com.cubrid.jdbc.proxy.driver.CUBRIDResultSetMetaDataProxy)2 FileNotFoundException (java.io.FileNotFoundException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Connection (java.sql.Connection)2