使用jxl api / Apache POI编辑现有的excel文件 [英] Edit existing excel files using jxl api / Apache POI
本文介绍了使用jxl api / Apache POI编辑现有的excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
保存它,或者可能给我一个关于如何编辑现有excel文件中的一些数据的示例程序然后保存
感谢提前!!
解决方案
教程这里是非常有帮助和写得很好的。他们使用由Apache POI项目开发的外部JAR。
这是编辑一个单元格的简单示例:
InputStream inp = new FileInputStream(wb.xls);
工作簿wb = WorkbookFactory.create(inp);
Sheet sheet = wb.getSheetAt([sheet index]);
行row = sheet.getRow([row index]);
单元格= row.getCell([cell index]);
String cellContents = cell.getStringCellValue();
//在这里修改cellContents
//将输出写入文件
cell.setCellValue(cellContents);
FileOutputStream fileOut = new FileOutputStream(wb.xls);
wb.write(fileOut);
fileOut.close();
希望有帮助
I am interested and would like to learn more about java , how to write into existing excel sheets / manipulating the existing data. I was wondering if you could give me an idea on how to edit an existing excel file and save it using the jxl api / Apache POI or perhaps give me a sample program on how to edit some data in an existing excel file and then save it Thanks in advance !!
解决方案
The tutorials here are very helpful and well-written. They use an external JAR developed by the Apache POI project. Here's an simple example of editing one cell:
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();
Hope it helps
这篇关于使用jxl api / Apache POI编辑现有的excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文