Changing value of cell in Excel via apache-poi

让人想犯罪 __ 提交于 2019-12-13 04:18:03

问题


I'm trying to change value of cell in .xls document.

In .xls file i have got only 1 cell - A1 with abc value inside.

My code:

        File fo = new File("D:\\TMP\\Zeszyt1.xls");
        HSSFWorkbook a = new HSSFWorkbook(new FileInputStream(fo));
        HSSFSheet my_sheet = a.getSheetAt(0);
        HSSFRow my_row = my_sheet.getRow(0);

        HSSFCell myCell;
        myCell = my_row.getCell(0);
        myCell.setCellValue("NEW VALUE");

How to commit this changes? When i open .xls file i still have got abc value inside A1.


回答1:


You have to write to the file.

FileOutputStream outputStream = new FileOutputStream(new File("abc.xls"));
workbook.write(outputStream);
outputStream.close();//Close in finally if possible


来源:https://stackoverflow.com/questions/24574490/changing-value-of-cell-in-excel-via-apache-poi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!