You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Debendra <de...@yahoo.co.in> on 2009/09/15 07:03:11 UTC

writeProtectWorkbook() method does not work to set password to excel file to open

Hi,
Could anyone please help me to create a password protected excel sheet. The
requirement is, password needs to be given to open an excel file. It will
not open the excel file without password. I am using the following program,
but it is not asking any password while opening.

import java.io.;
import org.apache.poi.hssf.usermodel.;
class PasswordExcelSheet {
public static void main(String arg[]) {
try{
FileOutputStream out = new
FileOutputStream("D:\\java_prog\\excelsheet\\MyExcel.xls");
HSSFWorkbook hssfworkbook = new HSSFWorkbook();
hssfworkbook.writeProtectWorkbook("abc","xyz");
HSSFSheet sheet = hssfworkbook.createSheet("new sheet");
String s="HCL Tech";
HSSFCellStyle cs = hssfworkbook.createCellStyle();
HSSFDataFormat df = hssfworkbook.createDataFormat();
HSSFFont f = hssfworkbook.createFont();
HSSFFont f2 = hssfworkbook.createFont();
cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
HSSFRow row = sheet.createRow((short)0);
HSSFCell cell = row.createCell((short)0);
cell.setCellValue(s );
cell.setCellStyle(cs);
//sheet.protectSheet("xyz");
hssfworkbook.write(out);
out.close();
}
catch(Exception e){
System.out.println("Error : "+e);
}
}
} 
-- 
View this message in context: http://www.nabble.com/writeProtectWorkbook%28%29-method-does-not-work-to-set-password-to-excel-file-to-open-tp25447832p25447832.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


Re: writeProtectWorkbook() method does not work to set password to excel file to open

Posted by MSB <ma...@tiscali.co.uk>.
Sorry that did not work. I should have the time tonight to play with some
code and will let you know if I make any progress.

Yours

Mark B


Debendra wrote:
> 
> Hi Mark,
> If I uncomment the statement sheet.protectSheet("xyz"); then it does not
> allow to modify the excel sheet but it does not ask any password to open
> the excel file. It is not prompting any password while opening the excel
> file, but my requirement is it should ask password to open the excel file.
> The excel file will not be opened without any password. Could you please
> help me to solve this issue.
> 
> Thanks,
> Debendra
> 
> 
> MSB wrote:
>> 
>> I think that I am correct in saying that there are two parts to this
>> equation, cell is locking and protection; unless cells are locked then
>> protection will not be enabled.
>> 
>> The easy wasy to test this hypotheses is to modify the cell style you are
>> creating in the attached code and add this line;
>> 
>> cs.setLocked(true);
>> 
>> apply the cell style as you are now and uncomment the protectSheet("xyz")
>> line;
>> 
>> sheet.protectSheet("xyz");
>> 
>> I think that will solve the problem but cannot be absolutely certain;
>> either way, it is certainly worth checking.
>> 
>> Yours
>> 
>> Mark B
>> 
>> 
>> Debendra wrote:
>>> 
>>> Hi,
>>> Could anyone please help me to create a password protected excel sheet.
>>> The requirement is, password needs to be given to open an excel file. It
>>> will not open the excel file without password. I am using the following
>>> program, but it is not asking any password while opening.
>>> 
>>> import java.io.;
>>> import org.apache.poi.hssf.usermodel.;
>>> class PasswordExcelSheet {
>>> public static void main(String arg[]) {
>>> try{
>>> FileOutputStream out = new
>>> FileOutputStream("D:\\java_prog\\excelsheet\\MyExcel.xls");
>>> HSSFWorkbook hssfworkbook = new HSSFWorkbook();
>>> hssfworkbook.writeProtectWorkbook("abc","xyz");
>>> HSSFSheet sheet = hssfworkbook.createSheet("new sheet");
>>> String s="HCL Tech";
>>> HSSFCellStyle cs = hssfworkbook.createCellStyle();
>>> HSSFDataFormat df = hssfworkbook.createDataFormat();
>>> HSSFFont f = hssfworkbook.createFont();
>>> HSSFFont f2 = hssfworkbook.createFont();
>>> cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
>>> HSSFRow row = sheet.createRow((short)0);
>>> HSSFCell cell = row.createCell((short)0);
>>> cell.setCellValue(s );
>>> cell.setCellStyle(cs);
>>> //sheet.protectSheet("xyz");
>>> hssfworkbook.write(out);
>>> out.close();
>>> }
>>> catch(Exception e){
>>> System.out.println("Error : "+e);
>>> }
>>> }
>>> } 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/writeProtectWorkbook%28%29-method-does-not-work-to-set-password-to-excel-file-to-open-tp25447832p25457488.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


