简体   繁体   中英

How to read and write simultaneously from excel?

How to read and write simultaneously from excel? Scenario: Search "Facebook","Yahoo" in google search bar and write the title. For Both reading data and writing the title same excel should be used. Currently using Apache POI for file-handling.

To read excel cell data use smth like this:

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();
}

How to write date here is a good example: click

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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