Over a million developers have joined DZone.

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.
Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}