0

我在将 Excel 文件上传到Action我的 JIRA 插件中的 Webwork 类时遇到问题。我正在使用 apache.poi 来操作 Excel 文件,如下所示:

public class ExcelWebworkAction extends JiraWebActionSupport
{
    private static final long serialVersionUID = -7589391189615316463L;
    private static final Logger log = LoggerFactory.getLogger(ExcelWebworkAction.class);

    @Override
    public String doExecute() throws Exception {
        MultiPartRequestWrapper wrapper = (MultiPartRequestWrapper)ServletActionContext.getRequest();
        File file = wrapper.getFile("fileField");
        FileInputStream filestrem = new FileInputStream(file.getPath());

        HSSFWorkbook workbook = null;

        try {
            workbook = new HSSFWorkbook(filestrem);
        } catch (IOException e) {
            e.printStackTrace();
        }

        HSSFSheet sheet = workbook.getSheetAt(0);
        Iterator<Row> rowIterator = sheet.iterator();
        while (rowIterator.hasNext()) {
            Row row = rowIterator.next();
            Iterator<Cell> cellIterator = row.cellIterator();
            while (cellIterator.hasNext()) {
                Cell cell = cellIterator.next();
            }
        }

        filestrem.close();

        return super.doExecute(); //returns SUCCESS
    }

}

当代码到达该行时:

workbook = new HSSFWorkbook(filestrem);

我被踢出班级去一个叫ActionSupport从 JIRA 调用的课堂,但没有错误或堆栈跟踪来指导我。

我错过了什么吗?它有什么问题吗?:(

提前感谢您对此问题的任何见解。

4

1 回答 1

1

The underlying library is probably throwing some sort of unchecked exception. To debug, try changing:

catch (IOException e)

to:

catch (Throwable e)

and then set a breakpoint on the e.printStackTrace() line.

(Or wrap the whole method in the try/catch block if you're not 100% sure of exactly where it's crashing.)

于 2014-10-09T17:33:44.503 回答