RCP ProgressDialog를 이용한 TableViewer 데이터 엑셀로 내보내기
RCP/RCP

RCP ProgressDialog를 이용한 TableViewer 데이터 엑셀로 내보내기

반응형

public void processExcelExport(ExcelExportActionNotification object) {


Display.getDefault().syncExec(new Runnable() {

public void run() {

try {

FileDialog fd = new FileDialog(object.getTable().getControl().getShell(), SWT.SAVE);

fd.setText("Save");

fd.setFilterPath("C:/");

String[] filterExt = {"*.xls", "*.*" };

fd.setFilterExtensions(filterExt);

String path = fd.open();


if (path == null || path == "" || fd.getFileName() == null || fd.getFileName() == "") {

exceptionHandler.handleException(Message.ExportcancelMsg);

return;

}

FileContainer.getInstance().setFilePath(path);

new ProgressMonitorDialog(object.getTable().getControl().getShell()).run(false, false,

new LongRunningOperation(object, path));

} catch (Exception e) {

LOGGER.error("Export Error", e);

exceptionHandler.handleException(Message.errExportContent);

}

}

});

}


public class LongRunningOperation implements

IRunnableWithProgress {

ExcelExportActionNotification notification;

String path;


public LongRunningOperation(ExcelExportActionNotification object, String path) {

this.notification = object;

this.path = path;

}


@Override

public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {

try (FileOutputStream out = new FileOutputStream(FileContainer.getInstance().getCurrentFile())) {

//Create Data, 작업량 설정

monitor.beginTask("Export Data",

notification.getTable().getTable().getItemCount() * notification.getColumn_header().length);



//Create workbook and sheet

workbook = new HSSFWorkbook();

HSSFSheet sheet = workbook.createSheet();

sheet.setGridsPrinted(true);

sheet.setFitToPage(true);

sheet.setDisplayGuts(true);


//Header 설정

row = sheet.createRow(0);

for (int colIndex = 0; colIndex < notification.getColumn_header().length; colIndex++) {

cell = row.createCell(colIndex);

cell.setCellValue(notification.getColumn_header()[colIndex]);

}


//Data Input

for (int rowIndex = 0; rowIndex < notification.getTable().getTable().getItemCount(); rowIndex++) {

row = sheet.createRow(rowIndex + 1);

for (int colIndex = 0; colIndex < notification.getColumn_header().length; colIndex++) {

cell = row.createCell(colIndex);

cell.setCellValue(notification.getTable().getTable().getItem(rowIndex).getText(colIndex));

monitor.worked(1);

}

}


monitor.done();

workbook.write(out);


//내보내기가 완료된 엑셀파일 실행

if (MessageDialog.openConfirm(null, Message.successTitle, Message.msgExportSuccess)) {

Program program = Program.findProgram("xls");

program.execute(path);

}

} catch (IOException e) {

LOGGER.error("Export Error", e);

exceptionHandler.handleException(Message.errExportContent);

} finally {

workbook = null;

row = null;

cell = null;

}

}

}


결과 화면

 

반응형

'RCP > RCP' 카테고리의 다른 글

RCP ActivePage Hide and Show  (0) 2016.12.24
RCP workbench 글로벌 후크  (0) 2016.12.24
RCP ActivePage에 특정 View 열기  (0) 2016.12.24
rcp 구조 및 기초  (0) 2016.12.24
Viwer의 종류와 프로바이더 종류 및 설명  (0) 2016.12.23