Re: writeProtectWorkbook() method does not work to set password to excel file to open

Posted by MSB <ma...@tiscali.co.uk>.
On the 16th of September, I posted two replies to your original question.
Neither I am sorry to say contained any good news but I have copied the text
out of the second reply for you below;

"Sorry to say that I cannot report any real progress and that I am moving
toward the conclusion that it is not possible to set the open password for
an Excel file using POI.

As I indicated in an earlier post, I did try using a template file that I
created with Excel and which had an open password. Unfortunately, it was
not possible even to open this file using POI, closing that avenue of
exploration quite conclusively.

The writeProtectWorkbook() method does work after a fashion; if you try
to open the file using Excel, you will be asked for a password but it is
still possible to view a read-only copy of it's contents even if you do
not supply a password.

Not too sure what your options are at this stage though I am confident many
people would appreciate it if you would consdier patching the API to support
setting the open password. Other than that, I would guess that you could
look at;

* Creating an on activation macro that would prompt the user to enter
  a password.
* Using OpenOffices' UNO interface to automate the base application and use
  that to create Excel workbooks.
* Using OLE to control Excel itself directly from Java code.

None of these solutions is ideal in my opinion as each has it's own inherent
limitations but they could offer you a short term fix.

Yours

Mark B"



Debendra wrote:
> 
> Hi Mark,
> Could you please inform us, did you get any solution for this.
> 
> Regards,
> Debendra
> 
> 
> Debendra wrote:
>> 
>> Hi All,
>> You are saying that it is not possible to set password to an excel file
>> to open using existing POI API. If it is not possible to create a
>> password protected excel sheet which asks password to open then we need
>> to put our effort to add this functionality to POI. If you have found out
>> a way to do this using POI then could you please publish the same in this
>> discussion.
>> 
>> Regards,
>> Debendra
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/writeProtectWorkbook%28%29-method-does-not-work-to-set-password-to-excel-file-to-open-tp25447832p25530583.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


Re: writeProtectWorkbook() method does not work to set password to excel file to open

Posted by Debendra <de...@yahoo.co.in>.
Hi Mark,
Could you please inform us, did you get any solution for this.

Regards,
Debendra


Debendra wrote:
> 
> Hi All,
> You are saying that it is not possible to set password to an excel file to
> open using existing POI API. If it is not possible to create a password
> protected excel sheet which asks password to open then we need to put our
> effort to add this functionality to POI. If you have found out a way to do
> this using POI then could you please publish the same in this discussion.
> 
> Regards,
> Debendra
> 

-- 
View this message in context: http://www.nabble.com/writeProtectWorkbook%28%29-method-does-not-work-to-set-password-to-excel-file-to-open-tp25447832p25530574.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


Re: writeProtectWorkbook() method does not work to set password to excel file to open

Posted by Debendra <de...@yahoo.co.in>.
Hi All,
You are saying that it is not possible to set password to an excel file to
open using existing POI API. If it is not possible to create a password
protected excel sheet which asks password to open then we need to put our
effort to add this functionality to POI. If you have found out a way to do
this using POI then could you please publish the same in this discussion.

Regards,
Debendra
-- 
View this message in context: http://www.nabble.com/writeProtectWorkbook%28%29-method-does-not-work-to-set-password-to-excel-file-to-open-tp25447832p25503361.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


Re: writeProtectWorkbook() method does not work to set password to excel file to open

Posted by "Lingjiao.Chen" <li...@cloudnovations.com>.
Thanks, I'll follow on that route.

>I suggest that you ask on the dev list very soon as the developer that  
>is most likely to be of help is in the US.

I'm not sure what you meant by this. I am a developer situated in the
U.S.... But okay :confused:


