Ms word MSWord Applescript:无法在段落后插入表格

Ms word MSWord Applescript:无法在段落后插入表格,ms-word,applescript,Ms Word,Applescript,我有一个严重的问题,试图在表格后添加一段。似乎无论我使用什么命令,文本总是出现在表中,即使我创建了一个新段落并向前移动了范围。非常感谢您对本脚本的任何帮助 请参阅下面的脚本: tell application "Microsoft Word" set myDocument to make new document set documentName to name of myDocument activate object document documentName

我有一个严重的问题,试图在表格后添加一段。似乎无论我使用什么命令,文本总是出现在表中,即使我创建了一个新段落并向前移动了范围。非常感谢您对本脚本的任何帮助

请参阅下面的脚本:

tell application "Microsoft Word"
    set myDocument to make new document
    set documentName to name of myDocument
    activate object document documentName
    set myTitle to create range myDocument start 0 end 0
    set content of myTitle to "Word Export"
    set myTitle to expand myTitle by a sentence item
    select myTitle
    set ascii name of font object of text object of selection to "calibri"
    set other name of font object of text object of selection to "calibri"
    set bold of text object of selection to true
    set font size of font object of text object of selection to 16
    set alignment of paragraph format of text object of selection to align paragraph center
    collapse range text object of selection direction collapse end
    insert paragraph at text object of selection
    insert paragraph at text object of selection
    insert text "Category - All" at text object of paragraph 2 of myDocument
    set myCategory to text object of paragraph 2 of active document
    set myCategory to collapse range myCategory direction collapse end
    set bold of myCategory to true
    set font size of font object of text object of paragraph 2 of myDocument to 14
    set alignment of paragraph format of myCategory to align paragraph center
    collapse range text object of selection direction collapse end
    insert paragraph at text object of selection
    insert paragraph at text object of selection
    insert text "Testing 1" at text object of paragraph 4 of myDocument
    set currentParagraph to text object of paragraph 4 of active document
    set bold of currentParagraph to false
    set bold of text object of selection to false
    set font size of font object of text object of paragraph 4 of myDocument to 12
    set alignment of paragraph format of currentParagraph to align paragraph left
    set currentParagraph to collapse range currentParagraph direction collapse end
    collapse range text object of selection direction collapse end
    -- Up to Paragraph 6 
    insert paragraph at text object of selection
    insert paragraph at text object of selection
    set oDoc to active document
    set oTable to make new table at oDoc with properties {text object:(paragraph 6), number of rows:3, number of columns:4}
    collapse range text object of selection direction collapse end
    set myRange to text object of selection
    set myRange to move end of range myRange by a table

    insert paragraph at text object of selection
    insert paragraph at text object of selection
    insert text "Testing 2" at text object of paragraph 8 of myDocument
    set currentParagraph to text object of paragraph 8 of active document
    set bold of currentParagraph to false
    set bold of text object of selection to false
    set font size of font object of text object of paragraph 8 of myDocument to 12
    set alignment of paragraph format of currentParagraph to align paragraph left
    set currentParagraph to collapse range currentParagraph direction collapse end
    collapse range text object of selection direction collapse end
    -- Up to Paragraph 10 
    insert paragraph at text object of selection
    insert paragraph at text object of selection
    set oDoc to active document
    set oTable to make new table at oDoc with properties {text object:(paragraph 10), number of rows:3, number of columns:4}
    collapse range text object of selection direction collapse end
    activate

结束讲述

我想这就是你正在尝试的。我自己对Applescript这个词不太熟悉,所以可能有更好的方法来做到这一点。作为一种习惯,我尽量避免使用选择,所以关键是能够将范围设置到文档的末尾

tell application "Microsoft Word"
    set myDocument to make new document
    set documentName to name of myDocument
    activate object document documentName

    set theRange to create range myDocument start 0 end 0
    set content of theRange to "Word Export"
    set theRange to expand theRange by a paragraph item
    set ascii name of font object of theRange to "calibri"
    set other name of font object of theRange to "calibri"
    set bold of theRange to true
    set font size of font object of theRange to 16
    set alignment of paragraph format of theRange to align paragraph center

    set theRange to my appendParagraphs(myDocument, 1)
    insert text "Category - All" at theRange
    set theRange to expand theRange by a paragraph item
    set bold of theRange to true
    set font size of font object of theRange to 14
    set alignment of paragraph format of theRange to align paragraph center

    set theRange to my appendParagraphs(myDocument, 2)
    insert text "Testing 1" at theRange
    set theRange to expand theRange by a paragraph item
    set bold of theRange to false
    set font size of font object of theRange to 12
    set alignment of paragraph format of theRange to align paragraph left

    -- Up to Paragraph 6 
    set theRange to my appendParagraphs(myDocument, 3)
    make new table at theRange with properties {number of rows:3, number of columns:4}
    set theRange to move end of range theRange by a table

    set theRange to my appendParagraphs(myDocument, 1)
    insert text "Testing 2" at theRange
    set theRange to expand theRange by a paragraph item
    set bold of theRange to false
    set font size of font object of theRange to 12
    set alignment of paragraph format of theRange to align paragraph left

    -- Up to Paragraph 10 
    set theRange to my appendParagraphs(myDocument, 3)
    make new table at theRange with properties {number of rows:3, number of columns:4}
    set theRange to move end of range theRange by a table
    --activate
end tell

to endOfDoc(aDocument)
    tell application "Microsoft Word" to tell aDocument to return (create range aDocument start (end of content of text object of aDocument) - 1 end (end of content of text object of aDocument) - 1)
end endOfDoc

to appendParagraphs(aDocument, paraCount)
    tell application "Microsoft Word" to tell aDocument
        repeat paraCount times
            insert paragraph at my endOfDoc(aDocument)
        end repeat
        return my endOfDoc(aDocument)
    end tell
end appendParagraphs