Search in sources :

Example 16 with WritableSheet

use of jxl.write.WritableSheet 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 17 with WritableSheet

use of jxl.write.WritableSheet in project cubrid-manager by CUBRID.

the class RunSQLProcessManager method createaWritableSheet.

/**
	 * create excel sheet
	 * @param wwb
	 * @param fileName
	 * @param index
	 * @return
	 */
public WritableSheet createaWritableSheet(WritableWorkbook wwb, String fileName, int index) {
    // FIXME logic code move to core module
    WritableSheet ws = null;
    try {
        ws = wwb.createSheet(fileName, index);
        WritableCellFormat normalCellStyle = getNormalCell();
        jxl.write.Label header = new jxl.write.Label(0, 0, Messages.failedSQLlineNumber, normalCellStyle);
        ws.addCell(header);
        jxl.write.Label header1 = new jxl.write.Label(1, 0, Messages.failedSQL, normalCellStyle);
        ws.addCell(header1);
        jxl.write.Label header2 = new jxl.write.Label(2, 0, Messages.failedErrorMessage, normalCellStyle);
        ws.addCell(header2);
        ws.setColumnView(1, 100);
        ws.setColumnView(2, 80);
    } catch (Exception e) {
        ws = null;
        LOGGER.error("create WritableSheet error", e);
    }
    return ws;
}
Also used : WritableSheet(jxl.write.WritableSheet) WritableCellFormat(jxl.write.WritableCellFormat) WriteException(jxl.write.WriteException)

Example 18 with WritableSheet

use of jxl.write.WritableSheet 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 19 with WritableSheet

use of jxl.write.WritableSheet in project cubrid-manager by CUBRID.

the class Export method exportXls.

/**
	 * export all data in Query Editor result table cache as xls
	 *
	 * @param monitor IProgressMonitor
	 * @throws IOException if failed
	 * @throws FileNotFoundException if failed
	 * @throws UnsupportedEncodingException if failed
	 * @throws RowsExceededException if failed
	 * @throws NumberFormatException if failed
	 * @throws WriteException if failed
	 *
	 */
private void exportXls(final IProgressMonitor monitor) throws IOException, FileNotFoundException, UnsupportedEncodingException, RowsExceededException, NumberFormatException, WriteException {
    // FIXME move this logic to core module
    workbook = null;
    try {
        if (fileCharset == null || fileCharset.trim().length() == 0) {
            workbook = Workbook.createWorkbook(file);
        } else {
            WorkbookSettings workbookSettings = new WorkbookSettings();
            workbookSettings.setEncoding(fileCharset);
            workbook = Workbook.createWorkbook(file, workbookSettings);
        }
        int totalSheetNum = 0;
        // 65536: limit xls row number except the column row
        final int rowLimit = ImportFileConstants.XLS_ROW_LIMIT - 1;
        // 256: limit xls column number..
        final int columnLimit = ImportFileConstants.XLS_COLUMN_LIMIT;
        for (int k = 0; k < resultDataList.size(); k++) {
            List<ColumnInfo> columnList = resultColsList.get(k);
            List<Map<String, String>> dataList = resultDataList.get(k);
            WritableSheet sheet = workbook.createSheet("Sheet " + (k + 1), totalSheetNum++);
            int colCount = columnList.size();
            int itemCount = dataList.size();
            if (colCount > columnLimit) {
                if (!CommonUITool.openConfirmBox(Messages.columnCountOver)) {
                    return;
                }
                colCount = columnLimit;
            }
            //export columns
            exportColumnsForXls(sheet, k, columnLimit);
            int sheetNum = 0;
            for (int i = 0, xlsRecordNum = 1; i < itemCount; i++) {
                if (!CommonUITool.isAvailableMemory(ExportTableDataTask.REMAINING_MEMORY_SIZE)) {
                    throw new OutOfMemoryError();
                }
                int start = 0;
                for (int j = start; j < colCount; j++) {
                    String colType = columnList.get(j).getType();
                    String colIndex = columnList.get(j).getIndex();
                    String value = dataList.get(i).get(colIndex);
                    int colNumber = j - start;
                    FieldHandlerUtils.setValue2XlsCell(sheet, colNumber, xlsRecordNum, colType, value);
                }
                xlsRecordNum++;
                if (((i + 1) % rowLimit) == 0 && (i + 1) < itemCount) {
                    sheetNum++;
                    sheet = workbook.createSheet("Sheet " + (k + 1) + "_" + sheetNum, totalSheetNum++);
                    exportColumnsForXls(sheet, k, columnLimit);
                    xlsRecordNum = 1;
                }
                exportedCount++;
                monitor.subTask(Messages.bind(com.cubrid.common.ui.cubrid.table.Messages.msgExportDataRow, exportedCount));
            }
        }
    } finally {
        try {
            if (workbook != null) {
                workbook.write();
            }
        } finally {
            try {
                if (workbook != null) {
                    workbook.close();
                }
            } catch (WriteException e) {
                LOGGER.error("", e);
            } catch (IOException e) {
                LOGGER.error("", e);
            }
        }
    }
}
Also used : WriteException(jxl.write.WriteException) WorkbookSettings(jxl.WorkbookSettings) WritableSheet(jxl.write.WritableSheet) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 20 with WritableSheet

