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!

How to create a table with columns and rows

Status
Not open for further replies.

daisy4u721

Programmer
Aug 24, 2009
34
US
Does anyone have an idea on how to create a table with columns and rows using tcl.

Any information or idea would be appreciated.

Thanks
 
Do you have any objection to using the TkTable library? I'm sure it's advanced since I last used it but it was and is a pretty slick implementation.

You need to load the Tktable library:
load tktable.dll
Then it depends on how you have your window configured. In my case I had a grid of frames so in the 2nd frame of the 2nd frame:
Code:
set w .2.2
table $w.t -yscrollcommand "$w.yscr set" -xscrollcommand "$w.xscr set"
scrollbar $w.yscr -command "$w.t yview"
scrollbar $w.xscr -command "$w.t xview" -orient horizontal
pack $w.yscr -side right -fill y
pack $w.t -side top
pack $w.xscr -side top -fill x
$w.t configure -variable m1 -bg white -width 12 -height 8
$w.t configure -rows $i1 -titlerows 1
$w.t configure -cols 5 -colwidth 16
Note the line: $w.t configure -variable m1 -bg white -width 12 -height 8. m1 is a 2x2 array (matrix) automatically linked to the cells of the table (kind of like a list and a listbox's listvariable).


_________________
Bob Rashkin
 
Oops.
myself said:
m1 is a 2x2 array
I meant a 2D array. It's actually $i1 (set somewhere else) rows by 5 columns.

_________________
Bob Rashkin
 
Thank you Bong for the reply. I got this errors:

% invalid command name "table"
% bad window path name ".2.2"
% bad window path name ".2.2"
% bad window path name ".2.2.yscr"
% bad window path name ".2.2.t"
% bad window path name ".2.2.xscr"
% invalid command name ".2.2.t"
% can't read "i1": no such variable

Do you have any idea why?

Another question, is there anyway i can create a table and insert it in a word file.

Thanks.
 
% invalid command name "table"
First you have to load the library:
Code:
load tktable.dll
Did you do that?

% bad window path name ".2.2"
and all subsequent:
That is a reference to a frame I had created in my script. You need to refer to a frame where you want to place your table.

I don't know how to integrate Tcl and Word. I might be possible but if I needed to combine scripting and Word I'd use VBA instead of Tcl.

_________________
Bob Rashkin
 
Thanks Bong, and sorry for the late reply.

I found a code on wiki and it creates a table in word using tcom, but i have a question and i hope someone can help me.

Below is the code:
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  ]
[$doc Tables] Add  [[$application Selection] Range]  [set NumRows  3] [set NumColumns  4]
Does anyone know how to insert some text inside the columns and rows?

I tried to do this below:

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  ]
[$doc Tables] Add  [[$application Selection] Range]  [set NumRows  3] [set NumColumns  4]
[$application Selection] TypeText "Title"

I also tried using a \t i.e
Code:
[$application Selection] TypeText "Title\t"
[$application Selection] TypeText "Date"

But the text appear on the same row and column which is the first row and column. How do i insert text in each column and row?

Also, whenever i try to insert another table it inserts it one the first row/column, does anyone know why?

Any help will be appreciated.

Thanks in advance.
 
Well, I've never used Tcom but some of the syntax looks like it might be a conduit for VBA. Maybe I can help.

Instead of: [$doc Tables] Add
Try: set tbl [[$doc Tables] Add]

Now maybe you can configure it with something like:
$tbl [set numRows 3] (maybe, I don't really know).

Anyway, you should be able to refer to a particular cell in the table as $tbl.cell(n1,n2), where n1 is a row number and n2 is a column number, and the text of that cell as $tbl.cell(n1,n2).range.text="whatever"

_________________
Bob Rashkin
 
Bong,

Thanks for the help but its not coming out right. I will keep researching on it and try to figure it out.
 
I was able to figure it out, below is the code.

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  ]
[$doc Tables] Add  [[$application Selection] Range]  [set NumRows  1] [set NumColumns  3]
[$::application Selection] TypeText "Title"
[$::application Selection] MoveRight
[$::application Selection] TypeText "Date"
[$::application Selection] MoveRight
[$::application Selection] TypeText "Number"
[$::application Selection] MoveRight

Thanks,
Daisy
 
Hi,
I have ActiveTcl 8.5.7.1 wich contains tablelist (The Multi-Column Listbox Package Tablelist). But I havent use it yet.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top