Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Win32::OLE not support Ubuntu 14.10

by PhillipHuang (Beadle)
on Jun 11, 2015 at 09:52 UTC ( [id://1130005]=perlquestion: print w/replies, xml ) Need Help??

PhillipHuang has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks, I need to find and replace a word in DOC document by Perl, where i find this link: http://stackoverflow.com/questions/7051471/find-and-replace-a-word-in-doc-document-perl. It told me to use Win32::OLE, and when I try to install this module by cpan:
cpan[1]> install Win32::OLE Reading '/root/.cpan/Metadata' Database was generated on Thu, 11 Jun 2015 03:17:02 GMT Running install for module 'Win32::OLE' Checksum for /root/.cpan/sources/authors/id/J/JD/JDB/Win32-OLE-0.1712. +tar.gz ok Scanning cache /root/.cpan/build for sizes ...................................................................... +......DONE Configuring J/JD/JDB/Win32-OLE-0.1712.tar.gz with Makefile.PL OS unsupported Warning: No success on command[/usr/bin/perl Makefile.PL INSTALLDIRS=s +ite] JDB/Win32-OLE-0.1712.tar.gz /usr/bin/perl Makefile.PL INSTALLDIRS=site -- NOT OK Failed during this command: JDB/Win32-OLE-0.1712.tar.gz : writemakefile NO '/usr +/bin/perl Makefile.PL INSTALLDIRS=site' returned status 65280
it says "OS unsupported". Would you please give me any hints? or other modules and ways to modify Word DOC? Thanks in advanced, Phillip

Replies are listed 'Best First'.
Re: Win32::OLE not support Ubuntu 14.10
by Corion (Patriarch) on Jun 11, 2015 at 09:55 UTC

    Your OS is unsupported. Win32::OLE only works on Windows. Also, Win32::OLE needs Microsoft Word installed on the computer, which also only works on Windows.

Re: Win32::OLE not support Ubuntu 14.10
by marto (Cardinal) on Jun 11, 2015 at 09:56 UTC

    "Would you please give me any hints?"

    Not everything is cross platform, the module name should be a hint. The Win32 namespace is for modules for the Microsoft Windows system, they won't run on other OS. See also Linux:: modules.

Re: Win32::OLE not support Ubuntu 14.10
by marinersk (Priest) on Jun 11, 2015 at 11:16 UTC

    As noted, the approach you found is Windows-dependent.

    While not impossible, I do find it unlikely that you'll find a module out there which does the heavy lifting for you on this one.

    I'd say your options are:

    1. Research the file format for word docs and roll your own solution;
    2. Same as above, but do the extra work to make it a CPAN module.
      WARNING: Make sure this is legal and approved where you work -- in a tech company in the USA it is likely not (see Professional Employees and Works for Hire);
    3. Leave the problem unsolved;
    4. Update: Involve a Windows system with Word installed in the solution stream.

    Good luck!

      Research the file format for word docs and roll your own solution

      The "new" DOCX format is a ZIP archive of XML files and some other stuff. One of the XML files contains the document text. Archive::Zip can pack and unpack ZIP archives, XML::LibXML and some other modules can process XML.

      The "older" DOC formats are binary blobs. No easy way there, sorry.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

        Without looking up the format, I have to say that .DOCXfiles appear to be a cinch to edit. I just unzipped one, changed into the worddirectory it created, and popped open document.xml.

        While it has the typical Microsoft Word overabundant nonlinear code insertion (I did hack one of the early .DOCformats way back when and remember that observation being applicable), the raw text components seem to be fairly consistently in between <w:t>and </w:t>tags. Before writing production code I'd want to research that a bit, of course, but for a quick-n-dirty word replacement I'd probably be willing to gamble.

        Sample of what I found:

        <w:t xml:space="preserve"> so we can order food. Please include in your RSVP how many people will be attending. </w:t>

Re: Win32::OLE not support Ubuntu 14.10
by dasgar (Priest) on Jun 11, 2015 at 14:45 UTC

    As others have pointed out, you're not going to be able to use Win32::OLE on Ubuntu.

    I've got one idea that could work, but I have never looked into. You should be able to install LibreOffice, which can read most Word documents (see here for more details). I suspect (but don't know for sure) that there might be some kind of API available to automate LibreOffice - similar to using OLE to automate Office applications on Windows. If not, you should be able to open the Word document for viewing/editing.

    This link might have some helpful information about automating LibreOffice.

Re: Win32::OLE not support Ubuntu 14.10
by crusty_collins (Friar) on Jun 11, 2015 at 20:52 UTC
Re: Win32::OLE not support Ubuntu 14.10
by Anonymous Monk on Jun 11, 2015 at 23:06 UTC
Re: Win32::OLE not support Ubuntu 14.10
by PhillipHuang (Beadle) on Jun 12, 2015 at 02:17 UTC
    Well, thanks for your kindly suggestion . Since it is so difficult to edit Microsoft Word in Ubuntu, I think if using PDF is another way. There are some PDF modules found on CPAN already.

      I think it would be better if you explained what you're trying to do. Your first post said you wanted to find and replace some text within a Microsoft Word document. If your goal is to use some sort of template and customise it per user/customer then there are alternatives to Microsoft word. For example PDF::Reuse (see also PDF::Reuse::Tutorial). If the problem you're trying to solve is something other than this please let us know.

        I am a pre-sales technical support engineer. Nearly everyday a lot of sales call me to provide product-combination and related price. I use Perl to create a CGI page to meet the requirement. By Perl, Excel has already been created automatically, while how to get the report(used to be Word format) is my question. PS, the WORD report is based on some templates, so what I need to do is find and replace some key strings.
      PDF isn't meant to be edited. What about HTML?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1130005]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-20 03:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found