in reply to When not logged in, using Win32::OLE for Excel fails

You cannot launched Excel without a connected desktop and other things.

You have two possible approaches. Either have your service start up its own login session, mount the appropriate registry hive and set up everything as it should be. Or, use Spreadsheet::ParseExcel, which does not need Excel to read a spreadsheet.

Update: Also, maybe use Spreadsheet::Read, which can read more than just Excel files.

  • Comment on Re: When not logged in, using Win32::OLE for Excel fails

Replies are listed 'Best First'.
Re^2: When not logged in, using Win32::OLE for Excel fails
by gdolph (Novice) on Mar 31, 2010 at 09:59 UTC

    There may be another solution. I was experiencing a similar problem with Win32::OLE for excel after I migrated some scripts from a windows server 2003 to a windows 2008 server. I use Spreadsheet::WriteExcel to create a spreadsheet but as I want it in excel 2007 format (.xlsx) I use Win32::OLE to convert it from 2003 to 2007 format.

    my $exc = Win32::OLE->new('Excel.Application','Quit') || die "could no +t start excel\n"; $exc->{Visible} = 0; #runs excel in the background $exc->{DisplayAlerts} = 1; my $book = $exc->Workbooks->Open("$path") || die ("Can't open file $pa +th ", Win32::OLE->LastError()); $book->SaveAs({FileName => "$convto", FileFormat => 51}) || die ("Can' +t save as file format ", Win32::OLE->LastError()); $book->Close(); $exc->Quit();

    I did some searching and found that all I needed to do to fix is was to create the directory c:\windows\syswow64\config\systemprofile\desktop (or system32 instead of syswow64 on a 32 bit system). After I did that it all worked fine. Here's the posting I got that trick from:

    http://social.msdn.microsoft.com/Forums/en-ZA/olbasics/thread/e437524b-412a-4ed3-9cf8-fb9afed7a7ad

    Hope this helps!