| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 |
- kibana
- boot
- Web
- Spring Boot
- elasticsearch
- node
- 리뷰
- Git
- 독후감
- effective
- 맛집
- 자바스크립트
- Spring
- javascript
- 스프링
- jface
- 이펙티브
- 알고리즘
- JPA
- java
- 자바
- 후기
- error
- java8
- MySQL
- nodejs
- 백준
- RCP
- 엘라스틱서치
- 인터페이스
- Today
- Total
wedul
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 구조 및 기초 (1) | 2016.12.24 |
| Viwer의 종류와 프로바이더 종류 및 설명 (0) | 2016.12.23 |