Dave Fisher-6 wrote:
> 
> HI Ling,
> 
>> I want to rephrase my question. Will this functionality be included  
>> within
>> (not before) the 3.5 FINAL version release?
> 
> Nick was pretty clear. Unless you or someone else (unknown to us)  
> codes it in the next few days with unit tests and examples.
> 
> Then the answer is a simple "No"
> 
>> In the mean time, I will take your advice and look into the core
>> functionalities.
> 
> If this is important to you, then this is your path. This is the path  
> of most all developers and contributions to POI.
> 
> I suggest that you ask on the dev list very soon as the developer that  
> is most likely to be of help is in the US.
> 
> Regards,
> Dave
> 
> 
>>
>> Ling
>>
>>
>>
>> Nick Burch wrote:
>>>
>>> On Tue, 15 Sep 2009, Lingjiao.Chen wrote:
>>>> I know you've mentioned that the final version will be released  
>>>> sometime
>>>> soon (Oct). Do you for-see this functionality being included to that
>>>> version?
>>>
>>> I can't see the support being added before 3.5 final by any of the  
>>> core
>>> developers of poi, based on what people have said they'll be  
>>> working on.
>>>
>>> So, if it's important to you, I'd suggest you hop on over to the  
>>> dev list,
>>> and ask for pointers on how to start coding up the functionality  
>>> itself.
>>> Patches and new developers are always very welcome :)
>>>
>>> Nick
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>>> For additional commands, e-mail: user-help@poi.apache.org
>>>
>>>
>>>
>>
>> -- 
>> View this message in context:
>> http://www.nabble.com/writeProtectWorkbook%28%29-method-does-not-work-to-set-password-to-excel-file-to-open-tp25447832p25491210.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
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/writeProtectWorkbook%28%29-method-does-not-work-to-set-password-to-excel-file-to-open-tp25447832p25491913.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


Re: writeProtectWorkbook() method does not work to set password to excel file to open

Posted by Dave Fisher <da...@jmlafferty.com>.
HI Ling,

> I want to rephrase my question. Will this functionality be included  
> within
> (not before) the 3.5 FINAL version release?

Nick was pretty clear. Unless you or someone else (unknown to us)  
codes it in the next few days with unit tests and examples.

Then the answer is a simple "No"

> In the mean time, I will take your advice and look into the core
> functionalities.

If this is important to you, then this is your path. This is the path  
of most all developers and contributions to POI.

I suggest that you ask on the dev list very soon as the developer that  
is most likely to be of help is in the US.

Regards,
Dave


>
> Ling
>
>
>
> Nick Burch wrote:
>>
>> On Tue, 15 Sep 2009, Lingjiao.Chen wrote:
>>> I know you've mentioned that the final version will be released  
>>> sometime
>>> soon (Oct). Do you for-see this functionality being included to that
>>> version?
>>
>> I can't see the support being added before 3.5 final by any of the  
>> core
>> developers of poi, based on what people have said they'll be  
>> working on.
>>
>> So, if it's important to you, I'd suggest you hop on over to the  
>> dev list,
>> and ask for pointers on how to start coding up the functionality  
>> itself.
>> Patches and new developers are always very welcome :)
>>
>> Nick
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>> For additional commands, e-mail: user-help@poi.apache.org
>>
>>
>>
>
> -- 
> View this message in context: http://www.nabble.com/writeProtectWorkbook%28%29-method-does-not-work-to-set-password-to-excel-file-to-open-tp25447832p25491210.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
>


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


Re: writeProtectWorkbook() method does not work to set password to excel file to open

Posted by "Lingjiao.Chen" <li...@cloudnovations.com>.
Thanks, Nick.

I want to rephrase my question. Will this functionality be included within
(not before) the 3.5 FINAL version release?

In the mean time, I will take your advice and look into the core
functionalities.

Ling



Nick Burch wrote:
> 
> On Tue, 15 Sep 2009, Lingjiao.Chen wrote:
>> I know you've mentioned that the final version will be released sometime 
>> soon (Oct). Do you for-see this functionality being included to that 
>> version?
> 
> I can't see the support being added before 3.5 final by any of the core 
> developers of poi, based on what people have said they'll be working on.
> 
> So, if it's important to you, I'd suggest you hop on over to the dev list, 
> and ask for pointers on how to start coding up the functionality itself. 
> Patches and new developers are always very welcome :)
> 
> Nick
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/writeProtectWorkbook%28%29-method-does-not-work-to-set-password-to-excel-file-to-open-tp25447832p25491210.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


