Platinum Partner

Ruby & Word: Creating And Applying Styles

From the Ruby on Windows blog...


require 'win32ole'

word = WIN32OLE.connect('Word.Application')
doc = word.ActiveDocument

code_style = doc.Styles.Add({'Name' => 'Code', 'Type' => 1})

code_style.BaseStyle = 'Normal'
code_style.Font.Name = 'Consolas'
code_style.Font.Size = 12
code_style.Font.Bold = false
code_style.NoSpaceBetweenParagraphsOfSameStyle = true
code_style.Shading.BackgroundPatternColor = 15132390

doc.Paragraphs.each do |paragraph|
    if paragraph.Style.NameLocal == 'Preformatted Text'
        paragraph.Style = 'Code'
    end
end


Further details and discussion here.
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}