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