Search in sources :

Example 11 with WorkbookSettings

use of jxl.WorkbookSettings in project cubrid-manager by CUBRID.

the class ExportConnectionUtil method writeToXls.

/**
	 * Write to xls
	 *
	 * @throws IOException
	 * @throws RowsExceededException
	 * @throws WriteException
	 */
private void writeToXls() throws IOException, RowsExceededException, WriteException {
    // FIXME split logic and ui
    WritableWorkbook workbook = null;
    WorkbookSettings workbookSettings = new WorkbookSettings();
    workbookSettings.setEncoding("UTF-8");
    workbook = Workbook.createWorkbook(file, workbookSettings);
    WritableSheet sheet = workbook.createSheet(Messages.sheetNameConnections, 0);
    WritableFont wf = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD, false);
    WritableCellFormat wcf = new WritableCellFormat(wf);
    jxl.write.Label label = null;
    label = new jxl.write.Label(0, 0, Messages.nameColumn, wcf);
    sheet.addCell(label);
    label = new jxl.write.Label(1, 0, Messages.iPColumn, wcf);
    sheet.addCell(label);
    label = new jxl.write.Label(2, 0, Messages.portColumn, wcf);
    sheet.addCell(label);
    label = new jxl.write.Label(3, 0, Messages.userColumn, wcf);
    sheet.addCell(label);
    label = new jxl.write.Label(4, 0, Messages.commentColumn, wcf);
    sheet.addCell(label);
    label = new jxl.write.Label(5, 0, Messages.javaUrlColumn, wcf);
    sheet.addCell(label);
    label = new jxl.write.Label(6, 0, Messages.phpUrlColumn, wcf);
    sheet.addCell(label);
    int index = 1;
    for (CubridDatabase database : input) {
        if (database == null) {
            continue;
        }
        DatabaseInfo dbInfo = database.getDatabaseInfo();
        if (dbInfo == null) {
            continue;
        }
        /* name */
        sheet.addCell(new jxl.write.Label(0, index, dbInfo.getDbName()));
        /* ip */
        sheet.addCell(new jxl.write.Label(1, index, dbInfo.getBrokerIP()));
        /* port */
        sheet.addCell(new jxl.write.Label(2, index, dbInfo.getBrokerPort()));
        /* user */
        sheet.addCell(new jxl.write.Label(3, index, getDbUser(dbInfo)));
        /* comment */
        String comment = "";
        DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(database, managerMode);
        if (editorConfig != null && editorConfig.getDatabaseComment() != null) {
            comment = editorConfig.getDatabaseComment();
        }
        sheet.addCell(new jxl.write.Label(4, index, comment));
        /* java url */
        String javaUrl = NodeUtil.getJavaConnectionUrl(dbInfo);
        sheet.addCell(new jxl.write.Label(5, index, javaUrl));
        /* php url */
        String phpUrl = NodeUtil.getPHPConnectionUrl(dbInfo);
        sheet.addCell(new jxl.write.Label(6, index, phpUrl));
        index++;
    }
    workbook.write();
    workbook.close();
}
Also used : WritableWorkbook(jxl.write.WritableWorkbook) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) WritableFont(jxl.write.WritableFont) WorkbookSettings(jxl.WorkbookSettings) WritableSheet(jxl.write.WritableSheet) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) WritableCellFormat(jxl.write.WritableCellFormat) DatabaseEditorConfig(com.cubrid.common.ui.spi.model.DatabaseEditorConfig)

Example 12 with WorkbookSettings

use of jxl.WorkbookSettings in project cubrid-manager by CUBRID.

the class BrokerLogTopMergeProgress method writeExcelPartitionByfile.

/**
	 * writeExcelPartitionByfile
	 *
	 * @param mergeString
	 * @param xlsFile
	 * @throws Exception
	 */
