Monday, August 27, 2012

Word

Getting back into some Word and Excel automation for a programming task, and it has once again become painfully obvious that the state of automation of Office software is incredibly antiquated.

So: a real Perl OO wrapper for Word (and for Excel, but of course I know Excel in far less detail) would be a valuable thing, and could easily be factored out of my earlier Decl work with Word.  (And of course used by it, once I figure out that bug.)

This could easily be generalized to an OLE wrapper class as well that could be done in a more declarative way, but compiled.

This sort of thing would be incredibly useful in my daily life, and it's clear now that coming at it from the Decl end was a diversion.  I got excited about Decl and wanted to do all my programming there, but I should have been working directly in Perl.

Honestly - just a good documentation of the Word object model that didn't depend on Word's own help system would be a step forward.  (It's just that it's huge.)

Decisions:
  1. Call the class Win32::Word.
  2. I'm chickening out and not using Moose.  I still feel uncomfortable about the overhead, which is probably just me being old.
  3. I will, however, use the same declarative approach for OLE wrapping that Moose does, with the same syntactic sugar function trick.
Here's a neat idea I thought of, incidentally - search Github (and other sources of code) for instances of function/method/variable names (come to think of it, the constants would be a good thing to search on!) unique to the Word API.  That should net me a nice library of use cases, both for unit testing and for a nice cookbook.

Let's face it - Word automation sucks incredibly, it really does.  But it wouldn't have to.

Win32::OLE::Word should be the thin API, but I think something like Win32::OLE::Word::Sugar could include some significant simplifications and extensions to deal with common use cases (like searching for things in multiple stories).

No comments:

Post a Comment