Word Automation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
17 messages Options
Reply | Threaded
Open this post in threaded view
|

Word Automation

Germán S. Arduino-2
Hi People:

While I'm evaluating how to develop a new version of my Biochemical
Laboratories System, I must provides to my current customers (using my old
DOS system) a way to print using Windows printing system.

I'm thinking in Word templates (Then the users may design they own
templates) that can recover the data from the dbfs of the DOS system.

I can accomplish that using VB forms from inside Word, using ODBC to access
the DBFS, but I don't likes the deployment in Office solutions, and I'm not
an expert in VBA.

I want to ask if someone has made some experience of this type with Dolphin,
and some advices or examples or ideas.

My goals are that the users can design they own and several templates using
Word (I will provides some examples to the users, of course), but the
controlling app, that read the different dbfs and build the data to the word
document (working here as a reporting tool), and build the word document
using the applicable template (user selected) be a Dolphin application.

I know already how to deal with dbfs an another databases using ODBC and
DBConnection, but I don't know much about how to deal from Dolphin with
ActiveX, dlls and another stuff needed to automate Word.

Also I must to say that I owns at the moment only DSE then want to know if a
solution as this may be deployed as a ToGo app.
(If is possible then I will try to purchase the DPRO edition).

Thanks in Advance by the help.

gsa.


Reply | Threaded
Open this post in threaded view
|

Re: Word Automation

Blair McGlashan
"Germán S. Arduino" <[hidden email]> wrote in message
news:[hidden email]...

> Hi People:
>
> While I'm evaluating how to develop a new version of my Biochemical
> Laboratories System, I must provides to my current customers (using my old
> DOS system) a way to print using Windows printing system.
>
> I'm thinking in Word templates (Then the users may design they own
> templates) that can recover the data from the dbfs of the DOS system.
>
> I can accomplish that using VB forms from inside Word, using ODBC to
access
> the DBFS, but I don't likes the deployment in Office solutions, and I'm
not
> an expert in VBA.
>
> I want to ask if someone has made some experience of this type with
Dolphin,
> and some advices or examples or ideas.
>
> My goals are that the users can design they own and several templates
using
> Word (I will provides some examples to the users, of course), but the
> controlling app, that read the different dbfs and build the data to the
word
> document (working here as a reporting tool), and build the word document
> using the applicable template (user selected) be a Dolphin application.
>
> I know already how to deal with dbfs an another databases using ODBC and
> DBConnection, but I don't know much about how to deal from Dolphin with
> ActiveX, dlls and another stuff needed to automate Word.
>

Automating Word is straightforward enough - the main difficulty you will
face is understanding the sheer volume of classes and methods in the
automation interface, and finding those bits you need to use. Of course this
is fairly well documented on MSDN, and elsewhere.

IDispatch has some class example methods that might be of interest -
example3 and example4 automate Word. These go directly through IDispatch,
which has the advantage that you don't need to generate a very large class
library, but the disadvantage that you will be working blind against the
interface using the documentation, instead of getting the normal information
about the properties and methods on objects that one is used to in
Smalltalk.

Personally I would strongly recommend using the ActiveX Component Wizard to
generate a wrapping for Word. This will produce a large number of classes
and methods, but when you deploy the application the image stripper will
make a good job of removing those that you do not need so that the eventual
deployed application will not be bloated. Given the generated methods it
will be much easier for you to use the automation interface, with the
additional benefit that performance will be better.

AXTypeLibraryAnalyzer class>>example3 shows an example of automating
Microsoft Excel through a generated interface. Normally you would drive the
analyzer through the wizard UI, rather than scripting it as in the example,
but if you compare this with the IDispatch examples I think you will see
that it is much more like working in normal Smalltalk.

> Also I must to say that I owns at the moment only DSE then want to know if
a
> solution as this may be deployed as a ToGo app.
> (If is possible then I will try to purchase the DPRO edition).
>

Certainly it is possible to deploy an application that automates Word as a
ToGo application, but of course you will still need an installation of Word
on the target machines.

Regards

Blair


Reply | Threaded
Open this post in threaded view
|

Re: Word Automation

Bill Schwab-2
In reply to this post by Germán S. Arduino-2
Germán,

