Hello,

Yes there is a way to find this information but it will still mean iterating
through the rows on the sheet. If you take a look at the
org.apache.poi.ss.usermodel.Row interface, there is a method declared there
called getLastCellNum(), to quote the javadoc, it;

"Gets the index of the last cell contained in this row PLUS ONE."

The Row interface is implemented by both the HSSFRow and XSSFRow classes so
you are safe to call this method whichever stream you are using.

I must admit though that if it where me, I would simply keep track of how
many columns I was populating as I built each row. All that would entail is
having a simple int bariable for each Sheet in the workbook and, as you
populate ecah cell in a row then simply cehek to see if the column number is
greater than the value in this variable, if so, then update the variable.
Thinking about it further, you need only perfrom this test once, after you
have built each row because then you will know how many columns there are in
it.

As to deleting a page, then the answer is no, there is no inbuilt method. I
do not really know why you are seeing these extra pages but suspect that
there are 'empty' rows in the worksheet which could be there if you are
modifying an existing workbook or using a template. Again, it would be
fairly easy for you to determine if there are additional empty rows in the
sheet; as with the columns, just keep track of how many rows you are
creating then, and I am not sure which you will have to use as I have never
done this, call either the getLastRowNum() or getPhysicalNumberOfRows()
methods on the Sheet. There is likely to be a discrepancy which I think will
indicate how many rows you need to remove or hide.

Hope this helps; if not just post another message to the list and tell me a
little more about how you are building your workbook, whether you are using
a template file, etc.

Yours

Mark B


dgv123 wrote:
> 
> 
> Hi Mark,
> 
> hiding columns work, but then is there a way to find out how many columns
> are 
> present in a particular sheet..like the 'getlastrownum' method to find the
> last 
> row in a sheet. This way, i can iterate through the columns and hide them
> all.
> 
> Yes. I would like to know if POI has an inbuilt method to delete a
> page..when i 
> do a print preview, i see that my document has 4 pages when only the first
> page 
> has data...i would like to delete pages 2,3,4 so that they dont print out.
> 
> Thanks again for your help!
> Derryl.
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/POI-%28Excel%29-usage-questions.-tp24116860p24147820.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