lib/avv2word/document.rb in avv2word-1.1.20 vs lib/avv2word/document.rb in avv2word-1.1.21
- old
+ new
@@ -90,10 +90,14 @@
end
def content_types_xml_file
'[Content_Types].xml'
end
+
+ def footnotes_xml_file
+ 'word/footnotes.xml'
+ end
end
def initialize(template_path)
@replaceable_files = {}
@template_path = template_path
@@ -191,11 +195,13 @@
def add_footnotes(footnotes)
if footnotes.empty?
@replaceable_files["word/footnotes.xml"] = ""
return
end
- doc = Nokogiri::XML.parse(File.read("templates/default/word/footnotes.xml"))
+ #text = Zip::File.open("templates/default.docx"){|zipfile| zipfile.read("word/footnotes.xml")}
+ text = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><w:footnotes xmlns:wpc=\"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas\" xmlns:cx=\"http://schemas.microsoft.com/office/drawing/2014/chartex\" xmlns:cx1=\"http://schemas.microsoft.com/office/drawing/2015/9/8/chartex\" xmlns:cx2=\"http://schemas.microsoft.com/office/drawing/2015/10/21/chartex\" xmlns:cx3=\"http://schemas.microsoft.com/office/drawing/2016/5/9/chartex\" xmlns:cx4=\"http://schemas.microsoft.com/office/drawing/2016/5/10/chartex\" xmlns:cx5=\"http://schemas.microsoft.com/office/drawing/2016/5/11/chartex\" xmlns:cx6=\"http://schemas.microsoft.com/office/drawing/2016/5/12/chartex\" xmlns:cx7=\"http://schemas.microsoft.com/office/drawing/2016/5/13/chartex\" xmlns:cx8=\"http://schemas.microsoft.com/office/drawing/2016/5/14/chartex\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:aink=\"http://schemas.microsoft.com/office/drawing/2016/ink\" xmlns:am3d=\"http://schemas.microsoft.com/office/drawing/2017/model3d\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:wp14=\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" xmlns:w15=\"http://schemas.microsoft.com/office/word/2012/wordml\" xmlns:w16cid=\"http://schemas.microsoft.com/office/word/2016/wordml/cid\" xmlns:w16se=\"http://schemas.microsoft.com/office/word/2015/wordml/symex\" xmlns:wpg=\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\" xmlns:wpi=\"http://schemas.microsoft.com/office/word/2010/wordprocessingInk\" xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\" mc:Ignorable=\"w14 w15 w16se w16cid wp14\"><w:footnote w:type=\"separator\" w:id=\"-1\"><w:p w:rsidR=\"00C3170C\" w:rsidRDefault=\"00C3170C\" w:rsidP=\"001755D5\"><w:r><w:separator/></w:r></w:p></w:footnote><w:footnote w:type=\"continuationSeparator\" w:id=\"0\"><w:p w:rsidR=\"00C3170C\" w:rsidRDefault=\"00C3170C\" w:rsidP=\"001755D5\"><w:r><w:continuationSeparator/></w:r></w:p></w:footnote><w:footnote w:id=\"1\"><w:p w:rsidR=\"001755D5\" w:rsidRDefault=\"001755D5\"><w:pPr><w:pStyle w:val=\"FootnoteText\"/></w:pPr><w:r><w:rPr><w:rStyle w:val=\"FootnoteReference\"/></w:rPr><w:footnoteRef/></w:r><w:r><w:t xml:space=\"preserve\"> How are you?</w:t></w:r></w:p></w:footnote></w:footnotes>"
+ doc = Nokogiri::XML.parse( text )
fn_node = doc.xpath("//w:footnote").last
footnotes.each_with_index do |footnote,i|
fn_node2 = fn_node.clone
fn_node2.parent = fn_node.parent
fn_node2["w:id"] = (fn_node["w:id"].to_i + i).to_s
@@ -204,11 +210,11 @@
fn_node.remove
@replaceable_files["word/footnotes.xml"] = doc.to_xml
# add relation
rels = Nokogiri::XML(@replaceable_files["word/_rels/document.xml.rels"])
- new_rel = '<Relationship Id="rIdXXXXX" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes" Target="footnotes.xml"/>'
- new_rel.sub!(/XXXXX/, (rels.xpath("//xmlns:Relationship").size+1).to_s )
+ new_rel = '<Relationship Id="rIdXX" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes" Target="footnotes.xml"/>'
+ new_rel.sub!(/XX/, (rels.xpath("//xmlns:Relationship").size+1).to_s )
new_rel = Nokogiri::XML.parse(new_rel).child
rels.children.first << new_rel
@replaceable_files["word/_rels/document.xml.rels"] = rels.to_xml
end