There are two ways to drive Word via Automation.  You can use Dolphin's
TypeLibraryAnalyzer (via the ActiveX Component Wizard) to generate interface
classes, or you can leave it up to IDispatch, which is the method I prefer
(for Word and Excel) given the sprawling nature of Microsoft's "object
models".  The TypeLibraryAnalyzer is excellent, but its output is only as
good as the type library (and therefore IDL) given to it.

Feel free to try my Word Automation package, and if you like what you see, I
can wrap up the latest version of it for you.

Have a good one,

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Word Automation

Christopher J. Demers
In reply to this post by Germán S. Arduino-2
"Germán S. Arduino" <[hidden email]> wrote in message
news:[hidden email]...
...
> I'm thinking in Word templates (Then the users may design they own
> templates) that can recover the data from the dbfs of the DOS system.
>
> I can accomplish that using VB forms from inside Word, using ODBC to
access
> the DBFS, but I don't likes the deployment in Office solutions, and I'm
not
> an expert in VBA.
>
> I want to ask if someone has made some experience of this type with
Dolphin,
> and some advices or examples or ideas.
...

I have not done so much with Word, but rather with Excel, which is similar.
The best trick I can offer would be to record a macro in Word for anything
you are not sure how to code, and then translate the resulting VBA into
Smalltalk. I like to use the ActiveX wizard to generate classes so I can use
the built in tools (references / definitions, etc...) as well as my own code
completion tool.  You don't have to generate wrappers for all the classes,
but only the ones you need.  You can easily generate additional wrappers as
needed.  You can do a google search of this group for more information.  I
think in the latest version of Dolphin it should do a good job wrapping Word
automatically.  It used to require a little tweaking, but that may not be
needed now.

Chris


Reply | Threaded
Open this post in threaded view
|

Re: Word Automation

Germán S. Arduino-2
In reply to this post by Bill Schwab-2
Thanks Bill by your response.

>
> Feel free to try my Word Automation package, and if you like what you see,
I
> can wrap up the latest version of it for you.

Where is your Word Automation Package?.

I've searched in your web but not finded.

Regards.


Reply | Threaded
Open this post in threaded view
|

Re: Word Automation

Germán S. Arduino-2
In reply to this post by Blair McGlashan
Thanks Blair by your response.

I will try.

Regards.

"Blair McGlashan" <[hidden email]> escribió en el mensaje
news:c3a35p$26pi3p$[hidden email]...
>
> "Germán S. Arduino" <[hidden email]> wrote in message
> news:[hidden email]...
> > Hi People:
> >
> > While I'm evaluating how to develop a new version of my Biochemical
> > Laboratories System, I must provides to my current customers (using my
old

> > DOS system) a way to print using Windows printing system.
> >
> > I'm thinking in Word templates (Then the users may design they own
> > templates) that can recover the data from the dbfs of the DOS system.
> >
> > I can accomplish that using VB forms from inside Word, using ODBC to
> access
> > the DBFS, but I don't likes the deployment in Office solutions, and I'm
> not
> > an expert in VBA.
> >
> > I want to ask if someone has made some experience of this type with
> Dolphin,
> > and some advices or examples or ideas.
> >
> > My goals are that the users can design they own and several templates
> using
> > Word (I will provides some examples to the users, of course), but the
> > controlling app, that read the different dbfs and build the data to the
> word
> > document (working here as a reporting tool), and build the word document
> > using the applicable template (user selected) be a Dolphin application.
> >
> > I know already how to deal with dbfs an another databases using ODBC and
> > DBConnection, but I don't know much about how to deal from Dolphin with
> > ActiveX, dlls and another stuff needed to automate Word.
> >
>
> Automating Word is straightforward enough - the main difficulty you will
> face is understanding the sheer volume of classes and methods in the
> automation interface, and finding those bits you need to use. Of course
this
> is fairly well documented on MSDN, and elsewhere.
>
> IDispatch has some class example methods that might be of interest -
> example3 and example4 automate Word. These go directly through IDispatch,
> which has the advantage that you don't need to generate a very large class
> library, but the disadvantage that you will be working blind against the
> interface using the documentation, instead of getting the normal
information
> about the properties and methods on objects that one is used to in
> Smalltalk.
>
> Personally I would strongly recommend using the ActiveX Component Wizard
to
> generate a wrapping for Word. This will produce a large number of classes
> and methods, but when you deploy the application the image stripper will
> make a good job of removing those that you do not need so that the
eventual
> deployed application will not be bloated. Given the generated methods it
> will be much easier for you to use the automation interface, with the
> additional benefit that performance will be better.
>
> AXTypeLibraryAnalyzer class>>example3 shows an example of automating
> Microsoft Excel through a generated interface. Normally you would drive
the
> analyzer through the wizard UI, rather than scripting it as in the
example,
> but if you compare this with the IDispatch examples I think you will see
> that it is much more like working in normal Smalltalk.
>
> > Also I must to say that I owns at the moment only DSE then want to know
if
> a
> > solution as this may be deployed as a ToGo app.
> > (If is possible then I will try to purchase the DPRO edition).
> >
>
> Certainly it is possible to deploy an application that automates Word as a
> ToGo application, but of course you will still need an installation of
Word
> on the target machines.
>
> Regards
>
> Blair
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Word Automation

