You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Than, you need to find the existing table on your template and duplicate it, it's rows and it's cells.
defadd_docx_table(docx)# Note: Without this empty paragraph and not using insert_before# All tables are ending up at the bottom of the generated documentadd_docx_paragraph(docx,"")table=docx.tables.first.copytable.insert_before(docx.paragraphs.last)add_docx_table_headers(table,text)add_docx_table_rows(table,text)# Remove initial table artifacts that comes from the templatetable.rows.first.remove!table.rows.eachdo |row|
row.cells.first.remove!endenddefadd_docx_paragraph(docx,text,prepend_new_line: false)add_docx_paragraph(docx,"")ifprepend_new_lineparagraph_copy=docx.paragraphs.first.copyparagraph_copy.text=textparagraph_copy.insert_after(docx.paragraphs.last)enddefadd_docx_table_headers(table,text)first_row=table.rows.firstnew_row=first_row.copynew_row.insert_after(first_row)first_cell=new_row.cells.firstnew_cell=first_cell.copynew_cell.insert_after(new_row.cells.last)new_cell.paragraphs.first.text=textenddefadd_docx_table_rows(table,text)first_row=table.rows.firstnew_row=first_row.copynew_row.insert_after(table.rows.last)first_cell=new_row.cells.firstnew_cell=first_cell.copynew_cell.insert_after(new_row.cells.last)new_cell.text=textend
I modified my original code to be able to share this example, so it might have small problems here and there, but in order to understand the idea, I think it's a helpful example to start with.
Problem
I need to write a new table in an existing paragraph, and I don't see any functions supporting that. Please help.
The text was updated successfully, but these errors were encountered: