我很感兴趣并且想了解更多关于 java 的知识,如何写入现有的 Excel 工作表/操作现有的数据。我想知道您是否能给我一个关于如何编辑现有 Excel 文件并使用 jxl api / Apache POI 保存它的想法
或者给我一个示例程序,说明如何编辑现有 Excel 文件中的某些数据,然后保存它
提前致谢 !!
教程here http://poi.apache.org/spreadsheet/quick-guide.html非常有帮助并且写得很好。他们使用 Apache POI 项目开发的外部 JAR。
以下是编辑一个单元格的简单示例:
InputStream inp = new FileInputStream("wb.xls");
Workbook wb = WorkbookFactory.create(inp);
Sheet sheet = wb.getSheetAt([sheet index]);
Row row = sheet.getRow([row index]);
Cell cell = row.getCell([cell index]);
String cellContents = cell.getStringCellValue();
//Modify the cellContents here
// Write the output to a file
cell.setCellValue(cellContents);
FileOutputStream fileOut = new FileOutputStream("wb.xls");
wb.write(fileOut);
fileOut.close();
希望能帮助到你
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)