Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tcl/tcom, microsoft word and sql

Status
Not open for further replies.

daisy4u721

Programmer
Aug 24, 2009
34
US
I have a code that creates a MS word file with tables using tcom package. I am trying to insert some text from sql database into the columns and rows, ive being trying different codes and its doesnt seem to work, any help please? The code is below:

This code creates a 3 rows and 3 columns table

Code:
package require tcom
set application [::tcom::ref createobject "Word.Application"]
$application Visible 1
$application DisplayAlerts 0
set docs [$application Documents]
set doc [$docs Add  ]
set unit 12
[$doc Tables] Add  [[$application Selection] Range]  [set NumRows  3] [set NumColumns  3]
[$::application Selection] TypeText "Title"
[$::application Selection] MoveRight $unit 1
[$::application Selection] TypeText "Date"
[$::application Selection] MoveRight $unit 1
[$::application Selection] TypeText "Number"
[$::application Selection] MoveRight $unit 1

What im trying to do is insert text from sql under title and i tried this code but its giving me a "TYPE Mismatch" error.

Code:
set query "Select title From table"
set foo [sql $query]
[$::application Selection] TypeText "$foo"

Does anyone have any idea why its giving me this error?
Any help will be appreciated. I have been on this for the past 2 weeks.

Thanks.

 
Where do you tell sql what database to query?

_________________
Bob Rashkin
 
I have that i did not just type it in my question.

I mean it can access sql and output anything right but it wont just insert it in the word table.

for example, if i type

puts $foo, it will output it right.

but if i type

[$::application Selection] TypeText "$foo" it gives me a "type mismatch" error

 
I just figured something out now.

if i insert a "\n" or a "letter" before the $foo, like this:

[$::application Selection] TypeText "\n$foo" or
[$::application Selection] TypeText "a$foo"

it works with a "space" and "a" before it.... wierd!

but i can work with that.


Thanks for you help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top