I want to save a range of cells in XLS sheet as a HTML file, using a Perl script. I have googled for solutions to this problem. But haven’t found any.
However there is a solution similar to this using Excel VBA:
With ActiveWorkbook.PublishObjects.Add(xlSourceRange, _
"C:\Documents and Settings\Tim\Desktop\Page.htm", _
Selection.Parent.Name, _
Selection.Address(), _
xlHtmlStatic, "divExcelExport", _
"TestTitle")
.Publish (True)
.AutoRepublish = False
End With
So, I tried converting this to Perl code, but it gives me the following errors:
H:\test_code\data>perl a.pl
Win32::OLE(0.1702) error 0x800a03ec
in METHOD/PROPERTYGET “Add”
H:\test_code\data>
use strict;
use warnings "all";
use Win32::OLE;
my $Excel = Win32::OLE->GetActiveObject('Excel.Application') ||
Win32::OLE->new('Excel.Application','Quit');
my $Book = $Excel->Workbooks->Open("H:\\test_code\\data\\test.xls");
my $Sheet = $Book->Worksheets(1);
$Book->PublishObjects->Add({SourceType=>5, # int value for xlSourceRange
FileName => "H:\\test_code\\data\\test2.html",
Source => $Sheet->Range("A1:B2")->Address,
HtmlType => 0, # xlHtmlStatic s int value.
});
print Win32::OLE->LastError();
$Book->Close(0);
exit();
Can some one please suggest a solution for this problem.
Note, that I want to preserve all the formatting of the columns, (Decimal, number of digits, $ Sign, color etc..). Any solution which doesn’t involve usage of a commercial library is appreciated.
Thanks,
Rizwan.
This works for me, at least the HTML file is being generated: