From bdf1e62f601b77d3edfae163d3ceba448a89380a Mon Sep 17 00:00:00 2001 From: Urban Rotnik Date: Wed, 5 Aug 2020 16:14:43 +0200 Subject: [PATCH] Fix word reports when using headings --- app/services/reports/docx/private_methods.rb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/services/reports/docx/private_methods.rb b/app/services/reports/docx/private_methods.rb index 9b025459b..68d7a2b5d 100644 --- a/app/services/reports/docx/private_methods.rb +++ b/app/services/reports/docx/private_methods.rb @@ -19,12 +19,17 @@ module Reports::Docx::PrivateMethods tiny_mce_table(elem[:data]) elsif elem[:type] == 'newline' style = elem[:style] || {} - @docx.p elem[:value] do - align style[:align] - color style[:color] - bold style[:bold] - italic style[:italic] - style style[:style] if style[:style] + # print heading if its heading + # Mixing heading with other style setting causes problems for Word + if %w(h1 h2 h3 h4 h5).include?(style[:style]) + @docx.public_send(style[:style], elem[:value]) + else + @docx.p elem[:value] do + align style[:align] + color style[:color] + bold style[:bold] + italic style[:italic] + end end elsif elem[:type] == 'image' Reports::Docx.render_img_element(@docx, elem)