in reply to To Read and Edit docx files in Windows 7
There is no need for a module, as you can use the OLE interface to interact directly with Word. Any module that wraps (or replaces) this functionality would have to be updated for each new version of Office that comes out.
This code should get you started on the right track (though this is written for Word 2013, as that is what I have. You should be able to just change the object library version number to get it to work with your version of Word
use 5.16.2; use Win32::OLE; use Win32::OLE::Const 'Microsoft Office 15.0 Object Library'; my $word = Win32::OLE->new( 'Word.Application', 'Quit' ); my $doc = $word->Documents->Open( 'C:\Temp\OLE\Word\test.docx' ) || d +ie 'Unable to open document: ', Win32::OLE->LastError; my $paragraphs = Win32::OLE::Enum->new( $doc->Paragraphs ); while ( defined( my $paragraph = $paragraphs->Next ) ) { my $words = Win32::OLE::Enum->new( $paragraph->{Range}->{Words} ); while ( defined( my $word = $words->Next ) ) { $word->{Text} =~ s/([Hh])i/$1ello/; } } $doc->Save; $doc->Close;
You may also find this helpful: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word%28v=office.14%29.aspx
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: To Read and Edit docx files in Windows 7
by DVCHAL (Novice) on Dec 15, 2014 at 10:25 UTC | |
by SimonPratt (Friar) on Dec 15, 2014 at 15:15 UTC | |
by DVCHAL (Novice) on Dec 16, 2014 at 05:11 UTC | |
by Anonymous Monk on Dec 16, 2014 at 07:26 UTC | |
by DVCHAL (Novice) on Dec 16, 2014 at 10:54 UTC | |
|