.....and, I should have made it clear that removing a cell will not cause
those cells to it's right top automatically re-number themselves and so
effectively remove the column for you. You will still need to move these
cells to the left manually so to speak; well at least I think that you will
have to.

Yours

Mark B


MSB wrote:
> 
> Bear in ind that I have never needed to perfrom either operation when I
> say that I do not think thata there is an 'easy' soution to either
> problem.
> 
> Removing a column will be by far the easier operation to perform as all
> you will need to do is to iterate through all of the rows on the sheet and
> call the removeCell() method. This method is defined on the
> org.apache.poi.ss.usermodel.Row interface which HSSFRow and XSSFRow both
> implement.
> 
> Adding a column will, I think, be a little more tricky. On the HSSFRow
> class there is a method called moveCell() which, as it's name suggestes,
> allows you to move an existing cell from one column to a new one. The only
> snag with tha method is that the javadoc says the following "Moves the
> supplied cell to a new column, which must not already have a cell there!".
> To insert a new column, I am guessing that you will again need to process
> each row iteratively. Staring with the final cell in the column, you will
> need to move this to the next column, possibly next to remove it from the
> column it once occupied and then repeat this process; however, I have
> never tried this so cannot promise any sort of success. If you are
> targeting the OpenXML based file format through XSSFRow, then you are
> likely to be in more trouble beacuse I cannot see any similarly named
> methods defined on that class. Further, even though XSSFCell allows you to
> get at the column index of the cell, the setCellNum() method - which you
> allow you to set the cells column index - is protected. Having said this,
> I will take the time to have a better dig around and post again if I
> manage to make any progress.
> 
> Yours
> 
> Mark B
> 
> 
> AR Williamson wrote:
>> 
>> Good Day all.
>> 
>> I am loving Apache POI at the moment, but i have some simple questions 
>> that I am sure someone can help with.
>> 
>> With respect to adding a new column; is it true I don't need to do this 
>> explicitly, merely set a cell value in the given row/col position.
>> 
>> On that logic, how does one remove a column?  What is the recommended 
>> approach here?
>> 
>> thanks
>> 
>> alan
>> http://alan.blog-city.com/
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>> 
>> 
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Adding-Deleting-a-Column-tp25982828p26004545.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to