public void actionPerformed(ActionEvent e) {
btn_convert.setEnabled(false);
new ConvtSwingWorker().execute();
}
private class ConvtSwingWorker extends SwingWorker<Void, Void> {
@Override
protected Void doInBackground() throws Exception {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
log.append("begin to convert ..." + TLSwing.newline);
if (txt_source.getText().equals("")) {
log.append("please input source file...");
} else {
log.append("begin to convert ..." + txt_source.getText() + TLSwing.newline);
file_source = new File(txt_source.getText());
try {
in = new FileInputStream(file_source);
if (file_source.getName().endsWith("xlsx")) {
workbook = new XSSFWorkbook(in);
XSSFSheet sheet = workbook.getSheetAt(0);
Sheet sheet2 = workbook.getSheetAt(0);
for (Row row : sheet2) {
if (row.getRowNum() != 0) {
for (Cell cell : row) {
// log.append(getCellValue(sheet.getRow(2).getCell(2)));
log.append(getCellValue((XSSFCell) cell) + TLSwing.newline);
try {
Thread.currentThread().sleep(100);
} catch (InterruptedException e4) {
// TODO Auto-generated catch
// block
e4.printStackTrace(pw);
log.append("InterruptedException" + TLSwing.newline + sw.toString()
+ TLSwing.newline);
}
}
}
}
} else {
}
} catch (IOException e1) {
e1.printStackTrace(pw);
log.append("IOException" + TLSwing.newline + sw.toString() + TLSwing.newline);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e2) {
e2.printStackTrace(pw);
log.append("IOException" + TLSwing.newline + sw.toString() + TLSwing.newline);
}
}
}
}
return null;
}
@Override
protected void done() {
btn_convert.setEnabled(true);
}
}