JRBJhawk has asked for the wisdom of the Perl Monks concerning the following question:
Esteemed Monks:
I am using Perl to add some charts to an Excel spreadsheet generated in 2003 XML on another system. I can open the XML file and add the charts but when I try to save the modified spreadsheet in the 2007 xlOpenXMLWorkbook format, I get this error:
OLE exception from "Microsoft Office Excel"
Unable to get the SaveAs property from the Workbook class
Win32::OLE(0.1709) error 0x800a03ec
in METHOD/PROPERTY "SaveAs" in PerlMonks.pl line 31
Here is the code the error message refers to:
#!/usr/bin/perl -w use diagnostics; use diagnostics -verbose; use strict; use Cwd; use Win32::OLE; use Win32::OLE::Const "Microsoft Excel"; use Win32::OLE::Variant; use Win32::OLE::NLS qw(:LOCALE :DATE); my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); $Excel->{Visible} = 1; $Excel->{DisplayAlerts} = 0; my $dir = cwd(); $dir =~ s/\//\\/g; my $path = $dir . "\\PerlMonksTest.xml"; my $Book = $Excel->Workbooks->OpenXML($path); $Book->Activate; my $new_file= $dir . "\\PerlMonksTestWB.xlsx"; if(-e $new_file) {unlink $new_file or die "Could not remove '$new_file +': $!\n";} $Book->SaveAs( {Filename => "$new_file", FileFormat => 'xlOpenXMLWorkb +ook', CreateBackup => 'False'} ); #$Book->SaveAs( {Filename => "$new_file"} );
When I use the SaveAs in line 32 instead of 31, I don't get the error, but the workbook is saved as 2003 XML, which doesn't support charts (as far as I can tell).
I can supply the XML file referred to in the code above (PerlMonksTest.xml) if necessary.
Thanks for your help.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem using SaveAs when trying to change Excel format
by Anonymous Monk on Nov 06, 2009 at 18:16 UTC | |
by JRBJhawk (Novice) on Nov 10, 2009 at 16:35 UTC | |
by Anonymous Monk on Jul 09, 2014 at 05:41 UTC | |
by Anonymous Monk on Jul 09, 2014 at 06:54 UTC | |
by Anonymous Monk on Jul 09, 2014 at 11:43 UTC | |
|