Bill Schwab-2
In reply to this post by Germán S. Arduino-2
Germán,

> > Feel free to try my Word Automation package, and if you like what you
see,
> I
> > can wrap up the latest version of it for you.
>
> Where is your Word Automation Package?.
>
> I've searched in your web but not finded.

Try this:

    http://needle.anest.ufl.edu/anest4/bills/BillSchwab-D5-goodies-2.zip

Let me know if you want the updated version sooner than my "when I get
bored" release schedule would place it on the web.

Have a good one,

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Word Automation

Germán S. Arduino-2
In reply to this post by Christopher J. Demers
Thanks Chris.

"Christopher J. Demers" <[hidden email]> escribió en el
mensaje news:c3aaud$25ffr9$[hidden email]...

> "Germán S. Arduino" <[hidden email]> wrote in message
> news:[hidden email]...
> ...
> > I'm thinking in Word templates (Then the users may design they own
> > templates) that can recover the data from the dbfs of the DOS system.
> >
> > I can accomplish that using VB forms from inside Word, using ODBC to
> access
> > the DBFS, but I don't likes the deployment in Office solutions, and I'm
> not
> > an expert in VBA.
> >
> > I want to ask if someone has made some experience of this type with
> Dolphin,
> > and some advices or examples or ideas.
> ...
>
> I have not done so much with Word, but rather with Excel, which is
similar.
> The best trick I can offer would be to record a macro in Word for anything
> you are not sure how to code, and then translate the resulting VBA into
> Smalltalk. I like to use the ActiveX wizard to generate classes so I can
use
> the built in tools (references / definitions, etc...) as well as my own
code
> completion tool.  You don't have to generate wrappers for all the classes,
> but only the ones you need.  You can easily generate additional wrappers
as
> needed.  You can do a google search of this group for more information.  I
> think in the latest version of Dolphin it should do a good job wrapping
Word
> automatically.  It used to require a little tweaking, but that may not be
> needed now.
>
> Chris
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Word Automation

Germán S. Arduino-2
In reply to this post by Bill Schwab-2
Hi again Bill:

> Try this:
>
>     http://needle.anest.ufl.edu/anest4/bills/BillSchwab-D5-goodies-2.zip
>

Yes, it's ok now, WordAutomation.pac is here.

> Let me know if you want the updated version sooner than my "when I get
> bored" release schedule would place it on the web.

What means an "update version", is something wrong with this version? May be
the cause of my next questions?

a) When I try WordAutomation example2 the word document is showed in the
desktop only a very very short time and next dissapear. I imagine that the
document says 'Did it work?' but can't be sure, because Word don't be at
screen.

b) When I try WordAutomation fileName:'Hemograma.doc' then I get some
errors:

IDispatch>>invokeId:flags:parms:retVal:
IDispatch>>invokeId:flags:parms:
IDispatch>>invoke:with:
WordAutomation>>start:
WordAutomation class>>fileName:
UndefinedObject>>{unbound}doIt
CompiledExpression>>value:
SmalltalkWorkspace>>evaluateRange:ifFail:debug:
SmalltalkWorkspace>>evaluateRange:ifFail:
SmalltalkWorkspace>>displayIt