public void writeExcelPartitionByfile(ArrayList<ArrayList<String>> mergeString, File xlsFile) throws Exception {
    // FIXME move this logic to core module
    WritableWorkbook wwb = null;
    WritableSheet ws = null;
    String sheetName = "log_top_merge";
    try {
        WritableCellFormat normalCellStyle = getNormalCell();
        WritableCellFormat sqlCellStyle = getSQLCell();
        WorkbookSettings workbookSettings = new WorkbookSettings();
        workbookSettings.setEncoding(charset);
        wwb = Workbook.createWorkbook(xlsFile, workbookSettings);
        ws = wwb.createSheet(sheetName, 0);
        ws.setColumnView(7, 200);
        ws.addCell(new jxl.write.Label(0, 0, "NUM", normalCellStyle));
        ws.addCell(new jxl.write.Label(1, 0, "ID", normalCellStyle));
        ws.addCell(new jxl.write.Label(2, 0, "MAX (sec)", normalCellStyle));
        ws.addCell(new jxl.write.Label(3, 0, "MIN (sec)", normalCellStyle));
        ws.addCell(new jxl.write.Label(4, 0, "AVG (sec)", normalCellStyle));
        ws.addCell(new jxl.write.Label(5, 0, "Counts", normalCellStyle));
        ws.addCell(new jxl.write.Label(6, 0, "Errors", normalCellStyle));
        ws.addCell(new jxl.write.Label(7, 0, "SQL contents", normalCellStyle));
        jxl.write.Label label = null;
        jxl.write.Number num = null;
        for (int i = 0; i < mergeString.size(); i++) {
            List<String> oneLine = mergeString.get(i);
            int row = i + 1;
            for (int j = 0; j < 8; j++) {
                if (j == 0) {
                    String numString = oneLine.get(0) == null ? "" : oneLine.get(0);
                    num = new jxl.write.Number(j, row, Integer.valueOf(numString.replaceAll("Q", "")), normalCellStyle);
                    ws.addCell(num);
                } else if (j == 1) {
                    String comment = "";
                    String sql = oneLine.get(6) == null ? "" : oneLine.get(6).trim();
                    if (sql.startsWith("/*")) {
                        int endIndexOfComment = sql.indexOf("*/");
                        if (endIndexOfComment != -1) {
                            comment = sql.substring(2, endIndexOfComment).trim();
                        }
                    }
                    label = new jxl.write.Label(j, row, comment, sqlCellStyle);
                    ws.addCell(label);
                } else if (j > 1 && j < 7) {
                    num = new jxl.write.Number(j, row, Float.valueOf(oneLine.get(j - 1)), normalCellStyle);
                    ws.addCell(num);
                } else {
                    String s = oneLine.get(6);
                    if (s.length() > excelCelllength) {
                        s = s.substring(0, excelCelllength - 3);
                        s += "...";
                    }
                    label = new jxl.write.Label(j, row, s, sqlCellStyle);
                    ws.addCell(label);
                }
            }
        }
        wwb.write();
    } catch (Exception e) {
        LOGGER.error("write excel error", e);
        throw e;
    } finally {
        if (wwb != null) {
            try {
                wwb.close();
            } catch (Exception ex) {
                LOGGER.error("close excel stream error", ex);
            }
        }
    }
}
Also used : WritableSheet(jxl.write.WritableSheet) WorkbookSettings(jxl.WorkbookSettings) WritableCellFormat(jxl.write.WritableCellFormat) WriteException(jxl.write.WriteException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) WritableWorkbook(jxl.write.WritableWorkbook)

Example 13 with WorkbookSettings

use of jxl.WorkbookSettings 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 14 with WorkbookSettings

use of jxl.WorkbookSettings 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 15 with WorkbookSettings

use of jxl.WorkbookSettings 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)

Aggregations

WorkbookSettings (jxl.WorkbookSettings)16 WritableWorkbook (jxl.write.WritableWorkbook)10 File (java.io.File)9 WritableSheet (jxl.write.WritableSheet)8 IOException (java.io.IOException)7 WritableCellFormat (jxl.write.WritableCellFormat)6 WriteException (jxl.write.WriteException)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 SQLException (java.sql.SQLException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 WritableFont (jxl.write.WritableFont)3 FileNotFoundException (java.io.FileNotFoundException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Cell (jxl.Cell)2 Workbook (jxl.Workbook)2 BiffException (jxl.read.biff.BiffException)2 Label (jxl.write.Label)2 Constraint (com.cubrid.common.core.common.model.Constraint)1 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)1