use of jxl.WorkbookSettings in project cubrid-manager by CUBRID.
the class PstmtDataTask method getRowParameterListFromExcel.
/**
*
* Get the parameter of PSTMT list from excel file
*
* @return List<List<PstmtParameter>>
*/
private List<List<PstmtParameter>> getRowParameterListFromExcel() {
// FIXME move this logic to core module
File file = new File(fileName);
Workbook workbook = null;
List<List<PstmtParameter>> rowParaList = new ArrayList<List<PstmtParameter>>();
try {
if (fileCharset == null) {
workbook = Workbook.getWorkbook(file);
} else {
WorkbookSettings workbookSettings = new WorkbookSettings();
workbookSettings.setEncoding(fileCharset);
workbook = Workbook.getWorkbook(file, workbookSettings);
}
Sheet[] sheets = workbook.getSheets();
for (int sheetNum = 0; sheetNum < sheets.length; sheetNum++) {
Sheet sheet = sheets[sheetNum];
int rows = sheet.getRows();
int start = 0;
if (isFirstRowAsColumn) {
start = 1;
}
for (int i = start; i < rows; i++) {
List<PstmtParameter> paraList = new ArrayList<PstmtParameter>();
for (int j = 0; j < parameterList.size(); j++) {
PstmtParameter pstmtParameter = parameterList.get(j);
PstmtParameter newParam = new PstmtParameter(pstmtParameter.getParamName(), pstmtParameter.getParamIndex(), pstmtParameter.getDataType(), null);
int column = Integer.parseInt(pstmtParameter.getStringParamValue());
Cell cell = sheet.getCell(column, i);
String content = null;
String pattern = null;
if (cell == null) {
content = null;
} else if (cell instanceof EmptyCell) {
content = null;
} else {
content = cell.getContents();
CellFormat format = cell.getCellFormat();
if (format != null && format.getFormat() != null) {
pattern = format.getFormat().getFormatString();
}
}
String dataType = DataType.getRealType(pstmtParameter.getDataType());
content = FieldHandlerUtils.getRealValueForImport(dataType, content, parentFile);
FormatDataResult formatDataResult = null;
if (StringUtil.isEmpty(pattern)) {
formatDataResult = DBAttrTypeFormatter.format(dataType, content, false, dbCharset, true);
} else {
formatDataResult = DBAttrTypeFormatter.format(dataType, content, pattern, false, dbCharset, true);
}
if (formatDataResult.isSuccess()) {
newParam.setCharSet(fileCharset);
newParam.setParamValue(content);
} else {
dataTypeErrorHandling(getErrorMsg(i, column, dataType));
newParam.setCharSet(fileCharset);
newParam.setParamValue(null);
}
paraList.add(newParam);
}
rowParaList.add(paraList);
}
}
} catch (BiffException ex) {
throw new RuntimeException(ex);
} catch (IOException ex) {
throw new RuntimeException(ex);
} catch (DataFormatException ex) {
throw new RuntimeException(ex);
} catch (OutOfMemoryError error) {
throw new RuntimeException(error);
} finally {
if (workbook != null) {
workbook.close();
}
}
return rowParaList;
}
use of jxl.WorkbookSettings in project cubrid-manager by CUBRID.
the class XLSImportFileHandler method getSourceFileInfo.
/**
* Get the source file information
*
* @return ImportFileDescription
* @throws Exception in process.
*/
public ImportFileDescription getSourceFileInfo() throws Exception {
// FIXME move this logic to core module
synchronized (this) {
if (importFileDescription == null) {
final List<String> colsLst = new ArrayList<String>();
final List<Integer> itemsNumberOfSheets = new ArrayList<Integer>();
importFileDescription = new ImportFileDescription(0, 0, colsLst);
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(final IProgressMonitor monitor) {
monitor.beginTask("", IProgressMonitor.UNKNOWN);
Workbook workbook = null;
int totalRowCount = 0;
int sheetNum = 0;
try {
if (fileCharset == null) {
workbook = Workbook.getWorkbook(new File(fileName));
} else {
WorkbookSettings workbookSettings = new WorkbookSettings();
workbookSettings.setEncoding(fileCharset);
workbook = Workbook.getWorkbook(new File(fileName), workbookSettings);
}
// get column count and total row count
sheetNum = workbook.getNumberOfSheets();
if (sheetNum > 0) {
int columnCount = workbook.getSheet(0).getColumns();
for (int j = 0; !monitor.isCanceled() && j < columnCount; j++) {
Cell cell = workbook.getSheet(0).getCell(j, 0);
//$NON-NLS-1$
colsLst.add(cell == null ? "" : cell.getContents());
}
}
for (int i = 0; !monitor.isCanceled() && i < sheetNum; i++) {
int rowsInSheet = workbook.getSheet(i).getRows();
itemsNumberOfSheets.add(Integer.valueOf(rowsInSheet));
totalRowCount += rowsInSheet;
}
if (monitor.isCanceled()) {
throw new InterruptedException();
}
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
throw new RuntimeException(e);
} finally {
importFileDescription.setSheetNum(sheetNum);
importFileDescription.setTotalCount(totalRowCount);
importFileDescription.setFirstRowCols(colsLst);
importFileDescription.setItemsNumberOfSheets(itemsNumberOfSheets);
if (workbook != null) {
workbook.close();
}
monitor.done();
}
}
};
PlatformUI.getWorkbench().getProgressService().busyCursorWhile(runnable);
}
return importFileDescription;
}
}
use of jxl.WorkbookSettings in project cubrid-manager by CUBRID.
the class RunSQLProcessManager method createExcel.
/**
* create excel workbook
* @param excelFile
* @return
*/
public WritableWorkbook createExcel(File excelFile) {
WritableWorkbook wwb = null;
try {
WorkbookSettings workbookSettings = new WorkbookSettings();
workbookSettings.setEncoding(charset);
wwb = Workbook.createWorkbook(excelFile, workbookSettings);
} catch (Exception e) {
LOGGER.error("create excel error", e);
}
return wwb;
}
use of jxl.WorkbookSettings in project cubrid-manager by CUBRID.
the class ExportHostStatusDialog method saveAllData.
private boolean saveAllData() {
String fileName = saveExcelPath.getText() + saveExcelName.getText() + ".xls";
WorkbookSettings workbookSettings = new WorkbookSettings();
workbookSettings.setEncoding(fileCharsetCombo.getText());
boolean isOK = true;
try {
wwb = Workbook.createWorkbook(new File(fileName), workbookSettings);
/*System info*/
saveTableData(com.cubrid.cubridmanager.ui.host.Messages.titleServerInfo, editor.getDbServerInfoText().getText(), com.cubrid.cubridmanager.ui.host.Messages.titleServerInfo, 0);
/*DB info*/
saveDBInfoData(editor.getDatabaseTable(), com.cubrid.cubridmanager.ui.host.Messages.titleDBInfo, 1);
/*DB volume info*/
saveTableData(editor.getVolumeTableViewer().getTable(), com.cubrid.cubridmanager.ui.host.Messages.titleVolumeInfo, 2);
/*Broker info*/
saveTableData(editor.getBrokerTableViewer().getTable(), com.cubrid.cubridmanager.ui.host.Messages.titleBrokerInfo, 3);
/*System status*/
saveTableData(editor.getServerTableViewer().getTable(), com.cubrid.cubridmanager.ui.host.Messages.titleSystemInfo, 4);
wwb.write();
} catch (IOException e) {
isOK = false;
LOGGER.error("Export to error", e);
} catch (RowsExceededException e) {
isOK = false;
LOGGER.error("Export to error", e);
} catch (WriteException e) {
isOK = false;
LOGGER.error("Export to error", e);
} finally {
if (wwb != null) {
try {
wwb.close();
} catch (Exception ex) {
LOGGER.error("close excel stream error", ex);
}
}
}
return isOK;
}
use of jxl.WorkbookSettings 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);
}
}
}
}
Aggregations