gongcw has asked for the wisdom of the Perl Monks concerning the following question:
Updated
##################################################### ########### open the excel file for parsing ##################################################### my $srcExcelName = "test.xlsx"; my $excelObject=Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); $excelObject->{DisplayAlerts} = 0; my $xlsBook=$excelObject->WorkBooks->Open($srcExcelName); my $xlsSheet = $xlsBook->Worksheets("Sheet1"); ########### open the excel file for parsing ##################################################### ########### open the word file for saving ##################################################### my $wordBasicName=$excelFileName; $wordBasicName =~s/\.xlsx?$//; my $saveWordName=$wordBasicName.".docx"; my $wordObject = CreateObject Win32::OLE 'Word.Application' or die $!; $wordObject->{'Visible'} = 0; my $document = $wordObject->Documents->Add; my $selection = $wordObject->Selection; ########### open the word file for saving ##################################################### ########### get the picture in sheets and save them in workdir ##################################################### my $iCount=0; my $picFileType="BMP"; my @picFileArray; foreach my $picObj ( in $xlsSheet->Pictures){ my $savePicName = $workdir."aa".$iCount++.".".$picFileType; $picObj->Copy(); my $clip=Win32::Clipboard(); if( $clip->IsBitmap()){ open CLIPPIC, ">$savePicName"; binmode CLIPPIC; print CLIPPIC $clip->GetBitmap; close CLIPPIC; } push @picFileArray, $savePicName; } foreach ( @picFileArray ){ $selection -> TypeParagraph; $selection -> InlineShapes->AddPicture({ FileName => $_ }); $selection -> TypeParagraph; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to get picture in MS excel and insert them into MS word file by the module win32::OLE?
by roboticus (Chancellor) on Jan 05, 2010 at 12:26 UTC | |
by gongcw (Initiate) on Jan 06, 2010 at 08:58 UTC | |
by roboticus (Chancellor) on Jan 06, 2010 at 22:40 UTC | |
by gongcw (Initiate) on Jan 07, 2010 at 02:48 UTC | |
by roboticus (Chancellor) on Jan 07, 2010 at 13:51 UTC | |
|