in reply to Copy, Cut, Paste Word document
Here is a simple solution that inserts the entire body of one document at the end of another document. It assumes that you want to manipulate the two documents' files on disk. If what you wanted to do was (for example) insert the contents of the current selection into another open document, that would be slightly more involved. In general, none of this kind of stuff is too complicated; but finding good references and examples can be kinda tough. In addition to the docs for the Win32::OLE modules, I found the Microsoft documentation for the Word object model to be indispensable.
This is just an example. You'd probably want to add more error handling, not to mention a better way of defining which document files are to be processed.use Win32::OLE; use Win32::OLE::Const 'Microsoft Word'; my $source_doc = "X:\\source.doc"; my $dest_doc = "X:\\dest.doc"; my $Word = new Win32::OLE 'Word.Application', 'Quit'; $Word->Documents->open( $source_doc ) or die "Unable to open $source_doc ", Win32::OLE->LastError(); my $text = $Word->ActiveDocument->Content->Text; $Word->ActiveDocument->Close; $Word->Documents->open( $dest_doc ) or die "Unable to open $dest_doc ", Win32::OLE->LastError(); $Word->ActiveDocument->Content->InsertAfter({ Text => $text }); $Word->ActiveDocument->Close;
jdporter
...porque es dificil estar guapo y blanco.
|
|---|