Re: writeProtectWorkbook() method does not work to set password to excel file to open

Posted by Nick Burch <ni...@torchbox.com>.
On Tue, 15 Sep 2009, Lingjiao.Chen wrote:
> I know you've mentioned that the final version will be released sometime 
> soon (Oct). Do you for-see this functionality being included to that 
> version?

I can't see the support being added before 3.5 final by any of the core 
developers of poi, based on what people have said they'll be working on.

So, if it's important to you, I'd suggest you hop on over to the dev list, 
and ask for pointers on how to start coding up the functionality itself. 
Patches and new developers are always very welcome :)

Nick

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


Re: writeProtectWorkbook() method does not work to set password to excel file to open

Posted by "Lingjiao.Chen" <li...@cloudnovations.com>.
Hi Yegor,

We are gaining a lot of grounds in efforts of transitioning to the latest
poi-3.5 in order to support  .xlsx formats. One of the core requirements
from our application/client is to password protect the final output
workbook. 

I know you've mentioned that the final version will be released sometime
soon (Oct). Do you for-see this functionality being included to that
version?

Thanks.


Yegor Kozlov wrote:
> 
> writeProtecWorkbook() is XSSF is not yet supported.
> 
> Yegor
>> In respect to the subject, does anyone know why writeProtecWorkbook()
>> method
>> is not supported within the XSSFWorkbook API ? Is there an alternative
>> way
>> to password 'lock' the workbook with the XSSF format? Or is it that the
>> method hasn't been implemented yet ?
>> 
>> Thanks.
>> 
>> 
>> 
>> Debendra wrote:
>>> Hi Mark,
>>> If I uncomment the statement sheet.protectSheet("xyz"); then it does not
>>> allow to modify the excel sheet but it does not ask any password to open
>>> the excel file. It is not prompting any password while opening the excel
>>> file, but my requirement is it should ask password to open the excel
>>> file.
>>> The excel file will not be opened without any password. Could you please
>>> help me to solve this issue.
>>>
>>> Thanks,
>>> Debendra
>>>
>>>
>>> MSB wrote:
>>>> I think that I am correct in saying that there are two parts to this
>>>> equation, cell is locking and protection; unless cells are locked then
>>>> protection will not be enabled.
>>>>
>>>> The easy wasy to test this hypotheses is to modify the cell style you
>>>> are
>>>> creating in the attached code and add this line;
>>>>
>>>> cs.setLocked(true);
>>>>
>>>> apply the cell style as you are now and uncomment the
>>>> protectSheet("xyz")
>>>> line;
>>>>
>>>> sheet.protectSheet("xyz");
>>>>
>>>> I think that will solve the problem but cannot be absolutely certain;
>>>> either way, it is certainly worth checking.
>>>>
>>>> Yours
>>>>
>>>> Mark B
>>>>
>>>>
>>>> Debendra wrote:
>>>>> Hi,
>>>>> Could anyone please help me to create a password protected excel
>>>>> sheet.
>>>>> The requirement is, password needs to be given to open an excel file.
>>>>> It
>>>>> will not open the excel file without password. I am using the
>>>>> following
>>>>> program, but it is not asking any password while opening.
>>>>>
>>>>> import java.io.;
>>>>> import org.apache.poi.hssf.usermodel.;
>>>>> class PasswordExcelSheet {
>>>>> public static void main(String arg[]) {
>>>>> try{
>>>>> FileOutputStream out = new
>>>>> FileOutputStream("D:\\java_prog\\excelsheet\\MyExcel.xls");
>>>>> HSSFWorkbook hssfworkbook = new HSSFWorkbook();
>>>>> hssfworkbook.writeProtectWorkbook("abc","xyz");
>>>>> HSSFSheet sheet = hssfworkbook.createSheet("new sheet");
>>>>> String s="HCL Tech";
>>>>> HSSFCellStyle cs = hssfworkbook.createCellStyle();
>>>>> HSSFDataFormat df = hssfworkbook.createDataFormat();
>>>>> HSSFFont f = hssfworkbook.createFont();
>>>>> HSSFFont f2 = hssfworkbook.createFont();
>>>>> cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
>>>>> HSSFRow row = sheet.createRow((short)0);
>>>>> HSSFCell cell = row.createCell((short)0);
>>>>> cell.setCellValue(s );
>>>>> cell.setCellStyle(cs);
>>>>> //sheet.protectSheet("xyz");
>>>>> hssfworkbook.write(out);
>>>>> out.close();
>>>>> }
>>>>> catch(Exception e){
>>>>> System.out.println("Error : "+e);
>>>>> }
>>>>> }
>>>>> } 
>>>>>
>>>>
>>>
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/writeProtectWorkbook%28%29-method-does-not-work-to-set-password-to-excel-file-to-open-tp25447832p25454471.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