I'm trying with Win XP Prof. Edition and Word 2002 SP1.

c) My final goal would be to have several Word templates (for a Biochemical
Laboratory) with, by example, titles as "Hemograma" (a group of blood
determinations), with his determinations.

The determinations could be things composed of fixed text as: "Red Blood
Cell", "White Blood Cell" and his values. The values are in the databases of
my current DOS app, then my Dolphin app would by capable of retrieve these
values and fill the word template in the appropriates fields on the Word
document.

Then the user can customize the titles and fixed texts using fonts, colors,
also configure paper size, all using Word and my app only must to retrieve
the data from the databases and fill the fields in the word templates. That
could be possible with your package? or must be extended?.

Thanks in Advance by the help.

Regards.

---
Germán S. Arduino
http://www.arsol.biz


Reply | Threaded
Open this post in threaded view
|

Re: Word Automation

Bill Schwab-2
Germán,

> Yes, it's ok now, WordAutomation.pac is here.
>
> > Let me know if you want the updated version sooner than my "when I get
> > bored" release schedule would place it on the web.
>
> What means an "update version", is something wrong with this version? May
be
> the cause of my next questions?

I mention it only because I did some work on the package a few months ago,
and some of those additions might be useful to you.


> a) When I try WordAutomation example2 the word document is showed in the
> desktop only a very very short time and next dissapear. I imagine that the
> document says 'Did it work?' but can't be sure, because Word don't be at
> screen.

Inspect the WordAutomation instance; otherwise, it gets finalized, and
closes word.


> b) When I try WordAutomation fileName:'Hemograma.doc' then I get some
> errors:
>
> IDispatch>>invokeId:flags:parms:retVal:
> IDispatch>>invokeId:flags:parms:
> IDispatch>>invoke:with:
> WordAutomation>>start:
> WordAutomation class>>fileName:
> UndefinedObject>>{unbound}doIt
> CompiledExpression>>value:
> SmalltalkWorkspace>>evaluateRange:ifFail:debug:
> SmalltalkWorkspace>>evaluateRange:ifFail:
> SmalltalkWorkspace>>displayIt
>
> I'm trying with Win XP Prof. Edition and Word 2002 SP1.

A quick check with Ian's chunk browser suggests that this is one of the
things that changed.  An updated package will appear shortly.


> c) My final goal would be to have several Word templates (for a
Biochemical
> Laboratory) with, by example, titles as "Hemograma" (a group of blood
> determinations), with his determinations.

If you can say "documents" then it should be very easy.  If you want to load
templates into a common blank document, then I will yield to others.


> The determinations could be things composed of fixed text as: "Red Blood
> Cell", "White Blood Cell" and his values. The values are in the databases
of
> my current DOS app, then my Dolphin app would by capable of retrieve these
> values and fill the word template in the appropriates fields on the Word
> document.
>
> Then the user can customize the titles and fixed texts using fonts,
colors,
> also configure paper size, all using Word and my app only must to retrieve
> the data from the databases and fill the fields in the word templates.
That
> could be possible with your package? or must be extended?.

I think it will work.  As I hinted above, I would simply create blank
documents (a similar problem lead me to create the package) rather than
templates.  I found Word to be quite particular about the exact sequence of
operations.  Some things work as one would expect, others do not.

What do you mean by "fields"?  I have dropped things into tables, but have
never found need for fields themselves, though I suspect it would be a
relatively simple extension.  If you decide to pursue it, please feel free
to ask for help, and please share the result with us; I would like to extend
my released package accordingly.

Have a good one,

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Word Automation

Bill Schwab-2
Germán,

Please try

  http://needle.anest.ufl.edu/anest4/bills/WordAutomation3-04.zip

It might fix your problem loading existing files - please let me know if it
does not.

Have a good one,

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Word Automation

Germán S. Arduino-2
In reply to this post by Bill Schwab-2
Hi Bill:

>
> I mention it only because I did some work on the package a few months ago,
> and some of those additions might be useful to you.
>

Ah!, ok, of course I'm interested in know these new features.
(Sorry if my English isn't so good and I must says or ask more than once the
things).

