开发者

Apache POI: How to insert column in Excel file

I'm using POI to manipulate data in Excel files for a university project. I'm having trouble inserting a new column in an existing Excel. I tried to use

Cell c = createCell(int column);
c.setCellValue("someValue");

but it seems that if the column already exists, it replaces the existing data开发者_如何学Python. What I need is to shift all the other columns one column to the right when I insert the new one.

I searched over the internet but I couldn't find a solution to that. Is there a way to do it, without iterating all the cells in the row and moving them one-by-one ?


To my knowledge, POI doesn't support this directly. You could create a copy of the worksheet and copy the data over, leaving room for your new column. You also need to take into consideration the need to re-write any formulas in the columns beyond your insertion point and any formulas that use those cells.


According to this post from 2008, which I got from Google "poi insert column", POI does not presently have an API to do this. You will need to iterate over the rows and adjust all references yourself.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