poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Beardsley <markbrd...@tiscali.co.uk>
Subject Re: Equivalent methods in Apache POI
Date Wed, 12 Jan 2011 16:00:22 GMT

Hello again,

1) Will my new worksheet be created as the first sheet always? Can i specify
the index of the sheet when creating it? Say workbook.createSheet("sheet1",
0) etc. Please clarify. 

The worksheet wil always be created as the sheet at the next available index
number. So, when you create a new workbook, the first call to the
createSheet(String) method will create the equivalent of 'Sheet 1' in Excel
terms, the next call will create 'Sheet 2' and so on. There are only two
watys to reate sheets using the SS usermodel and they are createSheet() and
createSheet(String) and currently, there is no method to allow you to
specify the index number of the sheet. What you cold do if it is imprtant to
be able to determine where in the workbook the sheet appears is to use the
setSheetOrder(String, int) to specify this. The two parameters to this
method are the name of the sheet and the postion you want it to appear in
the workbook. So, imagine you wanted to create a new sheet and insert it
into an existing workbook as the second sheet, you would do something like

Sheet newSheet = workbook.createSheet("New Sheet");
workbook.setSheetOrder("New Sheet", 1);

Remember that sheets are indexed from zero and not from one.

2) How do i password protect the entire worksheet? is there a method defined
for achieving this feature? Please let me know. 

There is no easy answer to this question as the technique will differ
depenind upon whether you are dealing with the older binary format (HSSF) or
the more recent SpreadsheetML file format (XSSF). Off of the top of my head,
I cannot remember the exact steps for both and will need time to look over
some olde code before answering. I do know that HSSF requires you to call
the setLocked(boolean) method for each cell style but I cannot remember off
hand the second step in the process. I do not think it currently support
locking at the worksheet level but rather at the cell level also. XSSF
supports finer grained locking that I have explained elsewhere so I know I
have the code for this and can post it later. The drawbacks are obvious
though; you will need to maintain two different codebases to support the
different types of protection.

Will post again later.


Mark B
View this message in context: http://apache-poi.1045710.n5.nabble.com/Equivalent-methods-in-Apache-POI-tp3331946p3338391.html
Sent from the POI - User mailing list archive at Nabble.com.

To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org

View raw message