Re: writeProtectWorkbook() method does not work to set password to excel file to open

Posted by Yegor Kozlov <ye...@dinom.ru>.
writeProtecWorkbook() is XSSF is not yet supported.

Yegor
> In respect to the subject, does anyone know why writeProtecWorkbook() method
> is not supported within the XSSFWorkbook API ? Is there an alternative way
> to password 'lock' the workbook with the XSSF format? Or is it that the
> method hasn't been implemented yet ?
> 
> Thanks.
> 
> 
> 
> Debendra wrote:
>> Hi Mark,
>> If I uncomment the statement sheet.protectSheet("xyz"); then it does not
>> allow to modify the excel sheet but it does not ask any password to open
>> the excel file. It is not prompting any password while opening the excel
>> file, but my requirement is it should ask password to open the excel file.
>> The excel file will not be opened without any password. Could you please
>> help me to solve this issue.
>>
>> Thanks,
>> Debendra
>>
>>
>> MSB wrote:
>>> I think that I am correct in saying that there are two parts to this
>>> equation, cell is locking and protection; unless cells are locked then
>>> protection will not be enabled.
>>>
>>> The easy wasy to test this hypotheses is to modify the cell style you are
>>> creating in the attached code and add this line;
>>>
>>> cs.setLocked(true);
>>>
>>> apply the cell style as you are now and uncomment the protectSheet("xyz")
>>> line;
>>>
>>> sheet.protectSheet("xyz");
>>>
>>> I think that will solve the problem but cannot be absolutely certain;
>>> either way, it is certainly worth checking.
>>>
>>> Yours
>>>
>>> Mark B
>>>
>>>
>>> Debendra wrote:
>>>> Hi,
>>>> Could anyone please help me to create a password protected excel sheet.
>>>> The requirement is, password needs to be given to open an excel file. It
>>>> will not open the excel file without password. I am using the following
>>>> program, but it is not asking any password while opening.
>>>>
>>>> import java.io.;
>>>> import org.apache.poi.hssf.usermodel.;
>>>> class PasswordExcelSheet {
>>>> public static void main(String arg[]) {
>>>> try{
>>>> FileOutputStream out = new
>>>> FileOutputStream("D:\\java_prog\\excelsheet\\MyExcel.xls");
>>>> HSSFWorkbook hssfworkbook = new HSSFWorkbook();
>>>> hssfworkbook.writeProtectWorkbook("abc","xyz");
>>>> HSSFSheet sheet = hssfworkbook.createSheet("new sheet");
>>>> String s="HCL Tech";
>>>> HSSFCellStyle cs = hssfworkbook.createCellStyle();
>>>> HSSFDataFormat df = hssfworkbook.createDataFormat();
>>>> HSSFFont f = hssfworkbook.createFont();
>>>> HSSFFont f2 = hssfworkbook.createFont();
>>>> cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
>>>> HSSFRow row = sheet.createRow((short)0);
>>>> HSSFCell cell = row.createCell((short)0);
>>>> cell.setCellValue(s );
>>>> cell.setCellStyle(cs);
>>>> //sheet.protectSheet("xyz");
>>>> hssfworkbook.write(out);
>>>> out.close();
>>>> }
>>>> catch(Exception e){
>>>> System.out.println("Error : "+e);
>>>> }
>>>> }
>>>> } 
>>>>
>>>
>>
> 


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


Re: writeProtectWorkbook() method does not work to set password to excel file to open

Posted by "Lingjiao.Chen" <li...@cloudnovations.com>.
In respect to the subject, does anyone know why writeProtecWorkbook() method
is not supported within the XSSFWorkbook API ? Is there an alternative way
to password 'lock' the workbook with the XSSF format? Or is it that the
method hasn't been implemented yet ?

