Ask a questionAsk a question
 

AnswerCreate Password Protected Excel Sheet with OOXML

  • Tuesday, April 28, 2009 6:31 AMaditya prakash Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,
    I need to create an password protected excel sheet usign OOXML, XSL and ASP. I am able to create the excel sheet which is protected but that could be unprotected by user. I could not find any thing to put the password while making that excel sheet protected.
    Any Attributes avaliable with OOXML to make excel sheet password protected.

Answers

  • Monday, May 18, 2009 5:04 PMMark Miller_DSCMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hi Aditya,

     

    I have completed my investigation of this issue and will summarize my findings below:

    1)      When you create a “Protected” workbook in the Excel UI you will find that it becomes a Compound File Binary File Format (MS-CFB) document (not ZIP) although the file extension does not change.

    For example, this is the header for a protected document created in the Excel UI (MS-CFB document):

    0000h: D0 CF 11 E0 A1 B1 1A E1 00 00 00 00 00 00 00 00  ÐÏ.ࡱ.á........

     

                    This is the header for an unprotected document created in the Excel UI (ZIP package):

                    0000h: 50 4B 03 04 14 00 06 00 08 00 00 00 21 00 9E 6F  PK..........!.žo

     

    2)      You may use the System.IO.Packaging namespace in .NET to create the Excel documents programmatically, and an example is detailed here, http://support.microsoft.com/kb/931866.  Or, you may use the Open XML SDK, and there are several examples here, http://www.microsoft.com/downloads/details.aspx?familyid=8d46c01f-e3f6-4069-869d-90b8b096b556&displaylang=en.  Whichever you choose, or however you may already have coded it, you will need to implement the WorkbookProtection Class, and/or add the workbookProtection element *before* the bookViews element and *after* the workbookPr element.  Also note, the workbookPassword attribute is defined as xsd:hexBinary type with limited length of 2.  For more information refer to MSDN, http://msdn.microsoft.com/en-us/library/documentformat.openxml.spreadsheet.workbookprotection.workbookpassword(Office.14).aspx and/or ECMA 376 Standard, http://www.ecma-international.org/publications/standards/Ecma-376.htm

    3)      Note that even after implementing the “protection” mechanism described above the document is not considered “secure” as the password can fairly easily be obtained or removed.

     

    At this point in time the Open XML SDK does not provide functionality to open or create files with Compound File protection.  In other words, once the document is no longer a zip package it can no longer be opened within the Open XML SDK.  We are looking into ways of improving the SDK to support such scenarios.

     


    Regards,
    Mark Miller
    Escalation Engineer
    US-CSS DSC PROTOCOL TEAM

All Replies

  • Tuesday, April 28, 2009 3:31 PMJohn DunningMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello Aditya,

    We will review your question and post a response shortly.

    Thanks!
    John Dunning
    Senior Escalation Engineer Microsoft Corporation
    US-CSS DSC PROTOCOL TEAM
  • Thursday, May 07, 2009 10:27 PMMark Miller_DSCMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi Aditya Prakash,

    I am the owner of this issue and have been actively pursuing an answer for your question.  I have not yet completed my investigation of this issue.  However, I hope to have an answer for you soon.

    Regards,
    Mark Miller
    Escalation Engineer
    US-CSS DSC PROTOCOL TEAM

  • Monday, May 18, 2009 5:04 PMMark Miller_DSCMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hi Aditya,

     

    I have completed my investigation of this issue and will summarize my findings below:

    1)      When you create a “Protected” workbook in the Excel UI you will find that it becomes a Compound File Binary File Format (MS-CFB) document (not ZIP) although the file extension does not change.

    For example, this is the header for a protected document created in the Excel UI (MS-CFB document):

    0000h: D0 CF 11 E0 A1 B1 1A E1 00 00 00 00 00 00 00 00  ÐÏ.ࡱ.á........

     

                    This is the header for an unprotected document created in the Excel UI (ZIP package):

                    0000h: 50 4B 03 04 14 00 06 00 08 00 00 00 21 00 9E 6F  PK..........!.žo

     

    2)      You may use the System.IO.Packaging namespace in .NET to create the Excel documents programmatically, and an example is detailed here, http://support.microsoft.com/kb/931866.  Or, you may use the Open XML SDK, and there are several examples here, http://www.microsoft.com/downloads/details.aspx?familyid=8d46c01f-e3f6-4069-869d-90b8b096b556&displaylang=en.  Whichever you choose, or however you may already have coded it, you will need to implement the WorkbookProtection Class, and/or add the workbookProtection element *before* the bookViews element and *after* the workbookPr element.  Also note, the workbookPassword attribute is defined as xsd:hexBinary type with limited length of 2.  For more information refer to MSDN, http://msdn.microsoft.com/en-us/library/documentformat.openxml.spreadsheet.workbookprotection.workbookpassword(Office.14).aspx and/or ECMA 376 Standard, http://www.ecma-international.org/publications/standards/Ecma-376.htm

    3)      Note that even after implementing the “protection” mechanism described above the document is not considered “secure” as the password can fairly easily be obtained or removed.

     

    At this point in time the Open XML SDK does not provide functionality to open or create files with Compound File protection.  In other words, once the document is no longer a zip package it can no longer be opened within the Open XML SDK.  We are looking into ways of improving the SDK to support such scenarios.

     


    Regards,
    Mark Miller
    Escalation Engineer
    US-CSS DSC PROTOCOL TEAM