如何从excel同时读写?场景:在谷歌搜索栏中搜索“Facebook”,“雅虎”并撰写标题。对于读取数据和写入标题,应使用相同的excel。目前正在使用Apache POI进行文件处理。
答案 0 :(得分:0)
要读取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();
}
如何在此处写日期是一个很好的例子:click