tcom 操作word表格
#latest tcl
#install tcom package using teacup.
#how to use teacup
set docname "h:/ACG_FamilyCom_STD_Router_v0.1.doc"
set tmpname "h:/tmp.doc"
package require tcom
set application [::tcom::ref createobject "Word.Application"]
$application Visible 1
set H_Documents [$application Documents]
set Document [$H_Documents Open $docname]
set Tables [$Document Tables]
#set fid [open h:\ACG_FamilyCom_STD_Router_v0.1.html w]
for {set i 1} {$i<=[$Tables Count]} {incr i} {
set nowtable [$Tables Item $i]
set Rows [$nowtable Rows]
set Columns [$nowtable Columns]
puts $i:[$Rows Count]:[$Columns Count]
set Cell [$nowtable Cell 1 1]
set Range [$Cell Range]
regsub -all {[^a-zA-Z0-9 _]} [$Range Text] {} text
set text [$Range Text]
if {![regexp {Test Case} $text]} {
continue
}
for {set row 1} {$row<=[$Rows Count]} {incr row} {
for {set col 1} {$col<=[$Columns Count]} {incr col} {
set Cell [$nowtable Cell $row $col]
set Range [$Cell Range]
regsub -all {[^[:punct:][:space:][:alnum:]]} [$Range Text] {} text
if {[string length $text] >0} {
set text [string range $text 0 end-1]
}
if {$col == 1} {
set testcase $text
}
if {$col == 2} {
set description $text
}
if {$col == 3} {
set assumption $text
}
if {$col == 4} {
set actions $text
}
if {$col == 5} {
set expected $text
}
}
lappend fulllist $testcase $description $assumption $actions $expected
}
}
#close $fid
$application Quit
set application [::tcom::ref createobject "Word.Application"]
$application Visible 1
set H_Documents [$application Documents]
set Document [$H_Documents Open $tmpname]
set Tables [$Document Tables]
set i 3
foreach {testcase description assumption actions expected} $fulllist {
#puts "$testcase $description $assumption $actions $expected"
puts "$i"
set nowtable [$Tables Item $i]
set Rows [$nowtable Rows]
set Columns [$nowtable Columns]
set Cell [$nowtable Cell 1 2];set Range [$Cell Range];
$Range Text $testcase
set Cell [$nowtable Cell 2 2];set Range [$Cell Range];
$Range Text $description
set Cell [$nowtable Cell 5 2];set Range [$Cell Range];
$Range Text $assumption
set Cell [$nowtable Cell 6 2];set Range [$Cell Range];
$Range Text $actions
set Cell [$nowtable Cell 7 2];set Range [$Cell Range];
$Range Text $expected
incr i
}
proc methods H_interface {
set int [::tcom::info interface $H_interface]
foreach x [$int methods] {
lappend a "[lindex $x 2] [lindex $x 0] [lindex $x 1] [lindex $x 3]"
}
foreach x [lsort $a] {
puts $x
}
}
#install tcom package using teacup.
#how to use teacup
set docname "h:/ACG_FamilyCom_STD_Router_v0.1.doc"
set tmpname "h:/tmp.doc"
package require tcom
set application [::tcom::ref createobject "Word.Application"]
$application Visible 1
set H_Documents [$application Documents]
set Document [$H_Documents Open $docname]
set Tables [$Document Tables]
#set fid [open h:\ACG_FamilyCom_STD_Router_v0.1.html w]
for {set i 1} {$i<=[$Tables Count]} {incr i} {
set nowtable [$Tables Item $i]
set Rows [$nowtable Rows]
set Columns [$nowtable Columns]
puts $i:[$Rows Count]:[$Columns Count]
set Cell [$nowtable Cell 1 1]
set Range [$Cell Range]
regsub -all {[^a-zA-Z0-9 _]} [$Range Text] {} text
set text [$Range Text]
if {![regexp {Test Case} $text]} {
continue
}
for {set row 1} {$row<=[$Rows Count]} {incr row} {
for {set col 1} {$col<=[$Columns Count]} {incr col} {
set Cell [$nowtable Cell $row $col]
set Range [$Cell Range]
regsub -all {[^[:punct:][:space:][:alnum:]]} [$Range Text] {} text
if {[string length $text] >0} {
set text [string range $text 0 end-1]
}
if {$col == 1} {
set testcase $text
}
if {$col == 2} {
set description $text
}
if {$col == 3} {
set assumption $text
}
if {$col == 4} {
set actions $text
}
if {$col == 5} {
set expected $text
}
}
lappend fulllist $testcase $description $assumption $actions $expected
}
}
#close $fid
$application Quit
set application [::tcom::ref createobject "Word.Application"]
$application Visible 1
set H_Documents [$application Documents]
set Document [$H_Documents Open $tmpname]
set Tables [$Document Tables]
set i 3
foreach {testcase description assumption actions expected} $fulllist {
#puts "$testcase $description $assumption $actions $expected"
puts "$i"
set nowtable [$Tables Item $i]
set Rows [$nowtable Rows]
set Columns [$nowtable Columns]
set Cell [$nowtable Cell 1 2];set Range [$Cell Range];
$Range Text $testcase
set Cell [$nowtable Cell 2 2];set Range [$Cell Range];
$Range Text $description
set Cell [$nowtable Cell 5 2];set Range [$Cell Range];
$Range Text $assumption
set Cell [$nowtable Cell 6 2];set Range [$Cell Range];
$Range Text $actions
set Cell [$nowtable Cell 7 2];set Range [$Cell Range];
$Range Text $expected
incr i
}
proc methods H_interface {
set int [::tcom::info interface $H_interface]
foreach x [$int methods] {
lappend a "[lindex $x 2] [lindex $x 0] [lindex $x 1] [lindex $x 3]"
}
foreach x [lsort $a] {
puts $x
}
}
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/459749/viewspace-1213423/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- word放不下excel表格怎麼辦 word放不下excel表格的方法Excel
- Poi向Word插入表格,設定表格邊框和表格居中
- Python操作WordPython
- Java操作WordJava
- word怎麼設定表格數字水平居中 word設定表格數字居中的方法
- 如何將excel表格匯入word並保持格式不變 如何把excel的表格弄到word文件Excel
- 如何將Word文件轉成Excel表格?Excel
- word常規操作
- word(2010)使用VBA完成批處理操作-批量清除表格某單元格內容
- python 操作 Excel 表格PythonExcel
- java操作excel表格JavaExcel
- word怎麼使用公式計算求和 word表格一行求和公式
- word表格標題行重複怎麼設定 word表格標題行無法重複的方法
- 最小步長移動word表格標尺
- pdf的表格怎麼轉換成word?
- word裡面設定三線表格式
- Word的相關操作
- 7個超實用Word小技巧:Word怎麼將文字轉表格?
- 使用Java操作Excel表格JavaExcel
- pageoffice線上開啟word檔案生成表格
- excel表格怎麼轉換成word文件 表格資料轉換到文件Excel
- word字型放大怎麼操作?
- Spread表格元件For JAVA功能介紹—表格相關操作元件Java
- Java 讀取Word表格中的文字和圖片Java
- layui 表格操作匯入檔案UI
- Python 在Word中建立表格並填入資料、圖片Python
- Java 讀取Word文字框中的文字/圖片/表格Java
- python操作word、pdf問題彙總Python
- python-docx操作word文件詳解Python
- 如何設定excel表格貼上到word後寬度不變Excel
- Word 表格內容不會自動轉到下一頁
- WPS 使用宏操作 word裡面的所有表
- ppt轉換word文件怎麼操作 把ppt轉換成word純文字
- 表格單元格點選操作(彈窗)
- 怎麼做表格在電腦上怎麼操作 在電腦上做表格的操作方法介紹
- 10分鐘做好 Bootstrap Blazor 的表格元件匯出 Excel/Word/Html/PdfbootBlazor元件ExcelHTML
- 資料庫文件編寫,如何通過Navicat把表導成表格?資料庫快速匯出為excel表格資訊,excel匯出到word表格資料庫Excel
- Excel 2019表格操作技巧彙總 一秒鐘輕鬆製作各種表格Excel
- 安卓版 Google Sheets 表格應用支援滑鼠操作安卓Go