繁体   English   中英

如何同时从Excel读取和写入?

[英]How to read and write simultaneously from excel?

如何同时从Excel读取和写入? 场景:在Google搜索栏中搜索“ Facebook”,“ Yahoo”并输入标题。 对于读取数据和写入标题都应使用相同的excel。 当前使用Apache POI进行文件处理。

要读取excel单元格数据,请使用smth,如下所示:

File excel = null;
FileInputStream file = null;

try {
    excel = new File(dir + "\\" + filename + ".xls");
    file = new FileInputStream(excel);

    Workbook workbook = WorkbookFactory.create(file);
    Sheet 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();
            // Cell data logic
        }
    }
} catch (FileNotFoundException fn) {
    fail(fn.getMessage());
} catch (IOException ioe) {
    ioe.printStackTrace();
} finally {
    file.close();
}

这里的日期写法是一个很好的例子: 单击

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM