diff --git a/lib/ezdoc/xml/document_xml.rb b/lib/ezdoc/xml/document_xml.rb index d97cd02..4423165 100644 --- a/lib/ezdoc/xml/document_xml.rb +++ b/lib/ezdoc/xml/document_xml.rb @@ -130,27 +130,38 @@ module Ezdoc end def render_table(xml, table) + column_count = table.rows.first&.cells&.size || 1 + col_width = 5000 / column_count + xml["w"].tbl do xml["w"].tblPr do - xml["w"].tblW("w:w" => "0", "w:type" => "auto") + xml["w"].tblW("w:w" => "5000", "w:type" => "pct") xml["w"].tblBorders do %w[top left bottom right insideH insideV].each do |border| - xml["w"].send(border, "w:val" => "single", "w:sz" => "4", "w:color" => "000000") + xml["w"].send(border, "w:val" => "single", "w:sz" => "4", "w:space" => "0", "w:color" => "000000") end end end - table.rows.each { |row| render_table_row(xml, row) } + xml["w"].tblGrid do + column_count.times do + xml["w"].gridCol("w:w" => col_width.to_s) + end + end + table.rows.each { |row| render_table_row(xml, row, col_width) } end end - def render_table_row(xml, row) + def render_table_row(xml, row, col_width) xml["w"].tr do - row.cells.each { |cell| render_table_cell(xml, cell) } + row.cells.each { |cell| render_table_cell(xml, cell, col_width) } end end - def render_table_cell(xml, cell) + def render_table_cell(xml, cell, col_width) xml["w"].tc do + xml["w"].tcPr do + xml["w"].tcW("w:w" => col_width.to_s, "w:type" => "pct") + end xml["w"].p do cell.runs.each { |run| render_run(xml, run) } end