Fix issue where Word Online wasn't properly able to render our tables #5
@@ -130,27 +130,38 @@ module Ezdoc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def render_table(xml, table)
|
def render_table(xml, table)
|
||||||
|
column_count = table.rows.first&.cells&.size || 1
|
||||||
|
col_width = 5000 / column_count
|
||||||
|
|
||||||
xml["w"].tbl do
|
xml["w"].tbl do
|
||||||
xml["w"].tblPr 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
|
xml["w"].tblBorders do
|
||||||
%w[top left bottom right insideH insideV].each do |border|
|
%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
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_table_row(xml, row)
|
def render_table_row(xml, row, col_width)
|
||||||
xml["w"].tr do
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_table_cell(xml, cell)
|
def render_table_cell(xml, cell, col_width)
|
||||||
xml["w"].tc do
|
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
|
xml["w"].p do
|
||||||
cell.runs.each { |run| render_run(xml, run) }
|
cell.runs.each { |run| render_run(xml, run) }
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user