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

Hi monks i have an excel sheet in which have the following format:

For eg: Excel sheet name: Entries.pl Row A1 B1 Column A1 apple.c 123 B1 define.h 104 C1 struct.c 236 D1 math.h 256 E1 monks.pl 100

The excel sheet will have the same format for more than 1000 entries.

There are many documents (.doc) in a folder which contains the following word but the number is wrong over there...

for eg: 1.doc=> apple.c Entry No:321 monks.pl Entry No:125 2.doc=> define.h Entry No:256 struct.c ENtry No:258

I have to open each and every document manually and i have to see into excel sheet and change the entry no...Currently there are more than 1000 docs and is there any way to do it using perl ..Im not an expert in perl just now the basics ..Pls help out monks...

Replies are listed 'Best First'.
Re: Excel to Doc
by TJPride (Pilgrim) on Mar 04, 2012 at 16:41 UTC
    Docs are generally messy to work with. Is the only data inside the docs what you pasted?

    apple.c Entry No:321 monks.pl Entry No:125

    There are modules for reading docs and writing docs, but without some messy manipulation, I'm guessing the two aren't necessarily going to translate to each other without some messy code. The easiest solution would be to read the docs, convert the text, and then write out as something simpler, like plaintext or HTML or at worst, rtf. Short of that, you might consider batch converting the docs to text or rtf from MS Word itself, then batch converting them back once you're done running your script. Nothing knows how to convert docs better than MS Word, why reinvent the wheel?

    The Excel sheet is relatively simple, you can convert to CSV and then use something basic like Text::CSV to read and write it.

Re: Excel to Doc
by Anonymous Monk on Mar 04, 2012 at 18:16 UTC
    Just learn about the Visual Basic environment that is built in to every Office product. With it you can open documents of any type as objects and work with them directly as you please. There is nothing to be gained here by working outside of Microsoft's well-equipped padded cell environment... not enough of a technical challenge to warrant the trouble of not following the yellow brick road (which will indeed get you where you want to go).
Re: Excel to Doc
by Gangabass (Vicar) on Mar 05, 2012 at 10:50 UTC

    You can do this using Win32::OLE for changes in Word.

    Just read data from Excel file (with Spreadsheet::ParseExcel?). Next you need to open each *.doc file you have with Win32:OLE and make advanced search (using Word's regular expressions) for string you need (for example, monks.pl[ ]@Entry[ ]@No:[0-9]@>) and change finded string to the value you need.

    Next you need to make another search (from beginning of the document) for another Excel entry.