>
> > a) When I try WordAutomation example2 the word document is showed in the
> > desktop only a very very short time and next dissapear. I imagine that
the
> > document says 'Did it work?' but can't be sure, because Word don't be at
> > screen.
>
> Inspect the WordAutomation instance; otherwise, it gets finalized, and
> closes word.
>

ok, works now, but in a ToGo app, how is supposed work this feature? I need
that the resulting word doc be at screen showing the template with the value
of fields retrieved from the db and the fixed text of the template.

>
> A quick check with Ian's chunk browser suggests that this is one of the
> things that changed.  An updated package will appear shortly.
>

You means an updated WordAutomation package?

>
> > c) My final goal would be to have several Word templates (for a
> Biochemical
> > Laboratory) with, by example, titles as "Hemograma" (a group of blood
> > determinations), with his determinations.
>
> If you can say "documents" then it should be very easy.  If you want to
load
> templates into a common blank document, then I will yield to others.
>

I'm not sure of understand what you want to say, but yes, I want to load
templates (selected by the user o the dolphin app itself) into a common
blank document.

>
> I think it will work.  As I hinted above, I would simply create blank
> documents (a similar problem lead me to create the package) rather than
> templates.  I found Word to be quite particular about the exact sequence
of
> operations.  Some things work as one would expect, others do not.
>
> What do you mean by "fields"?  I have dropped things into tables, but have
> never found need for fields themselves,

I means, by example, the template says:

Type of Analysis: field1
Dr:                       field2
Protocol Number: filed3

Red Blood Cell:         field4
White Blood Cell:      filed5

Then the user that must to print that analysis enter in the dolphin app the
protocol number (is a unique key in my current databases). The dolphin app
search the results for this protocol number and bring up a new word document
with this template type (based in the analysis type) and fill the fields
(1-2-3-4-5) with the data retrieved from the dbfs, resulting in a thing like
this:

Type of Analysis: Hemograma
Dr: Frankestein
Protocol Number: 100199

Red Blood Cell:    4.500.000
White Blood Cell:        5.000


> though I suspect it would be a
> relatively simple extension.  If you decide to pursue it, please feel free
> to ask for help, and please share the result with us; I would like to
extend
> my released package accordingly.

I'm evaluating yet, but I'm very convinced that is the best manner of let
the users of my app configure and customize the printed reports of the
analysis of his laboratories and let myself concentrating only in the
functionality of the app and not in things as fonts, color, titles, paper
sizes and so.

I hope to be clair with my explanation and my intentions.

Regards.

Germán.





>
> Have a good one,
>
> Bill
>
> --
> Wilhelm K. Schwab, Ph.D.
> [hidden email]
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Word Automation

Germán S. Arduino-2
In reply to this post by Bill Schwab-2
Bill:

The url seems not responding.

Germán.

"Bill Schwab" <[hidden email]> escribió en el mensaje
news:c3d3k9$lei$[hidden email]...
> Germán,
>
> Please try
>
>   http://needle.anest.ufl.edu/anest4/bills/WordAutomation3-04.zip
>
> It might fix your problem loading existing files - please let me know if
it

> does not.
>
> Have a good one,
>
> Bill
>
> --
> Wilhelm K. Schwab, Ph.D.
> [hidden email]
>


Reply | Threaded
Open this post in threaded view
|

Re: Word Automation

Bill Schwab-2
In reply to this post by Germán S. Arduino-2
Germán,

> ok, works now, but in a ToGo app, how is supposed work this feature? I
need
> that the resulting word doc be at screen showing the template with the
value
> of fields retrieved from the db and the fixed text of the template.

I think the answer to your question is to simply hold a reference to the
WordAutomation instance so it won't be finalized.


> I'm not sure of understand what you want to say, but yes, I want to load
> templates (selected by the user o the dolphin app itself) into a common
> blank document.

IMHO, Word's handling of templates is hard enough to handle from the UI, so
would hesitate to try to program it.  However, you are encouraged to prove
me wrong, and to send me the code to make it work :)


> > I think it will work.  As I hinted above, I would simply create blank
> > documents (a similar problem lead me to create the package) rather than
> > templates.  I found Word to be quite particular about the exact sequence
> of
> > operations.  Some things work as one would expect, others do not.
> >
> > What do you mean by "fields"?  I have dropped things into tables, but
have

