Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

My application send an excel sheet with all the Data to the administrator. I need to make this excel sheet password protected. i.e a normal excel sheet you go to excel sheet-> tools -> options -> security and add a Password , on reopening the excel sheet it always asks for the password. This idea I need to hardcode into my application.

Replies are listed 'Best First'.
Re: Perl and excel sheets
by marto (Cardinal) on Jun 13, 2007 at 08:42 UTC
    Anonymous Monk,

    You have been given advice regards using Spreadsheet::WriteExcel, however I would ask that you read the documentation as it contains a note about $worksheet->protect();.

    Since you have been pretty non specific as to which OS you are using the following information may not be of use to you, however lets take a look at the differences between 'protecting' and 'password protecting' a workbook.

    'Tools'->'Options'->'Security'->'File Encryption settings for this workbook' generates the following vba code: ActiveWorkbook.Password = "mypasswordhere"

    'Tools'->'Protection'->'Protect Sheet' generates the following vba code: ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True

    If you are Windows based you could look at the ActiveState article How to convert a VBA macro to Perl, to implement either of the above in Perl.

    Hope this helps

    Martin
Re: Perl and excel sheets
by aquarium (Curate) on Jun 13, 2007 at 06:27 UTC
    Since you do not offer any kind of a start that you might have tried or any useful related information (e.g. Operating System)....I can only offer the general idea to have a look at the WriteEcel module, which has a protect() function.
    have fun
    the hardest line to type correctly is: stty erase ^H
Re: Perl and excel sheets
by the_hawk_1 (Scribe) on Jun 13, 2007 at 13:44 UTC
    Hi Anonymous,

    could have been interesting to register, anyway it's free!

    Anyway, you should take a look to the node Password protection creating an Excel spreadsheet. There is the answer to you need.

    I've tried $sheet->protect('MyPassword'); with ActivePerl on Windows XP, using WIN32::OLE module and it worked fine.

    Hope this will help.