Thanks.



Debendra wrote:
> 
> Hi Mark,
> If I uncomment the statement sheet.protectSheet("xyz"); then it does not
> allow to modify the excel sheet but it does not ask any password to open
> the excel file. It is not prompting any password while opening the excel
> file, but my requirement is it should ask password to open the excel file.
> The excel file will not be opened without any password. Could you please
> help me to solve this issue.
> 
> Thanks,
> Debendra
> 
> 
> MSB wrote:
>> 
>> I think that I am correct in saying that there are two parts to this
>> equation, cell is locking and protection; unless cells are locked then
>> protection will not be enabled.
>> 
>> The easy wasy to test this hypotheses is to modify the cell style you are
>> creating in the attached code and add this line;
>> 
>> cs.setLocked(true);
>> 
>> apply the cell style as you are now and uncomment the protectSheet("xyz")
>> line;
>> 
>> sheet.protectSheet("xyz");
>> 
>> I think that will solve the problem but cannot be absolutely certain;
>> either way, it is certainly worth checking.
>> 
>> Yours
>> 
>> Mark B
>> 
>> 
>> Debendra wrote:
>>> 
>>> Hi,
>>> Could anyone please help me to create a password protected excel sheet.
>>> The requirement is, password needs to be given to open an excel file. It
>>> will not open the excel file without password. I am using the following
>>> program, but it is not asking any password while opening.
>>> 
>>> import java.io.;
>>> import org.apache.poi.hssf.usermodel.;
>>> class PasswordExcelSheet {
>>> public static void main(String arg[]) {
>>> try{
>>> FileOutputStream out = new
>>> FileOutputStream("D:\\java_prog\\excelsheet\\MyExcel.xls");
>>> HSSFWorkbook hssfworkbook = new HSSFWorkbook();
>>> hssfworkbook.writeProtectWorkbook("abc","xyz");
>>> HSSFSheet sheet = hssfworkbook.createSheet("new sheet");
>>> String s="HCL Tech";
>>> HSSFCellStyle cs = hssfworkbook.createCellStyle();
>>> HSSFDataFormat df = hssfworkbook.createDataFormat();
>>> HSSFFont f = hssfworkbook.createFont();
>>> HSSFFont f2 = hssfworkbook.createFont();
>>> cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
>>> HSSFRow row = sheet.createRow((short)0);
>>> HSSFCell cell = row.createCell((short)0);
>>> cell.setCellValue(s );
>>> cell.setCellStyle(cs);
>>> //sheet.protectSheet("xyz");
>>> hssfworkbook.write(out);
>>> out.close();
>>> }
>>> catch(Exception e){
>>> System.out.println("Error : "+e);
>>> }
>>> }
>>> } 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/writeProtectWorkbook%28%29-method-does-not-work-to-set-password-to-excel-file-to-open-tp25447832p25453856.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


Re: writeProtectWorkbook() method does not work to set password to excel file to open

Posted by Debendra <de...@yahoo.co.in>.
Hi Mark,
If I uncomment the statement sheet.protectSheet("xyz"); then it does not
allow to modify the excel sheet but it does not ask any password to open the
excel file. It is not prompting any password while opening the excel file,
but my requirement is it should ask password to open the excel file. The
excel file will not be opened without any password. Could you please help me
to solve this issue.

Thanks,
Debendra


