What I am trying to do is to add a text to some excel file, using TCL script . For working with excel I am using Tcom .
set excelFilePath "C:/TCL.Marko.xlsx"
proc start_tcom {} {
global excelFilePath excelApp workbook
set excelApp [::tcom::ref createobject Excel.Application]
set workbooks [$excelApp Workbooks]
set workbook [$workbooks Open [file nativename [file join [pwd] $excelFilePath] ] ]
set worksheets [$workbook Worksheets]
#
set excel_sheet Marko.xlsx
set worksheet [$worksheets Item [expr 1]]
set cells [$worksheet Cells]
return $cells
}
Up till this point all works.
509 % start_tcom
::tcom::handle0x0284F9D8
Then I am running:
513 % foreach row {1 2 3} {
foreach column {A B C} {
$cells Item $row $column [incr i]
}
}
and getting this error:
0x800a01a8 {Unknown error 0x800A01A8}
if I am doing
save_and_close_tcom
I can see file Marko.xslx is updated with the correct time and date, so the TCL see the correct file, but still getting this error.
the " set excel_sheet Marko.xlsx" should be removed . this command means working with tab name "Marko.xlsx" , but this tab doesnt exist. and thats why the error came. this is the correct code with explanations :
proc start_tcom {} {
global excelFilePath excelApp workbook
set excelApp [::tcom::ref createobject Excel.Application]
# Connect to Excel COM object.
set workbooks [$excelApp Workbooks]
set workbook [$workbooks Open [file nativename [file join [pwd] $excelFilePath] ] ]
set worksheets [$workbook Worksheets]
# Create inital workbook.
set worksheet [$worksheets Item [expr 1]]
$worksheet Name "Booleans"
# Rename the first tab.
set cells [$worksheet Cells]
return $cells
#Making cells ready for input
}
set fp [open "[pwd]/TEMP/WTX.txt" r] set file_data [read $fp]
set Col A
set Row 1
set Row 1
while {[lindex $file_data $i] != ""} {
$cells Item $Row $Col $numeric_value_from_file
incr Row
}