By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,312 Members | 1,280 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,312 IT Pros & Developers. It's quick & easy.

Opening Password Protected Excel file using Win32:OLE in Perl

P: 33
Hi,
I need help to open a password protected excel file in perl using Win32:OLE.
when I tried to open file in normal way at the time of program execution it is prompting me to enter password.
I am giving the script i used for opening excel file..
So i want to know how to provide password parameter while opening the file.
Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use Win32::OLE;
  3. use Win32::OLE::Const 'Microsoft Excel';
  4. use Win32::OLE::Variant qw(:DEFAULT nothing);
  5. $Win32::OLE::Warn = 3;
  6.  
  7. my $excelObj;
  8. my $fileName = "D:\\Mohan\\test.xls";
  9. $excelObj = Win32::OLE->new('Excel.Application', 'Quit');
  10. $excelObj->{'DisplayAlerts'} = 0;
  11. $excelObj->{'AskToUpdateLinks'} = 0;
  12. $excelObj->{'Visible'} = 0;
  13. my $bookObj;
  14. # If there is any problem in accessing files then auto mail will be sent.       
  15. eval
  16. {
  17.     $bookObj = $excelObj->Workbooks->Open($fileName);
  18. };
  19. if($@)
  20. {
  21.     my $msg = "";
  22.     die "A problem was encountered when accessing the file $fileName \n";
  23. }
  24. my $sheetObj = $bookObj->Worksheets(1);
  25. my $val    = $sheetObj->Cells(10,3)->{'Value'};
  26. print "Value == $val\n";
  27. $excelObj->ActiveWorkbook->Close(0);
  28. $excelObj->Quit();
  29.  
Thanks in Advance.
Dec 10 '07 #1
Share this Question
Share on Google+
1 Reply


numberwhun
Expert Mod 2.5K+
P: 3,503
Hi,
I need help to open a password protected excel file in perl using Win32:OLE.
when I tried to open file in normal way at the time of program execution it is prompting me to enter password.
I am giving the script i used for opening excel file..
So i want to know how to provide password parameter while opening the file.
Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use Win32::OLE;
  3. use Win32::OLE::Const 'Microsoft Excel';
  4. use Win32::OLE::Variant qw(:DEFAULT nothing);
  5. $Win32::OLE::Warn = 3;
  6.  
  7. my $excelObj;
  8. my $fileName = "D:\\Mohan\\test.xls";
  9. $excelObj = Win32::OLE->new('Excel.Application', 'Quit');
  10. $excelObj->{'DisplayAlerts'} = 0;
  11. $excelObj->{'AskToUpdateLinks'} = 0;
  12. $excelObj->{'Visible'} = 0;
  13. my $bookObj;
  14. # If there is any problem in accessing files then auto mail will be sent.       
  15. eval
  16. {
  17.     $bookObj = $excelObj->Workbooks->Open($fileName);
  18. };
  19. if($@)
  20. {
  21.     my $msg = "";
  22.     die "A problem was encountered when accessing the file $fileName \n";
  23. }
  24. my $sheetObj = $bookObj->Worksheets(1);
  25. my $val    = $sheetObj->Cells(10,3)->{'Value'};
  26. print "Value == $val\n";
  27. $excelObj->ActiveWorkbook->Close(0);
  28. $excelObj->Quit();
  29.  
Thanks in Advance.
To tell you the truth, I am not really sure how you would do this as I haven't played with Excel spreadsheets with Perl. I did check CPAN and it looks like the Spreadsheet::ParseExcel module has "ToDo" plans of implementing something to access protected Excel spreadsheets. It may behoove you to contact the author and see where he is with that. If he hasn't touched it, then if you get a solution in place to do so, it would be a good chance to publish either your first or another Perl module.

Regards,

Jeff
Dec 10 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.