Reputation: 573
I want to add tabs to the .csv file I'm creating using the TCOM package in TCL. The following is the code I used to create a second tab. But I don't see a second Tab. I just see the first tab created.
set application [::tcom::ref createobject "Excel.Application"]
set XlFileFormat(xlCSV) [expr 6]
set workbooks [$application Workbooks]
set workbook [$workbooks Add]
$application DisplayAlerts False
set worksheets [$workbook Worksheets]
set worksheet1 [$worksheets Item [expr 1]]
set cells_worksheet1 [$worksheet1 Cells]
set worksheet2 [$worksheets Item [expr 2]
set cells_worksheet2 [$worksheet2 Cells]
Upvotes: 0
Views: 287
Reputation: 55533
What you call a "tab" here, is really a worksheet — a concept only existing in certain office spreadsheet applications such as Excel, you're using. When saving/loading data in their native file formats, those applications are able to preserve this high-level structure, but CSV is way simpler: it's just a two-dimensional matrix. Due to this simplicity, the CSV format can be used only to store the contents of a single sheet of a workspace maintained in a typical office spreadsheet software. Moreover, CSV won't store advanced stuff such as cell references or formulas or cell formatting etc — only raw data.
Now please evaluate carefully the following pieces of advice:
You should get under you skin the idea that in your case — scripting Excel via COM from Tcl, — Tcl and COM are conceptually just thin dumb layers which do nothing of interest: all the heavy lifting is done by Excel. This means, that if you face a problem with scripting some Excel action, think of Excel, not these wrappers. Performing the following steps should usually help:
Read the docs! There's no excuse for not reading an introductory material on what CSV is since the docs are in abundance. You have already been told that CSV is way simpler you think it is; this should have rung some bell.
Upvotes: 1