【问题标题】:Duplicate a Word table using Applescript使用 Applescript 复制 Word 表格
【发布时间】:2026-01-24 11:30:02
【问题描述】:

我有 AS 正在努力将数据写入 Word 2011 中的表格,我可以获取该表格的属性,但是如何复制表格并将新表格添加到活动文档但名称/ID 不同? abFile 在 tell 块之前指定。

tell application "Microsoft Word"
activate
open abFile
set tableProps to get properties of tables of active document
end tell

我想要的是一种表达方式:

make new table in active document with tableProps and name "2"

【问题讨论】:

  • 据我从字典中得知,MS Words 表没有“名称”属性。至少对于 OSX 10.8.5 上的 Word 2011 来说不是。此外,我认为对于任何正确实现的 applescript 字典,对象 ID 总是由 applescript 运行时环境分配,并且对脚本是只读的
  • 查看 SL 中的 Word 2011 字典我同意,但我怎样才能创建一个具有相同属性的新表并让 AS 处理 ID?

标签: ms-word applescript osx-snow-leopard


【解决方案1】:

我尝试的第一件事是:

tell application "Microsoft Word"
    activate
    open abFile
    set tableList to tables of active document
    set firstTable to item 1 of tableList
    make new table in active document with properties (properties of firstTable)
end tell

这确实创建了一个新表,但似乎没有实际复制任何属性 - 至少行数和列数不同。

您可以尝试的另一件事是简单地复制一个表:

tell application "Microsoft Word"
    activate
    open abFile
    set tableList to tables of active document
    set firstTable to item 1 of tableList
    duplicate item 1 of tableList
end tell

这确实创建了一个新表格,但它的单元格内容与原始表格相同。我不确定您是只想复制属性,还是还想复制单元格内容。

【讨论】:

    最近更新 更多