countryroadscat
countryroadscat

Reputation: 1750

Changing value of cell in Excel via apache-poi

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.

Upvotes: 0

Views: 8124

Answers (1)

Akash Thakare
Akash Thakare

Reputation: 22974

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

Upvotes: 4

Related Questions