@@ -52,7 +52,7 @@ doc.bookmarks.each_pair do |bookmark_name, bookmark_object|
5252end
5353```
5454
55- Don't have a local file but a buffer? Docx handles those to :
55+ Don't have a local file but a buffer? Docx handles those too :
5656
5757``` ruby
5858require ' docx'
@@ -130,6 +130,14 @@ doc.paragraphs.each do |p|
130130 end
131131end
132132
133+ # Substitute text with access to captures, note block arg is a MatchData, a bit
134+ # different than String.gsub. https://ruby-doc.org/3.3.7/MatchData.html
135+ doc.paragraphs.each do |p |
136+ p .each_text_run do |tr |
137+ tr.substitute_with_block(/total: (\d +) / ) { |match_data | " total: #{ match_data[1 ].to_i * 10 } " }
138+ end
139+ end
140+
133141# Save document to specified path
134142doc.save(' example-edited.docx' )
135143```
@@ -145,7 +153,7 @@ doc = Docx::Document.open('tables.docx')
145153# Iterate over each table
146154doc.tables.each do |table |
147155 last_row = table.rows.last
148-
156+
149157 # Copy last row and insert a new one before last row
150158 new_row = last_row.copy
151159 new_row.insert_before(last_row)
@@ -261,3 +269,4 @@ The following is a list of attributes and what they control within the style.
261269* Default formatting of inserted elements to inherited values
262270* Implement formattable elements.
263271* Easier multi-line text insertion at a single bookmark (inserting paragraph nodes after the one containing the bookmark)
272+
0 commit comments