TCL:表格(xls)中写入数据

 1 intToChar.tcl
 2
 3 # input a number : 1 to 32 , you will get a char A to Z
 4 #A-Z:1-32
 5 proc intToChar {int} {
 6     if {![string is integer $int]} {
 7         return "Please input a number!"
 8     }
 9     if {![expr 0<$int&&32>$int]} {
10         return "Input a numer range 1 to 32!"
11     }
12     set listChars [list A B C D E F G H I J K L M N O P Q R S T U V W X Y Z]
13     set intTemp [expr $int-1]
14     return [lindex $listChars $intTemp]
15 }
16
17 #test
18 #return [intToChar 1]
19
20
21 intToChar.tcl
22
23 package require tcom
24 source intToChar.tcl
25 proc xls_write {fileName date} {
26 #    if {[file exists $fileName]} {
27 #        return {File is existed !   Please delete or change the the of the file !}
28 #    }
29     if {""==$date} {
30         return "The date is NULL or ‘‘ !"
31     }
32 #    set fileName {D:/test.xlsx}
33     # 创建com实例,打开工作表
34     set application [::tcom::ref createobject "Excel.Application"]
35     $application Visible 1
36     set workbooks [$application Workbooks]
37     set workbook [$workbooks Add]
38     set worksheets [$workbook Worksheets]
39     #set worksheet [$worksheets Item "Sheet1"]
40     set worksheet [$worksheets Item [expr 1]]
41     set cells [$worksheet Cells]
42
43     set exeFlag 1
44
45     if {1==$exeFlag} {
46 #        set date {}
47         set dateRawLength [llength $date]
48         set rawIndex 0
49         while { $rawIndex < $dateRawLength } {
50             set dateColumnLength 0
51             set dateColumnLength [llength [lindex $date $rawIndex]]
52             set columnIndex 0
53             while { $columnIndex < $dateColumnLength } {
54                 [$cells Item [expr $rawIndex+1] [intToChar [expr $columnIndex+1]]] Value2 [lindex [lindex $date $rawIndex] $columnIndex]
55                 incr columnIndex
56             }
57             incr rawIndex
58         }
59     }
60     #code not work like wanting
61 #    if {[regexp -all {\\|/} $fileName]} {
62 #        cd [file dirname $fileName]
63 #    }
64     #save without asking
65     $application DisplayAlerts [expr 0]
66 #    $workbook SaveCopyAs {d://ts.xlsx}
67     $workbook SaveAs $fileName
68     $workbook Close
69     $application Quit
70 #    return [file join [file dirname $fileName] [file tail $fileName]]
71 }
72 #含路径的文件保存时,有时会失败,原因不详(xls默认保存路径:菜单"文件"-->"选项"-->"保存",查看路径)
73 set fileName {d:\testaaa.xlsx}
74 set date [list [list 1 2 3 4 5 6 7 8 9 10] [list a b c d e f g] [list nihao hello 你好 howAreYou?]]
75 #test
76 return [xls_write $fileName $date]
时间: 2024-08-07 08:38:23

TCL:表格(xls)中写入数据的相关文章

向post请求中写入数据,最终保存在了HttpWebRequest.Params中

一.向post请求中写入数据,最终保存在了HttpWebRequest.Params中: 1)如果存入的是IDictionary类型的字符串变量,如:“username=administrator”,则key=value: 2)如果写入的是string类型的变量,如"username",则key=null,value=username: protected void btnLogin_Click(object sender, EventArgs e) { string Url = &q

【转】从QDataStream向QByteArray中写入数据时的注意点(QT)

最近发现从QDataStream向QByteArray中写入数据常常是写不进去的,通过查看QT的源码: QDataStream &operator>>(QDataStream &in, QByteArray &ba){ ba.clear(); quint32 len; in >> len; if (len == 0xffffffff) return in; const quint32 Step = 1024 * 1024; quint32 allocated

计算机二级-C语言-程序填空题-190117记录-对文件的处理,复制两个文件,往新文件中写入数据。

//给定程序的功能是,调用函数fun将指定源文件中的内容赋值到指定目标文件中,复制成功时函数返回1,失败时返回0,把复制的内容输出到终端屏幕.主函数中源文件名放在变量sfname中,目标文件名放在变量tfname中. //重难点:对文件的处理.如何判断文件是否达到末尾,如何往文件中写入数据. 1 #include <stdio.h> 2 #include <stdlib.h> 3 int fun(char *source, char *target) 4 { FILE *fs,*f

POI向Excel中写入数据及追加数据

import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import java.io.*; import java.util.ArrayList; import java.

java实现赋值excel模板,并在新文件中写入数据,并且下载

/** * 生成excel并下载 */ public void exportExcel(){ File newFile = createNewFile(); //File newFile = new File("d:/ss.xls"); //新文件写入数据,并下载***************************************************** InputStream is = null; HSSFWorkbook workbook = null; HSSFSh

Python向excel中写入数据的方法 方法简单

最近做了一项工作需要把处理的数据写入到Excel表格中进行保存,所以在此就简单介绍使用Python如何把数据保存到excel表格中. 数据导入之前需要安装 xlwt依赖包,安装的方法就很简单,直接 pip install xlwt ,如果电脑中安装过就不需要重复安装. 接下来就做一个简单的demo ,把三行数据添加到excel中. 具体代码如下: #!/usr/bin/env python # coding=utf-8 from xlwt import * #需要xlwt库的支持 #import

lua向文件中写入数据,进行记录

function readfile(path) local file = io.open(path, "r") if file then local content = file:read("*a") io.close(file) return content end return nil end function writefile(path, content, mode) mode = mode or "w+b" local file = i

往Android SDCard中写入数据

一.用Environment 1.API获取sdcard的路径 File path=Environment.getExternalStorageDirectory(); path=new File(path,"test.txt"); 2.用流写入内容 3.获取WRITE_EXTERNAL_STORAGE权限 二.获取shared_prefs目录,写xml 1.获取SharedPreferences SharedPreferences shared =this.getSharedPref

第十六章,向txt文件中写入数据(C++)

#include <iostream> #include <fstream> int main(int argc, char** argv) { //app是追加的意思,append //盘符后面一定是双斜杠 \\ //没有这个文件,会自动创建 std::ofstream outfile("e:\\123.txt",std::ios::app); if(outfile.is_open()){ outfile<<"ccccc"; /