我在尝试在表格后添加段落时遇到了严重问题。似乎无论我使用什么命令,文本总是出现在表格中,即使我已经创建了一个新的段落并向前移动了范围。对此脚本的任何帮助都将非常感激。
请参阅以下脚本:
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
告诉
答案 0 :(得分:0)
我认为这就是你的尝试。我自己并不是特别熟悉Word 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