通过apache-poi更改Excel中单元格的值 [英] Changing value of cell in Excel via apache-poi
本文介绍了通过apache-poi更改Excel中单元格的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试更改 .xls 文档中单元格的值.
I'm trying to change value of cell in .xls document.
在 .xls 文件中,我只有 1 个单元格 - A1 里面有 abc
值.
In .xls file i have got only 1 cell - A1 with abc
value inside.
我的代码:
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");
如何提交此更改?当我打开 .xls 文件时,我仍然在 A1 中有 abc
值.
How to commit this changes? When i open .xls file i still have got abc
value inside A1.
推荐答案
你必须write
到文件中.
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
这篇关于通过apache-poi更改Excel中单元格的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文