MSB wrote:
> 
> I think that I am correct in saying that there are two parts to this
> equation, cell is locking and protection; unless cells are locked then
> protection will not be enabled.
> 
> The easy wasy to test this hypotheses is to modify the cell style you are
> creating in the attached code and add this line;
> 
> cs.setLocked(true);
> 
> apply the cell style as you are now and uncomment the protectSheet("xyz")
> line;
> 
> sheet.protectSheet("xyz");
> 
> I think that will solve the problem but cannot be absolutely certain;
> either way, it is certainly worth checking.
> 
> Yours
> 
> Mark B
> 
> 
> Debendra wrote:
>> 
>> Hi,
>> Could anyone please help me to create a password protected excel sheet.
>> The requirement is, password needs to be given to open an excel file. It
>> will not open the excel file without password. I am using the following
>> program, but it is not asking any password while opening.
>> 
>> import java.io.;
>> import org.apache.poi.hssf.usermodel.;
>> class PasswordExcelSheet {
>> public static void main(String arg[]) {
>> try{
>> FileOutputStream out = new
>> FileOutputStream("D:\\java_prog\\excelsheet\\MyExcel.xls");
>> HSSFWorkbook hssfworkbook = new HSSFWorkbook();
>> hssfworkbook.writeProtectWorkbook("abc","xyz");
>> HSSFSheet sheet = hssfworkbook.createSheet("new sheet");
>> String s="HCL Tech";
>> HSSFCellStyle cs = hssfworkbook.createCellStyle();
>> HSSFDataFormat df = hssfworkbook.createDataFormat();
>> HSSFFont f = hssfworkbook.createFont();
>> HSSFFont f2 = hssfworkbook.createFont();
>> cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
>> HSSFRow row = sheet.createRow((short)0);
>> HSSFCell cell = row.createCell((short)0);
>> cell.setCellValue(s );
>> cell.setCellStyle(cs);
>> //sheet.protectSheet("xyz");
>> hssfworkbook.write(out);
>> out.close();
>> }
>> catch(Exception e){
>> System.out.println("Error : "+e);
>> }
>> }
>> } 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/writeProtectWorkbook%28%29-method-does-not-work-to-set-password-to-excel-file-to-open-tp25447832p25450770.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


Re: writeProtectWorkbook() method does not work to set password to excel file to open

Posted by MSB <ma...@tiscali.co.uk>.
I think that I am correct in saying that there are two parts to this
equation, cell is locking and protection; unless cells are locked then
protection will not be enabled.

The easy wasy to test this hypotheses is to modify the cell style you are
creating in the attached code and add this line;

cs.setLocked(true);

apply the cell style as you are now and uncomment the protectSheet("xyz")
line;

sheet.protectSheet("xyz");

I think that will solve the problem but cannot be absolutely certain; either
way, it is certainly worth checking.

Yours

Mark B


Debendra wrote:
> 
> Hi,
> Could anyone please help me to create a password protected excel sheet.
> The requirement is, password needs to be given to open an excel file. It
> will not open the excel file without password. I am using the following
> program, but it is not asking any password while opening.
> 
> import java.io.;
> import org.apache.poi.hssf.usermodel.;
> class PasswordExcelSheet {
> public static void main(String arg[]) {
> try{
> FileOutputStream out = new
> FileOutputStream("D:\\java_prog\\excelsheet\\MyExcel.xls");
> HSSFWorkbook hssfworkbook = new HSSFWorkbook();
> hssfworkbook.writeProtectWorkbook("abc","xyz");
> HSSFSheet sheet = hssfworkbook.createSheet("new sheet");
> String s="HCL Tech";
> HSSFCellStyle cs = hssfworkbook.createCellStyle();
> HSSFDataFormat df = hssfworkbook.createDataFormat();
> HSSFFont f = hssfworkbook.createFont();
> HSSFFont f2 = hssfworkbook.createFont();
> cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
> HSSFRow row = sheet.createRow((short)0);
> HSSFCell cell = row.createCell((short)0);
> cell.setCellValue(s );
> cell.setCellStyle(cs);
> //sheet.protectSheet("xyz");
> hssfworkbook.write(out);
> out.close();
> }
> catch(Exception e){
> System.out.println("Error : "+e);
> }
> }
> } 
> 

-- 
View this message in context: http://www.nabble.com/writeProtectWorkbook%28%29-method-does-not-work-to-set-password-to-excel-file-to-open-tp25447832p25448594.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


Re: writeProtectWorkbook() method does not work to set password to excel file to open

Posted by MSB <ma...@tiscali.co.uk>.
There is nothing that I can see to explicitly set the open password for an
Excel (.xls) file. However, I am going to try a workaround just to see if
the following is possible;

Using Excel, create a template file and set the open password.
Open that file with POI and populate the worksheet(s) then save the workbook
away again using a different name. Hopefully, the password will not prevent
POI from parsing the file and allowing me to work with the workbook.
Try to open this workbook using Excel: hopefully, it will ask me for the
password.

Will post again later.

Yours

Mark B


