Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

tcom: cant get builtin document prperties

15 views
Skip to first unread message

delbert

unread,
Feb 25, 2009, 3:06:42 AM2/25/09
to
Hi,
Im trying to get the Builtin document properties and some custom
properties for an excel spreadsheet using tcom.

Ive tried various combinations of puts below and get the following
puts [$builtinproperties Item "Title"]
::tcom::handle0x00C81E08


puts [$builtinproperties "Title"]
interface DocumentProperties does not have method or property Title
while executing
"$builtinproperties "Title""
invoked from within
"puts [$builtinproperties "Title"]"


Any suggestions? I have the equivalent VBScript working fine, but id
prefer to do it natively in TCL.
Thanks
Del

package require tcom
set xlsFile [file nativename [file join [pwd] del.xls]]
set excel [::tcom::ref createobj Excel.Application]

$excel DisplayAlerts False
set workbooks [$excel Workbooks]
set workbook [$workbooks Open $xlsFile]

set customproperties [$workbook CustomDocumentProperties]
set builtinproperties [$workbook BuiltinDocumentProperties]

# puts [$builtinproperties Item "Title"]
# puts [$builtinproperties "Title"]
# puts [$builtinproperties "Author"]
# puts [$builtinproperties Name]
# puts [$customproperties MyCustomeProp]

$workbook Close
$excel Quit

Alexandre Ferrieux

unread,
Feb 25, 2009, 3:26:34 AM2/25/09
to

A bit of exploration shows that $builtinproperties is a collection (it
has the Item property).
So basically it is a "list" which you have to iterate over to get
objects with properties Name and Value:

::tcom::foreach x $builtinproperties {puts [$x Name]:[$x Value]}

How did I find out ? I used tcom's (and COM's) nice introspection
ability:

set in [::tcom::info interface $builtinproperties]
puts [$in properties]
puts [$in methods]

There, when you see props Item and Count, the object is indeed a
collection, mandating ::tcom::foreach to crack the hull open.

-Alex

delbert

unread,
Feb 25, 2009, 4:00:40 AM2/25/09
to
On Feb 25, 8:26 am, Alexandre Ferrieux <alexandre.ferri...@gmail.com>
wrote:

Hi Alex,
Thanks, that works perfectly. Can now search list to get the Builtin
and Custom properties i want.


I then tried to repeat the experiment with Word.
I eventually got it to work.
The problem i was having is there is inconsistencies between Word and
Excel to get the BuiltIn Properties.
Its case sensitive!!

Excel requires this (Builtin)
set builtinproperties [$workbook BuiltinDocumentProperties]

Word requries this (BuiltIn)
set builtinproperties [$document BuiltInDocumentProperties]

Thanks
Del

0 new messages