Hi Guys,
I am newbie in applescript.
I have created the following script to get values from excel, and Based on that Excel data, to create a 2 column table and 3 column table in an existing Word File (MS Word).
Script was running fine.
But when the Existing word file’s last paragraph was in Right Align.
The Newly created Tables (Cells) are also having Right align.
How to fix this?
Any help will be appreciated…
Thanks in advance,
John
tell application "Microsoft Excel"
tell active sheet
tell used range
delay 2
select (range "g1:g74")
copy range (range "g1:g74")
set thetext to the clipboard as list
set thetext to thetext as text
end tell
set paracount to count of paragraphs of (the clipboard)
repeat while thetext contains (return & return)
set AppleScript's text item delimiters to return & return
set theTextList to text items of thetext
set AppleScript's text item delimiters to return
set thetext to theTextList as text
end repeat
set reallist to paragraphs of thetext as text
set totalcount to count of paragraphs of thetext
set subcount to totalcount - 1
set Firstcount to totalcount - 3
if Firstcount > 1 then
set finalcount to Firstcount / 3
end if
end tell
if Firstcount is 0 then
tell application "Microsoft Word"
activate
tell active document
set nP to (count paragraph)
-- the doc must have at least two blank paragraphs at end of it before creating the textbox
if (content of text object of paragraph (nP - 1)) is not return then insert paragraph at after last character
if (content of text object of paragraph nP) is not return then insert paragraph at after last character
tell paragraph format of last paragraph to set alignment to align paragraph left
delay 0.1
select text object of last paragraph -- select the last blank paragraph
end tell
set oDoc to active document
set oTable to make new table at oDoc with properties {number of rows:1, number of columns:2} ¬
set iCount to 1
repeat with oCell in (get cells of text object of oTable)
set Newtext to paragraph iCount of thetext
insert text Newtext at text object of oCell
set iCount to iCount + 1
if iCount = 3 then
exit repeat
end if
end repeat
set tcount to count of tables of oDoc
tell paragraph format of column 1 of table tcount to set alignment to align paragraph center
set tbl to table tcount of active document
tell border options of tbl
set inside line style to line style single
set inside line width to line width50 point
set outside line style to line style single
set outside line width to line width50 point
end tell
end tell
else
tell application "Microsoft Word"
activate
tell active document
set nP to (count paragraph)
-- the doc must have at least two blank paragraphs at end of it before creating the textbox
if (content of text object of paragraph (nP - 1)) is not return then insert paragraph at after last character
if (content of text object of paragraph nP) is not return then insert paragraph at after last character
select text object of last paragraph -- select the last blank paragraph
end tell
set oDoc to active document
set oTable to make new table at oDoc with properties {number of rows:1, number of columns:2} ¬
set iCount to 1
repeat with oCell in (get cells of text object of oTable)
set Newtext to paragraph iCount of thetext
insert text Newtext at text object of oCell
set iCount to iCount + 1
if iCount = 3 then
exit repeat
end if
end repeat
set tcount to count of tables of oDoc
set tbl to table tcount of active document
tell border options of tbl
set inside line style to line style single
set inside line width to line width50 point
set outside line style to line style single
set outside line width to line width50 point
end tell
tell active document
set nP to (count paragraph)
-- the doc must have at least two blank paragraphs at end of it before creating the textbox
if (content of text object of paragraph (nP - 1)) is not return then insert paragraph at after last character
if (content of text object of paragraph nP) is not return then insert paragraph at after last character
set aa to content of text object of last paragraph
if aa = "" then
delete last paragraph
end if
select text object of last paragraph -- select the last blank paragraph
end tell
set oDoc to active document
try
set oTable to make new table at oDoc with properties {number of rows:finalcount, number of columns:3} ¬
set iCount to 3
repeat with oCell in (get cells of text object of oTable)
set Newtext to paragraph iCount of thetext
insert text Newtext at text object of oCell
set iCount to iCount + 1
end repeat
set tcount to count of tables of oDoc
set tbl to table tcount of active document
tell border options of tbl
set inside line style to line style single
set inside line width to line width50 point
set outside line style to line style single
set outside line width to line width50 point
end tell
end try
end tell
end if
end tell