> > never found need for fields themselves,
>
> I means, by example, the template says:
>
> Type of Analysis: field1
> Dr:                       field2
> Protocol Number: filed3
>
> Red Blood Cell:         field4
> White Blood Cell:      filed5

I _assume_ the fields can be accessed through an Automation collection, and
you can probably get to them directly.  Failing that, you could use a table,
and find the cells by the label next to field.


> Then the user that must to print that analysis enter in the dolphin app
the
> protocol number (is a unique key in my current databases). The dolphin app
> search the results for this protocol number and bring up a new word
document
> with this template type (based in the analysis type) and fill the fields
> (1-2-3-4-5) with the data retrieved from the dbfs, resulting in a thing
like
> this:
>
> Type of Analysis: Hemograma
> Dr: Frankestein
> Protocol Number: 100199
>
> Red Blood Cell:    4.500.000
> White Blood Cell:        5.000

You should be able to make that work.  Again, I question whether a template
is the correct mechanism (and whether it is sufficiently flexible and
robust), but the basic idea will work.



> I'm evaluating yet, but I'm very convinced that is the best manner of let
> the users of my app configure and customize the printed reports of the
> analysis of his laboratories and let myself concentrating only in the
> functionality of the app and not in things as fonts, color, titles, paper
> sizes and so.

It makes sense.  While in no way intended to discourage you, I want to
suggest that you set some priorities for what you need to make the project
succeed, and then things that would be nice if they happen to work.
Unfortunately, Automation servers (and Word will play that part) tend to be
black boxes that often give ambiguous, and sometimes misleading, error
messages..

When I use Automation, it's usually for a temporary solution, so I tend to
compromise early and put my energy into a smaller/faster/better result that
will be easier to maintain and install.  It also helps (sometimes) to get
your users to agree on what really matters (color might not be important, or
maybe they can agree on how it should look??) so that all involved can
sooner get back to real work.


> The url seems not responding.

It works for me, though I find that IE will not proceed to save-as if I
paste it into the address field.  I wouldn't mind except that it blames it
on the server rather than informing me that my request is invalid.  If that
is your problem, click on the Smalltalk Balloon, then look for WORD
AUTOMATION UPDATE on the Smalltalk page.  Of course there is alway the
possibility that the server was down when you tried to get the file.

FWIW, I have been having many problems with IE's caching of late, to the
point that I now have an HTTP client within easy reach inside my Dolphin
image.  For casual use, you can use the URL moniker library (see Dolphin's
Live Update to get started) to download and save files.  There is also an
extensive Smalltalk-based HTTP client (courtesy of Steve Waring???) that you
can download if you wish.

Have a good one,

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Word Automation

Christopher J. Demers
In reply to this post by Germán S. Arduino-2
"Germán S. Arduino" <[hidden email]> wrote in message
news:[hidden email]...
...

> > > c) My final goal would be to have several Word templates (for a
> > Biochemical
> > > Laboratory) with, by example, titles as "Hemograma" (a group of blood
> > > determinations), with his determinations.
> >
> > If you can say "documents" then it should be very easy.  If you want to
> load
> > templates into a common blank document, then I will yield to others.
>
> I'm not sure of understand what you want to say, but yes, I want to load
> templates (selected by the user o the dolphin app itself) into a common
> blank document.
...

I think the code bellow will show portions of what you might want to do.  It
will create a new document based on a template (*.dot file).  It will then
use the replace functionality of Word to replace a "field" name with a new
text value.  There may be a way to use some kind of actual field objects in
Word, you will have to research that further.  My approach bellow was just
to enter text with special names for the fields, escaped between some
character unlikely to straddle a non-token in the normal text.  The next
thing you wanted to do was to merge multiple reports into one document.  My
code does not demonstrate that.  It should not be hard to do.  If in doubt
just record a macro in Word while you do what you want manually and then
translate it into Smalltalk, that is how I got the code bellow.  You can
probably just copy everything from the component documents into the fine
common document, inserting page breaks where needed.

