Protecting Excel sheets using Apache POI

Hi All,

In this article I will show how to protect excel sheet using Apache POI, Apache POI, a project run by the Apache Software Foundation, and previously a sub-project of the Jakarta Project, provides pure Java libraries for reading and writing files in Microsoft Office formats, such as Word, PowerPoint and Excel.

The below programme will demonstrate on Excel :

public static void main(String arg[]) {
//Specify the name of the outout file
FileOutputStream out=new FileOutputStream(new File(“protected.xls”));

//Create  the workbook object
HSSFWorkbook hssfworkbook = new HSSFWorkbook();

/* Creates a sample sheet with name as Sheet 1 */
HSSFSheet sheet = hssfworkbook.createSheet(“Sheet1”);

String CELL_DATA = “First cell data”;

/* Creates first row */
HSSFRow row = sheet.createRow(0);

/* Creates a first cell */

HSSFCell cell =row.createCell((short)0);

/* Sets the value in first cell */

/* Sets the password for the sheet */

/* Writes to the File Output stream */

} catch(Exception e){


Hope this helps.

R Vashi

2 thoughts on “Protecting Excel sheets using Apache POI

  1. Bunty Raut

    Hi Rakesh,

    One Request can you please add some XML releted critical issue which you faced in your work experince , i am new to on XML and my current project i am using much XMl .

    Bunty Raut

    1. ®V Post author

      Hi Bunty,

      Sure there are plenty of issues we face while working XML like, parsing issue, DTD Validations, navigation issue, namespace issues,
      I will sure try to post more example on the same, Also you can post your issues which you are facing while handling XML Data. I would be very happy to solve the same.


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.