use of jxl.write.WritableSheet in project cubrid-manager by CUBRID.

the class ExportHostStatusDialog method saveDBInfoData.

private void saveDBInfoData(Table dbInfoTable, String sheetName, int sheetIndex) throws RowsExceededException, WriteException {
    WritableCellFormat normalCellStyle = getNormalCell();
    WritableSheet ws = wwb.createSheet(sheetName, sheetIndex);
    int rowIndex = 0;
    //title
    for (int j = 0; j < dbInfoTable.getColumnCount(); j++) {
        String cellString = dbInfoTable.getColumn(j).getText();
        ws.addCell(new jxl.write.Label(j, rowIndex, cellString, normalCellStyle));
        ws.setColumnView(j, 30);
    }
    rowIndex++;
    //row
    for (int j = 0; j < dbInfoTable.getItemCount(); j++) {
        TableItem tableItem = dbInfoTable.getItem(j);
        for (int k = 0; k < dbInfoTable.getColumnCount(); k++) {
            String cellString = tableItem.getText(k);
            if (k == 1) {
                if ((Boolean) tableItem.getData("isChecked")) {
                    cellString = "Y";
                } else {
                    cellString = "N";
                }
            }
            ws.addCell(new jxl.write.Label(k, rowIndex, cellString, normalCellStyle));
        }
        rowIndex++;
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) WritableSheet(jxl.write.WritableSheet) WritableCellFormat(jxl.write.WritableCellFormat)

Aggregations

WritableSheet (jxl.write.WritableSheet)21 WritableCellFormat (jxl.write.WritableCellFormat)10 WritableWorkbook (jxl.write.WritableWorkbook)10 WriteException (jxl.write.WriteException)9 WorkbookSettings (jxl.WorkbookSettings)8 IOException (java.io.IOException)6 Constraint (com.cubrid.common.core.common.model.Constraint)5 Label (jxl.write.Label)5 SchemaComment (com.cubrid.common.core.schemacomment.model.SchemaComment)4 SQLException (java.sql.SQLException)4 Number (jxl.write.Number)4 File (java.io.File)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Timestamp (java.sql.Timestamp)3 ArrayList (java.util.ArrayList)3 WritableFont (jxl.write.WritableFont)3 TableItem (org.eclipse.swt.widgets.TableItem)3 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)2 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)2 ExportDataFailedOneTableEvent (com.cubrid.common.ui.cubrid.table.event.ExportDataFailedOneTableEvent)2