The code bellow is not exactly pretty.  Some of Word's functions take a lot
of arguments.  I did not see an obvious way to specify named arguments.  If
there were a way to do that it would make the code much cleaner.  I normally
generate the classes with the ActiveX wizard, which also might make the code
look a little cleaner.  I did not do that in this case since this is just an
example.

=================
"Create a Word application."
word := IDispatch createObject: 'Word.Application'.
word setProperty: 'Visible' value: true.
docs := word getProperty: 'Documents'.
"Open the document from a template."
newDoc := docs invoke: 'Add' withArguments: #('C:\Documents and
Settings\cdemers\Application Data\Microsoft\Templates\FieldTest.dot' false 0
true).
find := (word getProperty: 'Selection') getProperty: 'Find'.
"Replace the field name with the field contents. This could be done for many
fields."
find invoke: 'Execute' withArguments: (OrderedCollection new add:
'[FieldName1]'; add: true; add: true; add: false; add: false; add: false;
add: true; add: 1; add: VARIANT unspecified; add: 'New Text'; add: 2
"Repalce all"; add: VARIANT unspecified; add: VARIANT unspecified; add:
VARIANT unspecified; add: VARIANT unspecified; yourself).
=================

Chris


Reply | Threaded
Open this post in threaded view
|

Re: Word Automation

Germán S. Arduino-2
Thanks Chris by the example.

"Christopher J. Demers" <[hidden email]> escribió en el
mensaje news:c3dipa$26qi7r$[hidden email]...
> "Germán S. Arduino" <[hidden email]> wrote in message
> news:[hidden email]...
> ...
> > > > c) My final goal would be to have several Word templates (for a
> > > Biochemical
> > > > Laboratory) with, by example, titles as "Hemograma" (a group of
blood
> > > > determinations), with his determinations.
> > >
> > > If you can say "documents" then it should be very easy.  If you want
to
> > load
> > > templates into a common blank document, then I will yield to others.
> >
> > I'm not sure of understand what you want to say, but yes, I want to load
> > templates (selected by the user o the dolphin app itself) into a common
> > blank document.
> ...
>
> I think the code bellow will show portions of what you might want to do.
It
> will create a new document based on a template (*.dot file).  It will then
> use the replace functionality of Word to replace a "field" name with a new
> text value.  There may be a way to use some kind of actual field objects
in
> Word, you will have to research that further.  My approach bellow was just
> to enter text with special names for the fields, escaped between some
> character unlikely to straddle a non-token in the normal text.  The next
> thing you wanted to do was to merge multiple reports into one document.
My
> code does not demonstrate that.  It should not be hard to do.  If in doubt
> just record a macro in Word while you do what you want manually and then
> translate it into Smalltalk, that is how I got the code bellow.  You can
> probably just copy everything from the component documents into the fine
> common document, inserting page breaks where needed.
>
> The code bellow is not exactly pretty.  Some of Word's functions take a
lot
> of arguments.  I did not see an obvious way to specify named arguments.
If
> there were a way to do that it would make the code much cleaner.  I
normally
> generate the classes with the ActiveX wizard, which also might make the
code
> look a little cleaner.  I did not do that in this case since this is just
an

> example.
>
> =================
> "Create a Word application."
> word := IDispatch createObject: 'Word.Application'.
> word setProperty: 'Visible' value: true.
> docs := word getProperty: 'Documents'.
> "Open the document from a template."
> newDoc := docs invoke: 'Add' withArguments: #('C:\Documents and
> Settings\cdemers\Application Data\Microsoft\Templates\FieldTest.dot' false
0
> true).
> find := (word getProperty: 'Selection') getProperty: 'Find'.
> "Replace the field name with the field contents. This could be done for
many

> fields."
> find invoke: 'Execute' withArguments: (OrderedCollection new add:
> '[FieldName1]'; add: true; add: true; add: false; add: false; add: false;
> add: true; add: 1; add: VARIANT unspecified; add: 'New Text'; add: 2
> "Repalce all"; add: VARIANT unspecified; add: VARIANT unspecified; add:
> VARIANT unspecified; add: VARIANT unspecified; yourself).
> =================
>
> Chris
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Word Automation

Germán S. Arduino-2
In reply to this post by Bill Schwab-2
Hi Bill, Thanks by your advices.

The url is working now.