Debendra wrote:
> 
> Hi,
> Could anyone please help me to create a password protected excel sheet.
> The requirement is, password needs to be given to open an excel file. It
> will not open the excel file without password. I am using the following
> program, but it is not asking any password while opening.
> 
> import java.io.;
> import org.apache.poi.hssf.usermodel.;
> class PasswordExcelSheet {
> public static void main(String arg[]) {
> try{
> FileOutputStream out = new
> FileOutputStream("D:\\java_prog\\excelsheet\\MyExcel.xls");
> HSSFWorkbook hssfworkbook = new HSSFWorkbook();
> hssfworkbook.writeProtectWorkbook("abc","xyz");
> HSSFSheet sheet = hssfworkbook.createSheet("new sheet");
> String s="HCL Tech";
> HSSFCellStyle cs = hssfworkbook.createCellStyle();
> HSSFDataFormat df = hssfworkbook.createDataFormat();
> HSSFFont f = hssfworkbook.createFont();
> HSSFFont f2 = hssfworkbook.createFont();
> cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
> HSSFRow row = sheet.createRow((short)0);
> HSSFCell cell = row.createCell((short)0);
> cell.setCellValue(s );
> cell.setCellStyle(cs);
> //sheet.protectSheet("xyz");
> hssfworkbook.write(out);
> out.close();
> }
> catch(Exception e){
> System.out.println("Error : "+e);
> }
> }
> } 
> 

-- 
View this message in context: http://www.nabble.com/writeProtectWorkbook%28%29-method-does-not-work-to-set-password-to-excel-file-to-open-tp25447832p25466985.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


Re: writeProtectWorkbook() method does not work to set password to excel file to open

Posted by MSB <ma...@tiscali.co.uk>.
Sorry to say that I cannot report any real progress and that I am moving
toward the conclusion that it is not possible to set the open password for
an Excel file using POI.

As I indicated in an earlier post, I did try using a template file that I
created with Excel and which had an open password. Unfortunately, it was
not possible even to open this file using POI, closing that avenue of 
exploration quite conclusively.

The writeProtectWorkbook() method does work after a fashion; if you try
to open the file using Excel, you will be asked for a password but it is
still possible to view a read-only copy of it's contents even if you do
not supply a password.

Not too sure what your options are at this stage though I am confident many
people would appreciate it if you would consdier patching the API to support
setting the open password. Other than that, I would guess that you could 
look at;

* Creating an on activation macro that would prompt the user to enter
  a password.
* Using OpenOffices' UNO interface to automate the base application and use
  that to create Excel workbooks.
* Using OLE to control Excel itself directly from Java code.

None of these solutions is ideal in my opinion as each has it's own inherent
limitations but they could offer you a short term fix.

Yours

Mark B


Debendra wrote:
> 
> Hi,
> Could anyone please help me to create a password protected excel sheet.
> The requirement is, password needs to be given to open an excel file. It
> will not open the excel file without password. I am using the following
> program, but it is not asking any password while opening.
> 
> import java.io.;
> import org.apache.poi.hssf.usermodel.;
> class PasswordExcelSheet {
> public static void main(String arg[]) {
> try{
> FileOutputStream out = new
> FileOutputStream("D:\\java_prog\\excelsheet\\MyExcel.xls");
> HSSFWorkbook hssfworkbook = new HSSFWorkbook();
> hssfworkbook.writeProtectWorkbook("abc","xyz");
> HSSFSheet sheet = hssfworkbook.createSheet("new sheet");
> String s="HCL Tech";
> HSSFCellStyle cs = hssfworkbook.createCellStyle();
> HSSFDataFormat df = hssfworkbook.createDataFormat();
> HSSFFont f = hssfworkbook.createFont();
> HSSFFont f2 = hssfworkbook.createFont();
> cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
> HSSFRow row = sheet.createRow((short)0);
> HSSFCell cell = row.createCell((short)0);
> cell.setCellValue(s );
> cell.setCellStyle(cs);
> //sheet.protectSheet("xyz");
> hssfworkbook.write(out);
> out.close();
> }
> catch(Exception e){
> System.out.println("Error : "+e);
> }
> }
> } 
> 

-- 
View this message in context: http://www.nabble.com/writeProtectWorkbook%28%29-method-does-not-work-to-set-password-to-excel-file-to-open-tp25447832p25475012.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