使用TCOM创建CSV中的选项卡 [英] Creating tabs in CSV using TCOM

查看:188
本文介绍了使用TCOM创建CSV中的选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加使用TCL中的TCOM包创建的.csv文件的选项卡。以下是用于创建第二个选项卡的代码。但是我看不到第二个Tab。我只是看到第一个标签创建。

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] 


推荐答案

你在这里称之为标签,实际上是一个工作表—一个概念只存在于某些办公电子表格应用程序(如Excel)中,您正在使用。当他们以原生的/ em>文件格式保存/加载数据时,这些应用程序能够保留这个高级结构,但是 CSV 更简单:它只是一个二维矩阵。由于这种简单性,CSV格式只能用于存储在典型的办公电子表格软件中维护的单个工作表的内容。此外,CSV不会存储高级内容,如单元格引用或公式或单元格格式等。

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:


  • 你应该在你的皮肤下的想法,在你的情况—通过COM从Tcl脚本化Excel,— Tcl和COM在概念上只是薄薄的层,没有什么感兴趣的:所有的重的提升是由Excel完成的。这意味着,如果您在编写某些Excel操作时遇到问题,请考虑Excel,不是这些包装器。执行以下步骤应通常有助于:

  • 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:


  1. 启动Excel并尝试手动执行您的预期操作。在你特定的情况下,这样可以避免您提出这个问题,因为您将看到无法将多页文档保存为CSV格式的文件。

  2. 记录一个宏,然后打开宏编辑器,看看为您编写的Excel(在VBA中)。从任何运行时将此代码转换为COM调用的调用非常简单。这是使用COM脚本编写此类软件的常用方法。


  • 阅读文档!没有阅读介绍性材料的借口,因为文档丰富了什么是CSV。 您已被告知 CSV您的想法更简单;这应该有一些钟声。

  • 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.

    这篇关于使用TCOM创建CSV中的选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