Updated


My idea is to get each picture( or shape ) in excel firstly, then copy it to clipboard. The Win32::Clipboard can save picture object from clipboard.
I think the detailed code for all steps can show them clearly:


##################################################### ########### 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; }




The original problem:


Dear All,
I met some questions about the issuse in title recently.
I tried to parse excel by win32::ole module, but some pictures exist in one sheet. I need to get these picture objects and insert them into one word file.
My idea is save these pictures from excel file, and insert them into the word file. But problems appeared when I tried to save these picture from excel.
Actually, I'm not sure my idea is a correct method. Maybe some better ways can be employed for this issue. So could someone can give me some advices about how to use win32::ole to get the picture in excel, and insert them into word file?
And actually, I'm not familiar with the API of win32::ole very well. :(
Thanks very much for all friends.

In reply to How to get picture in MS excel and insert them into MS word file by the module win32::OLE? by gongcw

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.