CrazyEngineers Archive
Old, but evergreen and popular discussions on CrazyEngineers, presented to you in read-only mode.
@sookie • 09 Oct, 2009
Hi everyone,

Is anyone here having any idea of how to make excel files[more specific -generated as JasperReports] password protected and cell protected[I mean making it "read only" type] . Though I need to do so using Java program but that part I will look later. Anyone can shed any light related to this.

PS: Its kind of urgent.

Thanks a lot !
@Kaustubh Katdare • 09 Oct, 2009 I'm reading this as "How to password protect excel sheets" (office 2007) - Here's the solution:

1. Click the Microsoft Office Button (the Round , point to Prepare, and then click Encrypt Document.

2. In the Encrypt Document dialog box, in the Password box, type a password, and then click OK. You can type up to 255 characters. By default, this feature uses AES 128-bit advanced encryption. Encryption is a standard method used to help make your file more secure.

3. In the Confirm Password dialog box, in the Reenter password box, type the password again, and then click OK.

4. To save the password, save the file.
--------------------------------------------------------

Making a workbook read only -

1. On the Review tab, click Protect Document.

2. Select Restrict Formatting and Editing.

3. In Formatting restrictions, Editing restrictions and Start enforcement, you can make selections that meet your formatting and editing needs.
--------------------------------------------------------

I hope this helps.
@Mahesh Dahale • 09 Oct, 2009 For Microsoft Excel 2007

How to make excel files password protected

I hope this helps.
@sookie • 09 Oct, 2009 Thanks for the information both of you. I wish it could work for me but not.

Well, anyone has any ideas why following properties(or similar to them) exist for net.sf.jasperreports.engine.export.JRPdfExporterParameter Class
but not for net.sf.jasperreports.engine.export.JRXlsAbstractExporterParameter class? Is there any alternative for this? Any other API or similar class providing such properties?

JRPdfExporterParameter.IS_ENCRYPTED
JRPdfExporterParameter.IS_128_BIT_KEY
JRPdfExporterParameter.USER_PASSWORD
JRPdfExporterParameter.OWNER_PASSWORD

Why they have provided security related stuff for PDF API but not for Excel ? Any special reason for this ?
Thanks !
@sookie • 12 Oct, 2009 Hi everyone,

Thanks a lot for the help. Well, my problem is not solved yet and it seem a time-consuming one as many of the Java APIs have taken into consideration of only PDF Files security but not of Excel sheets. Don't know why everyone ignored such thing[I mean excel sheets security]. 😐. Anyway, I found that a password protected excel sheet can be created in Java. See if of any help to anyone here at any point of time.

Step # 1: Just download latest poi.jar from following location
All classes in poi-3.2-FINAL.jar

Step # 2: Write a program like following in your machine.
package demo;
import java.io.*;
import org.apache.poi.hssf.usermodel.*;
/**
 *
 * @author sookie
 */
public class PasswordProtectedExcelSheet {
 
 
    public static void main(String arg[]) {
        try{
            FileOutputStream out = new FileOutputStream("C:\\Sample.xls");
 
            /* Creates the workbook */
            HSSFWorkbook hssfworkbook = new HSSFWorkbook();
 
          // hssfworkbook.writeProtectWorkbook("xyz","xyz"); --> shows same behaviour even if uncommented
 
            /* Creates a sample sheet with name as Crazyengineer */
            HSSFSheet sheet = hssfworkbook.createSheet("Crazy Engineer");
            String CEAN_NAME = "sookie";
 
           /* Creates first row */
           HSSFRow row = sheet.createRow(0);
 
           /* Creates a first cell */
           HSSFCell cell =row.createCell((short)0);
 
           /* Sets the value in first cell */
           cell.setCellValue(CEAN_NAME);
 
           /* Sets the password for the sheet */
           sheet.protectSheet("xyz");
 
           /* Writes to the File Output stream */
            hssfworkbook.write(out);
            out.close();
        } catch(Exception e){
            e.printStackTrace();
            System.out.println("Exception occured");
        }
    }
 
 
}
As an outcome of above program, a Sample.xls file will create in C:\ and when you will open it "sookie' will be written in it. The best part is it will not allow you to modify the contents of the cell and would ask to remove the protected fromt he sheet using "Un Protect command" under "Review" tab and when you will remove it, it will ask for the password "xyz'. Afte entering correct password only, it will allow you to modify.

Worst part is it don't ask for password first. I want that it could first ask for the password without allowing user to view the report file. None of any such methods is provided in the API. I tried almost everything If anyone has any clue or has more time or has interest in playing with the stuff then Please check the classes of poi.jar and see how it can be changed to work in much betre way.

Any doubts ? Feel free to ask me.

Thanks !
@shreya_rulz • 22 Oct, 2009 hey heres a much simpler way to do it.
in your sheet or workbook go to "tools".
click on "options".
select the "security " tab out there.
you have 2 options:first is "password to open" and second is "password to modify".
select whichever you want.
@Saandeep Sreerambatla • 22 Oct, 2009 Moreover , If you want to encrypt and decrypt the file using crytographic methods this is the software.

Gpg4win

Will give more details once I work on this.

for more details check this.

Gpg4win - Wikipedia, the free encyclopedia




@sookie • 22 Oct, 2009
shreya_rulz
hey heres a much simpler way to do it.
in your sheet or workbook go to "tools".
click on "options".
select the "security " tab out there.
you have 2 options:first is "password to open" and second is "password to modify".
select whichever you want.
Thanks for the information. What if I don't want to do this manually for 1000 of excel sheets ? I just want to automate it in the code? What would be your SIMPLER way then? Any answers?

English-Scared
Moreover , If you want to encrypt and decrypt the file using crytographic methods this is the software.

Gpg4win

Will give more details once I work on this.

for more details check this.

Gpg4win - Wikipedia, the free encyclopedia
Thanks for the information. What if I don't want to use any third party software?What would be your answer if I want to embed everything in my code only? Any logic you know which these softwares use to encrypt files?

Before answering again Please read the problem asked carefully.

Thanks a lot !
@Aashish Joshi • 22 Oct, 2009 how bout recording a macro for it?? you'll still have to open all the files at least, and set the passwords but you're spared the clicks in between!!
@sookie • 25 Oct, 2009
mad_scientist
you'll still have to open all the files at least, and set the passwords but you're spared the clicks in between!!
Nope, it will not work in my problem's case. We set passwords through coding and even files also get opened through code only.
@teddywin125 • 26 Oct, 2009 Hello.
-
I've met the same problem,and It can be done by the 'Aspose.cells' component.
@sookie • 27 Oct, 2009
teddywin125
Hello.
-
I've met the same problem,and It can be done by the 'Aspose.cells' component.
Hey teddywin, are you saying that by setting "Password" property of "Workbook" Class, it can be done? Can you please put some more light into it like How to go for it ?


Thanks !
@M.E. CERVANTES • 11 Apr, 2012
sookie
Hi everyone,
I found that a password protected excel sheet can be created in Java. See if of any help to anyone here at any point of time.
Hi Sookie, I found your trend while trying to solve the same problem. You made my day. Thank you.
@Anoop Kumar • 12 Apr, 2012 Just related to topic:
Well protecting Excel with password is a myth. anyone can break your password and can able to edit the
"PASSWORD protected EXCEL SHEET" . just google how to edit password protected excel sheet and you will find the answer. I don't why microsoft added this feature if it is breakable so easily.Funny thing is you will not able to know the password but you after editing you can apply the same password again.😲
6.2k views

Related Posts

@gopaldeshpande · Jun 6, 2012

why is pile foundation preffered to an open footing foundation for a residential building even when hard rock strata is available at a depth of about 6 to 7 metres...
8.2k views

@Sudha Warad · Oct 25, 2011

Hi, can anybody please upload placement papers of SLK softwares with interview experience. Shortly SLK is coming to our college for recruiting, please upload it soon. Thank u all.
7.9k views

@Sharvari Panchbhai · Dec 9, 2014

Canadian tablets and smartphones maker, Datawind, is popularly known for manufacturing UbiSlate tablet computers and PocketSurfer smartphones with affordable price tags. The company is also known for the development of...
5.2k views

@raj87verma88 · May 23, 2009

During her KYCEan interview, CEan Durga mentioned that she would like something like "How Stuff Works" on CE. The idea sounded good and I have decided to write the first...
3.7k views

@swati verma · Oct 26, 2008

what is the function of trap flag in 8086 microprocessor?
11.6k views