On Sat, 9 Jan 2010 07:12:18 -0800 (PST), ""
<> declaimed the following in
gmane.comp.python.general:
> Hi.
> Im very new with python. I have got some answer on my issue to use
> interop or COM ''plugins'' to access MS Word through python but i
> don't even know what those two ''plugins'' are so I cannot use them.
> What I want to do is the following:
>
For Word documents, you WILL have to use such (on Windows the win32
extension library gives you the needed interfaces -- though I've not
used them myself [figuring out how to do what you want using the VBA
built into Word is difficult enough, and that IS pretty much the COM
interface]). Possibly the ctypes module will also give you said
access...
>
> What I would like to have is moved the entire (but really all of the
> text, must be 100% all) text into the .doc file with the highest ( ! )
> number. The target .doc files will always start with ''HD'' and always
> be similar to above examples.
> It is possible that the doc file (target file) is only one, so only
> HD1.doc. Therefore ''1'' is the maximum number and the text is moved
> into this file.
> Sometimes the target file is empty but usually won't be. If it won't
> be then the text should be moved to the end of the text, into first
> new line (no empty lines inbetween).
> So for example in the target file which has the maximum number in its
> name is the following text:
<snip>
> Could someone tell me please how to do this?
>
How familiar with Python are you?
I'd prototype this using plain text files first, avoiding any usage
of COM/Word access -- just plain file and directory operations.
After you have verified all conditions (destination file exists,
moving to end of contents, reading source file, writing data to
destination -- note that whether the destination contains data or not is
not relevant, you are appending the source text to the /end/ of whatever
is in the destination) are functioning properly THEN study the Word COM
model and replace the file open/close/read/write operations with Word
COM operations to do the same thing. The directory operations to find
the destination file are not Word or COM related and won't change.
The Word COM model is not something you will find documents for in
Python (not even the win32 module docs cover specifics of individual
applications).
--
Wulfraed Dennis Lee Bieber KD6MOG
HTTP://wlfraed.home.netcom.com/