Hi,
I am attempting to transfer data from a word table to Excel using
Win32::OLE. I am able to do it with the following piece of code, but I am
getting two little boxes after the text in each of the Excel cells. I
presume these are Word formatting characters. How can I filter these out? I
am using a test Word table of 5 rows and 5 columns.
I have come across suggestions that one should save the Word file as an html
file first. I did that and ran the program again after changing the input
file name to tesfile.mht, but I am getting the same results. Perhaps I have
to use some other module like HTML::PARSER. Isn't there some way I can do
the filtering through Win32::OLE itself?
use warnings;
use strict;
# INVOKE WIN32::OLE AND OPEN WORD AND EXCEL FILES
#================================================
my($Word,$wordfile,$doc,$tbl,$wordcell);
my($Excel,$excelfile,$book,$sheet,$excelcell);
my($row,$col);
use Win32::OLE qw(in with);
use Win32::OLE::Variant;
use Win32::OLE::NLS qw(:LOCALE :DATE);
use Win32::OLE::Const 'Microsoft Excel';
use Win32::OLE::Const 'Microsoft Word';
use Win32::OLE::Const 'Microsoft Office';
$Win32::OLE::Warn = 3; # Die on Errors.
$wordfile = 'E:/jag/word_perl/testfile.doc';
$Word = Win32::OLE->GetActiveObject('Word.Application')
|| Win32::OLE->new('Word.Application', 'Quit');
$doc = $Word->Documents->Open($wordfile);
$tbl = $doc->Tables(1);
$excelfile = 'E:/jag/word_perl/testfile.xls';
$Excel = Win32::OLE->GetActiveObject('Excel.Application')
|| Win32::OLE->new('Excel.Application', 'Quit');
$book = $Excel->Workbooks->Open($excelfile);
$sheet = $book->Worksheets("Sheet1");
# TRANSFER DATA
#==============
foreach $row(1..5) {
foreach $col(1..5) {
$wordcell = $tbl->Cell($row,$col)->Range->{Text};
$sheet->Cells($row,$col)->{Value} = $wordcell;
}
}
$doc->Save;
$doc->Close;
$book->Save;
$book->Close;
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs