Re: Setting cell styles
Re: Setting cell styles
- Subject: Re: Setting cell styles
- From: Paul Berkowitz <email@hidden>
- Date: Fri, 16 Nov 2012 14:54:58 -0800
- Thread-topic: Setting cell styles
Title: Re: Setting cell styles
I hadn't caught that you just wanted set the style of a column, not the whole table.
Unfortunately, columns and rows in Word are quite primitive constructs (and buggy, too). A column doesn't even have a 'text object' property, which would allow you to set the style of that. This would be very simple to do in Excel, but not in Word.
Here's what I would have recommended: create a new table style in you document based off the one you're currently using, or modify it, and then apply that table style to the whole table by script. Except that, for some reason, in my version of Word (2008), the one thing that doesn't seem to "take" is applying style changes just to "Even column stripes". And I don't see any preset styles that alternate column colors, only two colors. (And applying changes to even or odd row stripes does work.)
Sorry, I can't see anything better than what you did, cell by cell.
--
Paul Berkowitz
From: Jeremy Roussak <email@hidden>
Date: Fri, 16 Nov 2012 20:54:55 +0000
To: Paul Berkowitz <email@hidden>
Subject: Re: Setting cell styles
Thanks, but I don't want to set every cell of the table to a particular style. I want to set some columns to one style and others to another.
Jeremy
Jeremy Roussak
email@hidden
On 16 Nov 2012, at 20:39, Paul Berkowitz <email@hidden> wrote:
Re: Setting cell styles
On 11/16/12 9:50 AM, "Jeremy Roussak" <email@hidden <x-msg://539/email@hidden> > wrote:
Is there an easy way to set all the cells in a particular column of a table to the same style? I know I can loop, and this works:
tell active document
set mytable to table 1
set myttr to Word style "ttr"
end tell
set rowCount to count mytable's rows
repeat with i from 1 to rowCount
set txt to text object of (get cell from table mytable row i column 2)
set txt's style to myttr
end repeat
but it doesn't look nice.
If you check the Word dictionary, you'll see in the Table Suite that 'table' itself has a 'style' property. Its class is described as 'base style', but in fact it works to set the style to a Word style too. So whether are you referring to a table style here, or to a regular paragraph style, either way it works just to set the style of the table.
tell application "Microsoft Word"
tell active document
set mytable to table 1
set myttr to Word style "Table Colorful 3"
-- or : set myttr to Word style "Emphasis"
end tell
set style of mytable to myttr
end tell
It's instantaneous.
I also tried it with both paragraph and table styles I created myself, and it works. (You have to have created the styles in the particular document, since styles are elements of 'document' and not of the Word application; but you probably know that already. If this is a style you'll want again in other documents, add it to your Normal template or make a special template to which you add this style. Then any new document you make (always, if added to Normal, or from the appropriate template otherwise) will have the style built in.
--
Paul Berkowitz
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden