How to create new rows in apache poi 3.6?

☆樱花仙子☆ 提交于 2019-12-08 07:54:13

问题


I am using Apache POI 3.6 and java in our application.

I have data in row numbers 9 to 30.

Now, I want to include new rows after the row number 25. After doing like this, the old data in 26 to 30 was destroyed.... I want to add that new rows without destroy the old row's data...

We can manually, create new rows by just right click the mouse on the row Header like row number 25 and select insert then it will include the 26 row without deleting anything about the old values.

How I do it programatically using apache poi and java?


回答1:


First you need to do move down all the rows from 25 onwards by doing a shift

sheet1.shiftRows(25, sheet1.getLastRowNum(), 5);

this will move down all rows from 25 by 5 places

then insert the new rows in that position

row1 = sheet1.getRow(25); 
                HSSFCell cell1 = row1.createCell(0);
                cell1.setCellValue("text: The new line goes here");


来源:https://stackoverflow.com/questions/3651305/how-to-create-new-rows-in-apache-poi-3-6

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