Skip to content

Instantly share code, notes, and snippets.

@paytonrules
Created July 25, 2009 00:16
Show Gist options
  • Save paytonrules/154628 to your computer and use it in GitHub Desktop.
Save paytonrules/154628 to your computer and use it in GitHub Desktop.
require 'nokogiri'
system 'unzip Alliance.docx'
doc = Nokogiri::XML(open('word/document.xml'))
# Using Label Tag
doc.xpath("//w:fldSimple[contains(@w:instr, 'label_tag')]").each do |link|
command = link.attributes["instr"].value.match(/\#\{(.*)\}/)[1]
replacement_string = eval(command)
element.replace(Nokogiri::XML::Text.new(replacement_string, doc))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment