473,385 Members | 1,341 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

passing the return caharacter to word

Howdy there
I have the below code
<code>
import win32com.client,pythoncom
pythoncom.CoInitializeEx(pythoncom.COINIT_APARTMEN TTHREADED)
wordapp = win32com.client.Dispatch("Word.Application") # Create new Word Object
wordapp.Visible = 1 # Word Application should`t be visible
worddoc = wordapp.Documents.Add() # Create new Document Object
worddoc.Content.Text = "=rand(200,99)"+"/r"
worddoc.Content.MoveEnd
worddoc.SaveAs("c:\wiggle.doc")
worddoc.Close() # Close the Word Document (a save-Dialog pops up)
wordapp.Quit() # Close t
pythoncom.CoUninitialize()
</code>

the problem i have is that it
saves the word doc with "=rand(200,99)/r"
i think that i am expecting too much from the com or word to action this statement in word.
as pressing return after =rand(x,x) gives you "The quick brown fox jumps over the lazy dog." quite a few times :D hence filling up a document for testing purposes...

D2
May 9 '08 #1
1 1425
jlm699
314 100+
I'm pretty sure that in Windows the "return" character that you speak of is \r\n. You could alternately use os.linesep to return the end of line character for your OS. Also, C:\wiggle.doc I think should be C:\\wiggle.doc since \ is the escape character in Python. And when you say that visible = 1 should make the application non-visible that is a lie. visible =0 would be invisible, visible = 1 is visible.

Also, for your code tags use [ ] square brackets... you were close! ;)j
Also also, your opening code tag can read code=python to get syntax highlighting!

P.S. I tried your code and had no luck getting Word to automatically generate the text... I think the problem lies within auto completion; however I've never messed with Office com objects before so who knows...

Your code only slightly modified:
Expand|Select|Wrap|Line Numbers
  1. import os, win32com.client, pythoncom
  2. pythoncom.CoInitializeEx(pythoncom.COINIT_APARTMENTTHREADED)
  3. wordapp = win32com.client.Dispatch("Word.Application")
  4. wordapp.Visible = 1
  5. worddoc = wordapp.Documents.Add()
  6. worddoc.Content.Text="=rand(200,99)" + os.linesep
  7. worddoc.Content.MoveEnd()
  8. worddoc.SaveAs("C:\\wiggle.doc")
  9. worddoc.Close()
  10. wordapp.Quit()
  11. pythoncom.CoUninitialize()
  12.  
May 9 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: J. Campbell | last post by:
Suppose I have an object that is concatinatable (sp) using the '+' operator (eg string). I have a function(func)that will do some work to the object and return an int. For several reasons it is...
5
by: Active8 | last post by:
vector<double> signal; vector<double>::iterator iter; in_file.load_vector(signal); in_file.load_vector(signal.begin()); those calls give the compiler error: "could not deduce template...
2
by: Holger Butschek | last post by:
Hi folks, first of all, I'm absolutly new to javascript. I have designed a html-form and am trying to path parameters with the suffix of i.e. ?Seminartitel=hallowelt in the url. In the head...
0
by: Neelima Godugu | last post by:
Hi All, I have developed a windows forms user control, which I am going to host in Internet Explorer.. I am familiar with the security settings requirement inorder to do the above. I have...
5
by: Sakharam Phapale | last post by:
Hi All, I am using an API function, which takes file path as an input. When file path contains special characters (@,#,$,%,&,^, etc), API function gives an error as "Unable to open input file"....
5
by: nickm687 | last post by:
Hi i have this code below and i need to modify it so i can pass more than one text file to it. any ideas? i am new to this. thanks in advance. Nick int main(int argc, char *argv) { FILE *f;...
13
by: masso600 | last post by:
char word; in = fopen("test.txt", "r"); while(fscanf(in,"%s",&word)!=EOF) { /* Print all words */ /* printf("%s\n",&word); */
16
by: krreks | last post by:
I'm trying to pass this array char files; like this if(fillFileArr(&(files), &(buf), num)==-1) return -1; to this function
4
by: arnuld | last post by:
I am passing an array of struct to a function to print its value. First I am getting Segfaults and weired values. 2nd, is there any elegant way to do this ? /* Learning how to use an array...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.