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

TCL twapi excel write: Text formatting

118 views
Skip to first unread message

Nikh

unread,
Feb 11, 2018, 11:39:19 AM2/11/18
to
I am using twapi pacakge (4.1.27 , 64bit) to write data to excel. I made cell formatting to text before I write data, still I see values like '1.23E+09' when the actual data is '123356670668'. My code below.

Similar code works fine in tcom package (32bit package), so it is not issue with the version of Excel I am using. How can I display the actual value in Excel cell? (123356670668 in this case)

#twapi 4.1.27
package require twapi

set excelOutFile {C:\AA\1.xlsx}

set application [::twapi::comobj Excel.Application]
set workbooks [$application Workbooks]

set workbook [$workbooks Add]
set worksheets [$workbook Worksheets]
set worksheet [$worksheets Item [expr 1]]
$worksheet Activate
set cells [$worksheet Cells]

set range [$worksheet Range "A1" "A1"]
#change format to Text
$range NumberFormat "@"

$cells Item [expr 1] [expr 1] "123356670668"

$workbook SaveAs $excelOutFile
$application Quit
$cells -destroy
$worksheet -destroy
$worksheets -destroy
$workbook -destroy
$workbooks -destroy
$application -destroy
unset application

Paul Obermeier

unread,
Feb 11, 2018, 3:46:50 PM2/11/18
to
You have to explicitly tell Twapi, it is a string:
$cells Item [expr 1] [expr 1] [twapi::tclcast string "123356670668"]

Don't know, if that's already available in 4.1.27. Otherwise use the
latest Twapi version.

You might also take a look at my CAWT package, which hides lots of these
low-level details: http://www.posoft.de/html/extCawt.html

Best regards,
Paul

Nikh

unread,
Feb 11, 2018, 5:56:53 PM2/11/18
to
On Sunday, February 11, 2018 at 3:46:50 PM UTC-5, Paul Obermeier wrote:
> You have to explicitly tell Twapi, it is a string:
> $cells Item [expr 1] [expr 1] [twapi::tclcast string "123356670668"]
>
> Don't know, if that's already available in 4.1.27. Otherwise use the
> latest Twapi version.
>
> You might also take a look at my CAWT package, which hides lots of these
> low-level details: http://www.posoft.de/html/extCawt.html
>
> Best regards,
> Paul

twapi::tclcast did not work. This is working fine in tcom package. I have this issue only with twapi package.

Paul Obermeier

unread,
Feb 11, 2018, 6:13:08 PM2/11/18
to
Sorry, should be "twapi::tclcast bstr".
It's available only in twapi 4.2.X.
You should update to 4.2.X, because Ashok (developer of twapi) made lots
of fixes and enhancements regarding the COM interface.

Nikh

unread,
Feb 12, 2018, 8:53:54 PM2/12/18
to
On Sunday, February 11, 2018 at 6:13:08 PM UTC-5, Paul Obermeier wrote:
> Sorry, should be "twapi::tclcast bstr".
> It's available only in twapi 4.2.X.
> You should update to 4.2.X, because Ashok (developer of twapi) made lots
> of fixes and enhancements regarding the COM interface.
>
>
Well I tried to use the twapi 4.2.12 package posted at https://sourceforge.net/projects/twapi/.
It gave me an error "attempt to provide package twapi 4.2.12 failed: package twapi 4.1.27 provided instead" on 'package require twapi' command.

Gerald Lester

unread,
Feb 12, 2018, 9:24:53 PM2/12/18
to
Did you use the last release or the trunk?

If you use the trunk, you may have to build the pkgIndex.tcl yourself.

--
+----------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald...@kng-consulting.net |
+----------------------------------------------------------------------+

Nikh

unread,
Feb 12, 2018, 9:35:16 PM2/12/18
to
On Monday, February 12, 2018 at 9:24:53 PM UTC-5, Gerald Lester wrote:

> > Well I tried to use the twapi 4.2.12 package posted at https://sourceforge.net/projects/twapi/.
> > It gave me an error "attempt to provide package twapi 4.2.12 failed: package twapi 4.1.27 provided instead" on 'package require twapi' command.
> >
>
> Did you use the last release or the trunk?
>
> If you use the trunk, you may have to build the pkgIndex.tcl yourself.
>
> --
> +----------------------------------------------------------------------+
> | Gerald W. Lester, President, KNG Consulting LLC |
> | Email: Gerald...@kng-consulting.net |
> +----------------------------------------------------------------------+

I used the latest release

Peter Dean

unread,
Feb 12, 2018, 10:28:09 PM2/12/18
to
You could install the latest tcl from magicsplat.com. It has a
perfectly working 4.2.13

Ashok

unread,
Feb 13, 2018, 12:10:22 AM2/13/18
to
That error usually indicates an installation error; maybe you have both
4.1.27 and 4.2.12 somewhere in your Tcl library paths.

/Ashok
Message has been deleted

Nikh

unread,
Feb 13, 2018, 9:35:33 AM2/13/18
to
Here are the commands from tclsh window: it complains about cant find package twapi on first command. I assume that means no twapi pcakage in tcllib location.


%package require twapi
can't find package twapi
% lappend ::auto_path {C:\work\excel\twapi-4.2.12}
C:/tcltk/lib/tcl8.6 C:/tcltk/lib C:/tcltk/lib/tcllib1.15 {C:\work\excel\twapi-4.2.12}
% package require twapi
attempt to provide package twapi 4.2.12 failed: package twapi 4.1.27 provided instead
%

I am using the binaries posted at https://sourceforge.net/projects/twapi/.

Nikh

unread,
Feb 13, 2018, 12:12:24 PM2/13/18
to
twapi from magicsplat (4.2.13) is working as expected. Thanks!!
0 new messages