>Does SaveAs save the doc to a txt file? What I was thinking is
>"app.Documents.Open('D:/projects/Myself/HelloPython/src/Drugreservoir1.
txt')" can
>open the txt file which I can read. Is there any way I can read the
saved txt file after
>SaveAs...
Yes of course, you can use the ordinary Python
cool_go_blue wrote:
> THanks. After replying to your email, I thought about what you wrote,
> just like what you said in the following email. So, for a normal text
> file, just use open to read the file. There is no need to use the way
> to open a word document via win32com to read a text file. Wil
time and memory to
read a text file than the general input stream? Thanks again.
--- On Wed, 6/15/11, Tim Roberts wrote:
From: Tim Roberts
Subject: Re: [python-win32] UnicodeEncodingError when print a doc file
To: "Python-Win32 List"
Date: Wednesday, June 15, 2011, 7:52 PM
cool_go_
cool_go_blue wrote:
> So, my following code:
>
> app = win32com.client.gencache.EnsureDispatch('Word.Application')
> app.Documents.Open(r'D:/projects/Myself/HelloPython/src/Drugreservoir.doc')
> app.ActiveDocument.SaveAs(r'D:/projects/Myself/HelloPython/src/Drugreservoir1.txt',FileFormat=win32com.c
is
"app.Documents.Open('D:/projects/Myself/HelloPython/src/Drugreservoir1.txt')"
can open the txt file which I can read. Is there any way I can read the saved
txt file after SaveAs...
--- On Wed, 6/15/11, Tim Roberts wrote:
From: Tim Roberts
Subject: Re: [python-win32] Uni
cool_go_blue wrote:
> Thank you so much. It works. But where can I find the APIs such as
> Dispatch vs gencache.EnsureDispatch?
>
To a certain extent, this comes from on-the-job experience. It is
described in the win32com documentation. There's also a couple of books
on Python in Windows ("Pytho
replace").split():
print word
count += 1
print "total word: " , count
It works for the manual saved txt file.
--- On Wed, 6/15/11, Tim Roberts wrote:
From: Tim Roberts
Subject: Re: [python-win32] UnicodeEncodingError when print a doc file
To: "Python-Win32 List"
cool_go_blue wrote:
> this is the first three lines of my code:
>
> app = win32com.client.Dispatch('Word.Application')
> app.Documents.Open('D:\projects\Myself\HelloPython\src\Drugreservoir.doc')
> app.ActiveDocument.SaveAs('D:\projects\Myself\HelloPython\src\Drugreservoir1.txt',FileFormat=win32com
cool_go_blue wrote:
> I did try the one you suggest. But I got:
>
> File "D:\projects\Myself\MySVD\src\ReadWord.py", line 11, in
>
> app.ActiveDocument.SaveAs('D:\projects\Myself\HelloPython\src\Drugreservoir1.txt',FileFormat=win32com.client.constants.wdFormatText)
> File
> "D:\Softwares\P
ython27\lib\site-packages\win32com\client\__init__.py",
line 170, in __getattr__
raise AttributeError(a)
AttributeError: wdFormatText
Also I replace wdFormatText with wdFormatTextLineBreaks. Same error...
--- On Wed, 6/15/11, Tim Golden wrote:
From: Tim Golden
Subject: Re: [python-win32] U
On 15/06/2011 15:30, Tom Hawkins wrote:
By ‘manually’ I mean choosing the File->Save As menu item and changing
‘Save as type’ to Plain Text.
I’m not familiar with how to automate it directly from Python, but in
Word VBA you would use something like:
ActiveDocument.SaveAs FileName:="myfile.txt",
. But what API should I use to read all words and the
auto-number of this paragraph. It seems a huge table in each object map. Thanks.
-- On Tue, 6/14/11, Preston Landers wrote
From: Preston Landers
Subject: Re: [python-win32] UnicodeEncodingError when print a doc file
To: "cool_go_blue
By 'manually' I mean choosing the File->Save As menu item and changing
'Save as type' to Plain Text.
I'm not familiar with how to automate it directly from Python, but in
Word VBA you would use something like:
ActiveDocument.SaveAs FileName:="myfile.txt",
FileFormat:=wdFormatText
I think you'll have to get into the guts of the Document object to do things
like that. Here's the official Word 2007 object model documentation. Any
tutorials or examples you can find that use other languages like C# or
VB.NET would be relevant, you just have to translate them a bit to Python.
T
-win32] UnicodeEncodingError when print a doc file
To: "python-win32@python.org"
Date: Tuesday, June 14, 2011, 9:02 PM
cool_go_blue wrote:
> Thanks. It works. Actually, what I want to do is to parse the whole
> document. How can I retrieve the list of words in the
> document? I use
cool_go_blue wrote:
> Thanks. It works. Actually, what I want to do is to parse the whole
> document. How can I retrieve the list of words in the
> document? I use the following code:
>
> for word in doc.Content.Text.encode("cp1252", "replace"):
> print word
>
> It seems that word is each a cha
ow can I find API to process words in
an open word document. Thanks.
--- On Tue, 6/14/11, Preston Landers wrote:
From: Preston Landers
Subject: Re: [python-win32] UnicodeEncodingError when print a doc file
To: "cool_go_blue"
Date: Tuesday, June 14, 2011, 12:37 PM
The document contains
cool_go_blue wrote:
> I try to read a word document as follows:
>
> app = win32com.client.Dispatch('Word.Application')
> doc = app.Documents.Open('D:\myfile.doc')
> print doc.Content.Text
>
> I receive the following error:
>
> raceback (most recent call last):
> File "D:\projects\Myself\MySVD\src
I try to read a word document as follows:
app = win32com.client.Dispatch('Word.Application')
doc = app.Documents.Open('D:\myfile.doc')
print doc.Content.Text
I receive the following error:
raceback (most recent call last):
File "D:\projects\Myself\MySVD\src\ReadWord.py",
19 matches
Mail list logo