用java apache在excel中添加单元格

我正在阅读一个已经存在的Excel文件,并尝试添加某些单元格(C4-C15)。 我有难以通过Java操纵文件。 我正在使用Apache poi,并希望任何帮助或方向。

为了访问Apache POI中的单元格,您必须先获取一行,然后获取所选行中的单元格。 下面是例子:

//Input file InputStream inp = new FileInputStream("workbook.xls"); //Create workbook instance Workbook wb = WorkbookFactory.create(inp); //Create sheet instance Sheet sheet = wb.getSheetAt(0); for(int i = 3; i <= 16; ++i){ //Rows from 4 to 15 (Apache POI is zero based) Row row = sheet.getRow(i); Cell cell = row.getCell(2); //Column "C" //Do something with cell } // Write the output to a file FileOutputStream fileOut = new FileOutputStream("workbook.xls"); wb.write(fileOut); fileOut.close(); 

来源(更多的例子在这里)