Thanks Again.

Germán.

"Bill Schwab" <[hidden email]> escribió en el mensaje
news:c3dc4o$rhe$[hidden email]...

> Germán,
>
> > ok, works now, but in a ToGo app, how is supposed work this feature? I
> need
> > that the resulting word doc be at screen showing the template with the
> value
> > of fields retrieved from the db and the fixed text of the template.
>
> I think the answer to your question is to simply hold a reference to the
> WordAutomation instance so it won't be finalized.
>
>
> > I'm not sure of understand what you want to say, but yes, I want to load
> > templates (selected by the user o the dolphin app itself) into a common
> > blank document.
>
> IMHO, Word's handling of templates is hard enough to handle from the UI,
so
> would hesitate to try to program it.  However, you are encouraged to prove
> me wrong, and to send me the code to make it work :)
>
>
> > > I think it will work.  As I hinted above, I would simply create blank
> > > documents (a similar problem lead me to create the package) rather
than
> > > templates.  I found Word to be quite particular about the exact
sequence

> > of
> > > operations.  Some things work as one would expect, others do not.
> > >
> > > What do you mean by "fields"?  I have dropped things into tables, but
> have
> > > never found need for fields themselves,
> >
> > I means, by example, the template says:
> >
> > Type of Analysis: field1
> > Dr:                       field2
> > Protocol Number: filed3
> >
> > Red Blood Cell:         field4
> > White Blood Cell:      filed5
>
> I _assume_ the fields can be accessed through an Automation collection,
and
> you can probably get to them directly.  Failing that, you could use a
table,
> and find the cells by the label next to field.
>
>
> > Then the user that must to print that analysis enter in the dolphin app
> the
> > protocol number (is a unique key in my current databases). The dolphin
app

> > search the results for this protocol number and bring up a new word
> document
> > with this template type (based in the analysis type) and fill the fields
> > (1-2-3-4-5) with the data retrieved from the dbfs, resulting in a thing
> like
> > this:
> >
> > Type of Analysis: Hemograma
> > Dr: Frankestein
> > Protocol Number: 100199
> >
> > Red Blood Cell:    4.500.000
> > White Blood Cell:        5.000
>
> You should be able to make that work.  Again, I question whether a
template
> is the correct mechanism (and whether it is sufficiently flexible and
> robust), but the basic idea will work.
>
>
>
> > I'm evaluating yet, but I'm very convinced that is the best manner of
let
> > the users of my app configure and customize the printed reports of the
> > analysis of his laboratories and let myself concentrating only in the
> > functionality of the app and not in things as fonts, color, titles,
paper
> > sizes and so.
>
> It makes sense.  While in no way intended to discourage you, I want to
> suggest that you set some priorities for what you need to make the project
> succeed, and then things that would be nice if they happen to work.
> Unfortunately, Automation servers (and Word will play that part) tend to
be
> black boxes that often give ambiguous, and sometimes misleading, error
> messages..
>
> When I use Automation, it's usually for a temporary solution, so I tend to
> compromise early and put my energy into a smaller/faster/better result
that
> will be easier to maintain and install.  It also helps (sometimes) to get
> your users to agree on what really matters (color might not be important,
or
> maybe they can agree on how it should look??) so that all involved can
> sooner get back to real work.
>
>
> > The url seems not responding.
>
> It works for me, though I find that IE will not proceed to save-as if I
> paste it into the address field.  I wouldn't mind except that it blames it
> on the server rather than informing me that my request is invalid.  If
that
> is your problem, click on the Smalltalk Balloon, then look for WORD
> AUTOMATION UPDATE on the Smalltalk page.  Of course there is alway the
> possibility that the server was down when you tried to get the file.
>
> FWIW, I have been having many problems with IE's caching of late, to the
> point that I now have an HTTP client within easy reach inside my Dolphin
> image.  For casual use, you can use the URL moniker library (see Dolphin's
> Live Update to get started) to download and save files.  There is also an
> extensive Smalltalk-based HTTP client (courtesy of Steve Waring???) that
you

> can download if you wish.
>
> Have a good one,
>
> Bill
>
> --
> Wilhelm K. Schwab, Ph.D.
> [hidden email]
>
>
>