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;
}
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);
}
}
}
}
use of jxl.WorkbookSettings in project cubrid-manager by CUBRID.
the class XLSImportFileHandler method getWorkbook.
/**
*
* Get the excel workbook
*
* @return the Workbook
* @throws BiffException The exception
* @throws IOException The exception
*/
public Workbook getWorkbook() throws BiffException, IOException {
// FIXME move this logic to core module
synchronized (this) {
if (workbook == null) {
File file = new File(fileName);
if (fileCharset == null || fileCharset.trim().length() == 0) {
workbook = Workbook.getWorkbook(file);
} else {
WorkbookSettings workbookSettings = new WorkbookSettings();
workbookSettings.setEncoding(fileCharset);
workbook = Workbook.getWorkbook(file, workbookSettings);
}
}
return workbook;
}
}
use of jxl.WorkbookSettings in project trainning by fernandotomasio.
the class ImportNiveisAprendizagemCSV method execute.
@Override
public void execute() {
BufferedReader br = null;
String line;
String cvsSplitBy = "\\|";
Map<String, DominioAprendizagemDTO> dominiosMap = new HashMap<String, DominioAprendizagemDTO>();
Map<String, List<String>> verbosMap = new HashMap<String, List<String>>();
try {
br = new BufferedReader(new FileReader(new ClassPathResource("verbos.csv").getFile()));
while ((line = br.readLine()) != null) {
// use comma as separator
String[] data = line.split(cvsSplitBy);
String verbo = data[0];
String nivel = data[1];
List<String> verbos = verbosMap.get(nivel);
if (verbos != null) {
verbos.add(verbo);
} else {
verbos = new ArrayList<String>();
verbos.add(verbo);
verbosMap.put(nivel, verbos);
}
}
WorkbookSettings ws = new WorkbookSettings();
ws.setEncoding("Cp1252");
Workbook workbook = Workbook.getWorkbook(new ClassPathResource("niveis.xls").getInputStream(), ws);
Sheet sheet = workbook.getSheet(0);
for (int i = 0; i < sheet.getRows(); i++) {
String nome = sheet.getCell(0, i).getContents();
String codigo = sheet.getCell(1, i).getContents();
String descricao = sheet.getCell(2, i).getContents();
String dominio = sheet.getCell(3, i).getContents();
NivelAprendizagemDTO nivel = new NivelAprendizagemDTO();
nivel.setNome(nome);
nivel.setCodigo(codigo);
nivel.setDescricao(descricao);
List<String> verbos = verbosMap.get(nome);
String[] verbosArray = new String[verbos.size()];
for (int j = 0; j < verbos.size(); j++) {
verbosArray[j] = verbos.get(j);
}
nivel.setVerbos(verbosArray);
DominioAprendizagemDTO dominioAprendizagem = dominiosMap.get(dominio);
if (dominioAprendizagem == null) {
DominioAprendizagemDTO d = new DominioAprendizagemDTO();
d.setDescricao(dominio);
Long dominioId = service.createDominioAprendizagem(d);
d = service.findDominioAprendizagem(dominioId);
dominiosMap.put(dominio, d);
nivel.setDominioAprendizagem(d);
} else {
nivel.setDominioAprendizagem(dominioAprendizagem);
}
service.createNivelAprendizagem(nivel);
System.out.println(nome);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (BiffException ex) {
Logger.getLogger(ImportNiveisAprendizagemCSV.class.getName()).log(Level.SEVERE, null, ex);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
System.out.println("Done");
}
use of jxl.WorkbookSettings in project pentaho-kettle by pentaho.
the class ExcelOutput method init.
@Override
public boolean init(StepMetaInterface smi, StepDataInterface sdi) {
meta = (ExcelOutputMeta) smi;
data = (ExcelOutputData) sdi;
if (super.init(smi, sdi)) {
data.splitnr = 0;
data.realSheetname = environmentSubstitute(meta.getSheetname());
data.ws = new WorkbookSettings();
if (meta.isUseTempFiles()) {
data.ws.setUseTemporaryFileDuringWrite(true);
String realdir = environmentSubstitute(meta.getTempDirectory());
if (!Utils.isEmpty(realdir)) {
File file = new File(realdir);
if (!file.exists()) {
logError(BaseMessages.getString(PKG, "ExcelInputLog.TempDirectoryNotExist", realdir));
return false;
}
data.ws.setTemporaryFileDuringWriteDirectory(file);
}
}
data.ws.setLocale(Locale.getDefault());
data.Headerrowheight = Const.toInt(environmentSubstitute(meta.getHeaderRowHeight()), -1);
data.realHeaderImage = environmentSubstitute(meta.getHeaderImage());
if (!Utils.isEmpty(meta.getEncoding())) {
data.ws.setEncoding(meta.getEncoding());
}
if (!meta.isDoNotOpenNewFileInit()) {
data.oneFileOpened = true;
if (openNewFile()) {
return true;
} else {
logError("Couldn't open file " + meta.getFileName());
setErrors(1L);
stopAll();
}
} else {
return true;
}
}
return false;
}
Aggregations