use of jxl.write.WritableSheet 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();
}
use of jxl.write.WritableSheet 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);
}
}
}
}
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++;
}
}
use of jxl.write.WritableSheet in project cubrid-manager by CUBRID.
the class ExportTableDefinitionLayoutType1 method generateTableDetailSheets.
/**
* generate table name sheet
* @param wwb
* @param conn
* @param exportSchemaInfoList
* @param monitor
* @throws Exception
*/
public void generateTableDetailSheets(WritableWorkbook wwb, Connection conn, List<SchemaInfo> exportSchemaInfoList, IProgressMonitor monitor) throws Exception {
int sheetIndex = 1;
for (SchemaInfo schemaInfo : exportSchemaInfoList) {
String tableName = schemaInfo.getClassname();
monitor.subTask(Messages.bind(Messages.exportTableDefinitionProgressTaskWriteTable, tableName));
List<SchemaInfo> supers = SuperClassUtil.getSuperClasses(getProgressObject().getDatabase().getDatabaseInfo(), schemaInfo);
WritableSheet ws = wwb.createSheet(tableName, sheetIndex++);
int rowIndex = 0;
// Title
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell10, boldCellStyle));
ws.mergeCells(0, 0, 7, 0);
rowIndex++;
// System name
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell11, boldCellStyle));
ws.addCell(new jxl.write.Label(1, rowIndex, "", normalCellStyle));
// Date
ws.addCell(new jxl.write.Label(2, rowIndex, Messages.exportTableDefinitionCell4, boldCellStyle));
ws.addCell(new jxl.write.Label(3, rowIndex, dateString, normalCellStyle));
// Author
ws.addCell(new jxl.write.Label(5, rowIndex, Messages.exportTableDefinitionCell5, boldCellStyle));
ws.addCell(new jxl.write.Label(7, rowIndex, "", normalCellStyle));
ws.mergeCells(3, 1, 4, 1);
ws.mergeCells(5, 1, 6, 1);
rowIndex++;
String tableColumnText = "";
if (getProgressObject().isInstalledMetaTable()) {
SchemaComment tableComment = SchemaCommentHandler.find(getProgressObject().getSchemaCommentMap(), tableName, null);
if (tableComment != null) {
tableColumnText = tableComment.getDescription() == null ? "" : tableComment.getDescription();
}
}
// Table Name
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell6, boldCellStyle));
ws.addCell(new jxl.write.Label(1, rowIndex, tableName, normalLeftAlignCellStyle));
ws.mergeCells(1, 2, 7, 2);
rowIndex++;
// Table Description
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell27, boldCellStyle));
ws.addCell(new jxl.write.Label(1, rowIndex, tableColumnText, normalLeftAlignCellStyle));
ws.mergeCells(1, 3, 7, 3);
rowIndex++;
// Column ID
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell12, boldCellStyle));
// Data type
ws.addCell(new jxl.write.Label(1, rowIndex, Messages.exportTableDefinitionCell14, boldCellStyle));
// Size
ws.addCell(new jxl.write.Label(2, rowIndex, Messages.exportTableDefinitionCell15, boldCellStyle));
// Null
ws.addCell(new jxl.write.Label(3, rowIndex, Messages.exportTableDefinitionCell16, boldCellStyle));
// PK
ws.addCell(new jxl.write.Label(4, rowIndex, Messages.exportTableDefinitionCell17, boldCellStyle));
// FK
ws.addCell(new jxl.write.Label(5, rowIndex, Messages.exportTableDefinitionCell18, boldCellStyle));
// Default
ws.addCell(new jxl.write.Label(6, rowIndex, Messages.exportTableDefinitionCell26, boldCellStyle));
// Column description
ws.addCell(new jxl.write.Label(7, rowIndex, Messages.exportTableDefinitionCell25, boldCellStyle));
rowIndex++;
// column info
for (DBAttribute columnAtt : schemaInfo.getAttributes()) {
String attrName = columnAtt.getName();
String defaultValue = columnAtt.getDefault();
String columnText = "";
if (getProgressObject().isInstalledMetaTable()) {
SchemaComment columnComment = SchemaCommentHandler.find(getProgressObject().getSchemaCommentMap(), tableName, attrName);
if (columnComment != null) {
columnText = columnComment.getDescription() == null ? "" : columnComment.getDescription();
}
}
ws.addCell(new jxl.write.Label(0, rowIndex, attrName, normalLeftAlignCellStyle));
String showType = DataType.getShownType((columnAtt.getType()));
if (showType.indexOf("(") > -1 && showType.endsWith("")) {
showType = showType.substring(0, showType.indexOf("("));
}
ws.addCell(new jxl.write.Label(1, rowIndex, showType, normalLeftAlignCellStyle));
int size = DataType.getSize(columnAtt.getType());
int scale = DataType.getScale(columnAtt.getType());
if (size < 0 && scale < 0) {
ws.addCell(new jxl.write.Label(2, rowIndex, "", normalRightAlignCellStyle));
} else if (scale < 0) {
ws.addCell(new jxl.write.Number(2, rowIndex, size, normalRightAlignCellStyle));
} else {
ws.addCell(new jxl.write.Label(2, rowIndex, Integer.toString(size) + "," + Integer.toString(scale), normalRightAlignCellStyle));
}
//get nullable
boolean isNULL = true;
if (!columnAtt.isClassAttribute()) {
if (columnAtt.getInherit().equals(tableName)) {
Constraint pk = schemaInfo.getPK(supers);
if (null != pk && pk.getAttributes().contains(attrName)) {
isNULL = false;
}
} else {
List<Constraint> pkList = schemaInfo.getInheritPK(supers);
for (Constraint inheritPK : pkList) {
if (inheritPK.getAttributes().contains(attrName)) {
isNULL = false;
}
}
}
}
if (columnAtt.isNotNull()) {
isNULL = false;
}
ws.addCell(new jxl.write.Label(3, rowIndex, isNULL ? "Y" : "", normalCellStyle));
//get pk
boolean isPk = false;
if (!columnAtt.isClassAttribute()) {
if (columnAtt.getInherit().equals(tableName)) {
Constraint pk = schemaInfo.getPK(supers);
if (null != pk && pk.getAttributes().contains(attrName)) {
isPk = true;
}
} else {
List<Constraint> pkList = schemaInfo.getInheritPK(supers);
for (Constraint inheritPK : pkList) {
if (inheritPK.getAttributes().contains(attrName)) {
isPk = true;
}
}
}
}
ws.addCell(new jxl.write.Label(4, rowIndex, isPk ? "Y" : "", normalCellStyle));
//get fk
boolean isFk = false;
for (Constraint fk : schemaInfo.getFKConstraints()) {
for (String columns : fk.getAttributes()) {
if (columns.equals(attrName)) {
isFk = true;
break;
}
}
}
ws.addCell(new jxl.write.Label(5, rowIndex, isFk ? "Y" : "", normalCellStyle));
ws.addCell(new jxl.write.Label(6, rowIndex, defaultValue, normalCellStyle));
ws.addCell(new jxl.write.Label(7, rowIndex, columnText, normalLeftAlignCellStyle));
rowIndex++;
}
// blank
for (int i = 0; i < 8; i++) {
ws.addCell(new jxl.write.Label(i, rowIndex, "", normalCellStyle));
}
rowIndex++;
// index
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell20, boldCellStyle));
ws.mergeCells(0, rowIndex, 7, rowIndex);
rowIndex++;
// NO
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell21, boldCellStyle));
// Index name
ws.addCell(new jxl.write.Label(1, rowIndex, Messages.exportTableDefinitionCell22, boldCellStyle));
// Column ID
ws.addCell(new jxl.write.Label(3, rowIndex, Messages.exportTableDefinitionCell13, boldCellStyle));
// Order
ws.addCell(new jxl.write.Label(5, rowIndex, Messages.exportTableDefinitionCell23, boldCellStyle));
// Memo
ws.addCell(new jxl.write.Label(6, rowIndex, Messages.exportTableDefinitionCell19, boldCellStyle));
ws.mergeCells(1, rowIndex, 2, rowIndex);
ws.mergeCells(3, rowIndex, 4, rowIndex);
ws.mergeCells(6, rowIndex, 7, rowIndex);
rowIndex++;
List<Constraint> constraints = getProgressObject().getIndexList(schemaInfo);
for (int i = 0; i < constraints.size(); i++) {
Constraint constraint = constraints.get(i);
int columnSize = constraint.getAttributes().size();
// mark current row index
int currentRowIndex = rowIndex;
for (int j = 0; j < columnSize; j++) {
String columnName = constraint.getAttributes().get(j);
ws.addCell(new jxl.write.Number(0, rowIndex, i + 1, normalCellStyle));
ws.addCell(new jxl.write.Label(1, rowIndex, constraint.getName(), normalLeftAlignCellStyle));
ws.addCell(new jxl.write.Label(3, rowIndex, columnName, normalLeftAlignCellStyle));
ws.addCell(new jxl.write.Number(5, rowIndex, j + 1, normalCellStyle));
ws.addCell(new jxl.write.Label(6, rowIndex, "", normalCellStyle));
if (columnSize == 1) {
ws.mergeCells(1, rowIndex, 2, rowIndex);
}
ws.mergeCells(3, rowIndex, 4, rowIndex);
ws.mergeCells(6, rowIndex, 7, rowIndex);
rowIndex++;
}
//if multiple colulmn merge NO/Index Name CELL by vertical logic
if (columnSize > 1) {
ws.mergeCells(0, currentRowIndex, 0, currentRowIndex + columnSize - 1);
ws.mergeCells(1, currentRowIndex, 2, currentRowIndex + columnSize - 1);
}
}
// blank
ws.addCell(new jxl.write.Label(0, rowIndex, "", normalCellStyle));
ws.addCell(new jxl.write.Label(1, rowIndex, "", normalCellStyle));
ws.addCell(new jxl.write.Label(3, rowIndex, "", normalCellStyle));
ws.addCell(new jxl.write.Label(5, rowIndex, "", normalCellStyle));
ws.addCell(new jxl.write.Label(6, rowIndex, "", normalCellStyle));
ws.mergeCells(1, rowIndex, 2, rowIndex);
ws.mergeCells(3, rowIndex, 4, rowIndex);
ws.mergeCells(6, rowIndex, 7, rowIndex);
rowIndex++;
// DDL
ws.addCell(new jxl.write.Label(0, rowIndex, Messages.exportTableDefinitionCell24, boldCellStyle));
ws.mergeCells(0, rowIndex, 7, rowIndex);
rowIndex++;
String ddl = getProgressObject().getDDL(schemaInfo);
ws.addCell(new jxl.write.Label(0, rowIndex, ddl, normalLeftAlignCellStyle));
ws.mergeCells(0, rowIndex, 7, rowIndex);
ws.setRowView(0, 500);
int lineNumbner = ddl.split(StringUtil.NEWLINE).length;
ws.setRowView(rowIndex, lineNumbner * 350);
// column width
ws.setColumnView(0, 18);
ws.setColumnView(1, 20);
ws.setColumnView(2, 13);
ws.setColumnView(3, 9);
ws.setColumnView(4, 9);
ws.setColumnView(5, 9);
ws.setColumnView(6, 10);
ws.setColumnView(7, 29);
monitor.worked(1);
}
}
use of jxl.write.WritableSheet in project cubrid-manager by CUBRID.
the class ExportTableDefinitionLayoutType2 method generateTableNamesSheet.
/**
* Generate table name sheet
*
* @param wwb
* @param exportTableNames
* @throws Exception
*/
public void generateTableNamesSheet(WritableWorkbook wwb, List<String> exportTableNames) throws Exception {
WritableSheet ws = wwb.createSheet(Messages.exportTableDefinitionCell1, 0);
// Tables
ws.addCell(new jxl.write.Label(0, 0, Messages.exportTableDefinitionCell2, boldCellStyle));
ws.mergeCells(0, 0, 5, 0);
// Project
ws.addCell(new jxl.write.Label(0, 1, Messages.exportTableDefinitionCell3, boldCellStyle));
ws.addCell(new jxl.write.Label(1, 1, "", normalCellStyle));
// Date
ws.addCell(new jxl.write.Label(2, 1, Messages.exportTableDefinitionCell4, boldCellStyle));
ws.addCell(new jxl.write.Label(3, 1, dateString, normalCellStyle));
// Author
ws.addCell(new jxl.write.Label(4, 1, Messages.exportTableDefinitionCell5, boldCellStyle));
ws.addCell(new jxl.write.Label(5, 1, "", normalCellStyle));
// Table Name
ws.addCell(new jxl.write.Label(0, 2, Messages.exportTableDefinitionCell6, boldCellStyle));
// Table ID
ws.addCell(new jxl.write.Label(1, 2, Messages.exportTableDefinitionCell7, boldCellStyle));
// Description
ws.addCell(new jxl.write.Label(2, 2, Messages.exportTableDefinitionCell8, boldCellStyle));
// Memo
ws.addCell(new jxl.write.Label(5, 2, Messages.exportTableDefinitionCell9, boldCellStyle));
ws.mergeCells(2, 2, 4, 2);
//table name data
int rowIndex = 3;
for (String tableName : exportTableNames) {
String tableColumnText = "";
if (getProgressObject().isInstalledMetaTable()) {
SchemaComment tableComment = SchemaCommentHandler.find(getProgressObject().getSchemaCommentMap(), tableName, null);
if (tableComment != null) {
tableColumnText = tableComment.getDescription() == null ? "" : tableComment.getDescription();
}
}
ws.addCell(new jxl.write.Label(0, rowIndex, tableColumnText, normalLeftAlignCellStyle));
ws.addCell(new jxl.write.Label(1, rowIndex, tableName, normalLeftAlignCellStyle));
ws.addCell(new jxl.write.Label(2, rowIndex, "", normalCellStyle));
ws.addCell(new jxl.write.Label(5, rowIndex, "", normalCellStyle));
ws.mergeCells(2, rowIndex, 4, rowIndex);
rowIndex++;
}
ws.setRowView(0, 500);
// column width
ws.setColumnView(0, 25);
ws.setColumnView(1, 28);
ws.setColumnView(2, 15);
ws.setColumnView(3, 18);
ws.setColumnView(4, 15);
ws.setColumnView(5, 20);
}
Aggregations