Search code examples
htmlruby-on-railsrubyopenxmldocx

underline in OpenXml::Docx using Ruby


I am using the OpenXml::Docx for creating docx and adding some text with some style like double underline, strike. The documentations explains through an example

 require "openxml/docx"

 text = OpenXml::Docx::Elements::Text.new("Some text that I want to 
 include in my new OOXML document")
 run = OpenXml::Docx::Elements::Run.new
 run.bold = true
 run << text
 paragraph = OpenXml::Docx::Elements::Paragraph.new
 paragraph << run


document = OpenXml::Docx::Package.new
document.document << paragraph
document.save("/path/where/i/save/things/test.docx")

So, I tried to make the text underlined but I was not able to do::

run = OpenXml::Docx::Elements::Run.new
run.underline = True

The underline tag is present as as property link but it is not showing in the output docx. Please let me know the correct method. Also, let me know way to do double underline.


Solution

  • Check the code for the Underline class for the attributes that can be set.

    e.g. You can set the type of underline with this:

    run = OpenXml::Docx::Elements::Run.new
    run.underline.type = :dash