简体   繁体   English

通过apache-poi在Excel中更改单元格的值

[英]Changing value of cell in Excel via apache-poi

I'm trying to change value of cell in .xls document. 我正在尝试更改.xls文档中单元格的值。

In .xls file i have got only 1 cell - A1 with abc value inside. 在.xls文件中,我只有1个单元格-A1,里面有abc值。

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. 当我打开.xls文件时,我在A1内仍然有abc值。

You have to write to the file. 您必须write文件。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用合并的单元格值大于单元格宽度的Apache-POI增加excel行的高度? - How to increase the height of the excel row using Apache-POI having merged cell value greater than the cell width? Apache-POI在Excel中设置值,但是另一个单元格的公式无法使用该值,除非我在处理栏中手动按Enter - Apache-POI sets values in Excel, but the formula of another cell is unable to work with the value until I manually press enter in the processing strip Apache-POI 在 excel 中对行进行排序 - Apache-POI sorting rows in excel 在excel中更改其他单元格值时更改单元格值[通过Apache POI进行数据验证] - Changing Cell Value upon changing other cell value in excel [Data validation through Apache POI] Apache-POI-如何在Cell-Editor中像Excel一样四舍五入数字 - Apache-POI - How do i round numbers like Excel does in Cell-Editor 如何在apache-poi的新版本中为单个单元格设置Excel单元格前景色? - How to set an Excel Cell foreground color for individual cells in the new version for apache-poi? 如何使用apache-poi 3.9修改pptx文件中表格的单元格值? - How to modify the cell value of a table in an pptx file with apache-poi 3.9? Java Apache-POI nullpointer异常,有关在现有行中创建单元格 - Java Apache-POI nullpointer exception on creating a cell in an existing row Apache-POI:单元格背景颜色不起作用 - Apache-POI: Cell Background Color doesn't work Apache POI读取Excel单元格的公式值 - Apache POI reading formula value of excel cell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM