Search in sources :

Example 6 with WritableCellFormat

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

the class ExportDashboardDialog method exportTableList.

/**
	 * export dashboard table list
	 * @return boolean sucess
	 */
public boolean exportTableList() throws Exception {
    WritableWorkbook wwb = null;
    WritableSheet ws = null;
    String fileName = saveExcelPath.getText() + saveExcelName.getText() + ".xls";
    try {
        WritableCellFormat normalCellStyle = getNormalCell();
        WorkbookSettings workbookSettings = new WorkbookSettings();
        workbookSettings.setEncoding(fileCharsetCombo.getText());
        wwb = Workbook.createWorkbook(new File(fileName), workbookSettings);
        for (int i = 0; i < exportTableList.size(); i++) {
            ws = wwb.createSheet(sheetNames[i], i);
            Table table = exportTableList.get(i);
            int rowIndex = 0;
            //title
            for (int j = 0; j < table.getColumnCount(); j++) {
                String cellString = table.getColumn(j).getText();
                ws.addCell(new jxl.write.Label(j, rowIndex, cellString, normalCellStyle));
                ws.setColumnView(j, 30);
            }
            rowIndex++;
            //row
            for (int j = 0; j < table.getItemCount(); j++) {
                TableItem tableItem = table.getItem(j);
                for (int k = 0; k < table.getColumnCount(); k++) {
                    String cellString = tableItem.getText(k);
                    ws.addCell(new jxl.write.Label(k, rowIndex, cellString, normalCellStyle));
                }
                rowIndex++;
            }
        }
        wwb.write();
        return true;
    } catch (Exception e) {
        LOGGER.error(e.getMessage());
        throw e;
    } finally {
        if (wwb != null) {
            try {
                wwb.close();
            } catch (Exception ex) {
                LOGGER.error("close excel stream error", ex);
            }
        }
    }
}
Also used : WritableWorkbook(jxl.write.WritableWorkbook) Table(org.eclipse.swt.widgets.Table) TableItem(org.eclipse.swt.widgets.TableItem) WritableSheet(jxl.write.WritableSheet) WorkbookSettings(jxl.WorkbookSettings) WritableCellFormat(jxl.write.WritableCellFormat) File(java.io.File) WriteException(jxl.write.WriteException)

Example 7 with WritableCellFormat

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

the class ImportResultDialog method getNormolCell.

public static WritableCellFormat getNormolCell() {
    // FIXME move this logic to core module
    WritableFont font = new WritableFont(WritableFont.TIMES, 12);
    WritableCellFormat format = new WritableCellFormat(font);
    try {
        format.setAlignment(jxl.format.Alignment.LEFT);
        format.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
        format.setBorder(Border.ALL, BorderLineStyle.THIN, Colour.BLACK);
        format.setWrap(true);
    } catch (WriteException e) {
        e.printStackTrace();
    }
    return format;
}
Also used : WriteException(jxl.write.WriteException) WritableFont(jxl.write.WritableFont) WritableCellFormat(jxl.write.WritableCellFormat)

Example 8 with WritableCellFormat

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

the class ExportToXlsHandler method writeHeader.

/**
	 * Write the sheet header
	 *
	 * @param sheet
	 * @param columnNameList
	 * @throws RowsExceededException
	 * @throws WriteException
	 */
private void writeHeader(WritableSheet sheet, List<String> columnNameList) throws RowsExceededException, WriteException {
    // FIXME move this logic to core module
    WritableFont wf = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD, false);
    WritableCellFormat wcf = new WritableCellFormat(wf);
    for (int columnIndex = 0; columnIndex < columnNameList.size(); columnIndex++) {
        String columnName = columnNameList.get(columnIndex);
        Label label = new Label(columnIndex, 0, columnName, wcf);
        sheet.addCell(label);
        label = null;
    }
    wcf = null;
    wf = null;
}
Also used : WritableFont(jxl.write.WritableFont) Label(jxl.write.Label) WritableCellFormat(jxl.write.WritableCellFormat)

Example 9 with WritableCellFormat

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

the class ExportHostStatusDialog method saveTableData.

private void saveTableData(String columnName, String content, String sheetName, int sheetIndex) throws RowsExceededException, WriteException {
    WritableCellFormat normalCellStyle = getNormalCell();
    WritableSheet ws = wwb.createSheet(sheetName, sheetIndex);
    ws.addCell(new jxl.write.Label(0, 0, columnName, normalCellStyle));
    ws.setColumnView(0, 30);
    ws.addCell(new jxl.write.Label(0, 1, content, normalCellStyle));
}
Also used : WritableSheet(jxl.write.WritableSheet) WritableCellFormat(jxl.write.WritableCellFormat)

Example 10 with WritableCellFormat

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

the class ExportHostStatusDialog method saveTableData.

private void saveTableData(Table table, 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 < table.getColumnCount(); j++) {
        String cellString = table.getColumn(j).getText();
        ws.addCell(new jxl.write.Label(j, rowIndex, cellString, normalCellStyle));
        ws.setColumnView(j, 30);
    }
    rowIndex++;
    //row
    for (int j = 0; j < table.getItemCount(); j++) {
        TableItem tableItem = table.getItem(j);
        for (int k = 0; k < table.getColumnCount(); k++) {
            String cellString = tableItem.getText(k);
            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

WritableCellFormat (jxl.write.WritableCellFormat)24 WritableFont (jxl.write.WritableFont)17 WriteException (jxl.write.WriteException)17 WritableSheet (jxl.write.WritableSheet)10 WorkbookSettings (jxl.WorkbookSettings)6 WritableWorkbook (jxl.write.WritableWorkbook)6 Label (jxl.write.Label)3 TableItem (org.eclipse.swt.widgets.TableItem)3 File (java.io.File)2 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 List (java.util.List)2 SqlRunnerFailed (com.cubrid.common.ui.common.sqlrunner.model.SqlRunnerFailed)1 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)1 DatabaseEditorConfig (com.cubrid.common.ui.spi.model.DatabaseEditorConfig)1 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)1 CUBRIDResultSetMetaDataProxy (com.cubrid.jdbc.proxy.driver.CUBRIDResultSetMetaDataProxy)1 FileNotFoundException (java.io.FileNotFoundException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 SQLException (java.sql.SQLException)1