File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 134134doc.save(' example-edited.docx' )
135135```
136136
137+ ### Writing to tables
138+
139+ ``` ruby
140+ require ' docx'
141+
142+ # Create a Docx::Document object for our existing docx file
143+ doc = Docx ::Document .open (' tables.docx' )
144+
145+ # Iterate over each table
146+ doc.tables.each do |table |
147+ last_row = table.rows.last
148+
149+ # Copy last row and insert a new one before last row
150+ new_row = last_row.copy
151+ new_row.insert_before(last_row)
152+
153+ # Substitute text in each cell of this new row
154+ new_row.cells.each do |cell |
155+ cell.paragraphs.each do |paragraph |
156+ paragraph.each_text_run do |text |
157+ text.substitute(' _placeholder_' , ' replacement value' )
158+ end
159+ end
160+ end
161+ end
162+
163+ doc.save(' tables-edited.docx' )
164+ ```
165+
137166### Advanced
138167
139168``` ruby
You can’t perform that action at this time.
0 commit comments