axlsx_rails excel report format breaks in windows
Asked Answered
C

0

6

Am using axlsx_rails gem with activeadmin to export formatted excel report This format is working fine in Ubuntu LibreOffice but the styles breaks in windows OS.

This is the proper aligned format in Ubuntu.

enter image description here

But below this image is from Windows that header border and spacing not aligned properly

enter image description here

My code is here.

Gemfile

gem 'axlsx', '~> 2.0.1'
gem 'axlsx_rails'
gem 'rubyzip', '~> 1.0.0'

config/initializers/mime_types.rb

Mime::Type.register "application/vnd.ms-excel", :xls

app/admin/job.rb

member_action :export_lease_abstract, method: :get do
  @job = Job.find(params[:id])
  render xlsx: 'export_lease_abstract_new_format', filename: 'lease_abstract_new_format', disposition: 'inline'
 end

sample view file - export_lease_abstract_new_format.xlsx.axlsx

wb = xlsx_package.workbook
header_style = wb.styles.add_style :sz => 14, :name => 'Times New Roman', :b => true, :alignment => {:horizontal => :center, :vertical => :top, :wrap_text => true}, :bg_color => "C0C0C0", :fg_color => "000000"
property_style = wb.styles.add_style :b => true, :sz => 12, :name => 'Times New Roman', :border => { :color => 'FF000000', :style => :thin }
sub_header_style = wb.styles.add_style :b => true, :sz => 10, :name => 'Times New Roman', :border => { :color => 'FF000000', :style => :thin }
content_title_style = wb.styles.add_style :b => true, :sz => 10, :name => 'Times New Roman'
content_value_style = wb.styles.add_style :sz => 10, :name => 'Times New Roman', :alignment => {:horizontal => :left}
content_title_top = wb.styles.add_style :b => true, :sz => 10, :name => 'Times New Roman', :alignment => {:horizontal => :left, :vertical => :top}
content_wrap_text = wb.styles.add_style :sz => 10, :name => 'Times New Roman', :alignment => {:horizontal => :left, :vertical => :top, :wrap_text => true}
content_title_center = wb.styles.add_style :b => true, :sz => 10, :name => 'Times New Roman', :alignment => {:horizontal => :center}
content_title_right = wb.styles.add_style :b => true, :sz => 10, :name => 'Times New Roman', :alignment => {:horizontal => :right}
rent_value_center_style = wb.styles.add_style :sz => 8, :name => 'Times New Roman', :alignment => {:horizontal => :center}
rent_value_right_style = wb.styles.add_style :sz => 10, :name => 'Times New Roman', :alignment => {:horizontal => :right}

border = wb.styles.add_style :border => { :color => 'FF000000', :style => :thin }
gray_cell = wb.styles.add_style  :bg_color => "C0C0C0", :fg_color => "FF"

wb.add_worksheet(:name => "Lease Abstract") do |sheet|
  sheet.sheet_view.show_grid_lines = false
  sheet.column_widths 5.2, 32.5, 12, 14, nil, 15, nil, nil, 5.2

  sheet.add_row [nil, nil, nil, nil, nil, nil, nil, nil, nil], :style => gray_cell
  sheet.add_row [nil, @job.la_project.name, nil, nil, nil, nil, nil, nil, nil], :style => [gray_cell, header_style, nil, nil, nil, nil, nil, nil, gray_cell], :height => 20
  sheet.merge_last_row columns:["B","H"]

  # img = File.expand_path('../../../assets/images/hds-logo.png', File.dirname(__FILE__))
  # sheet.add_image(:image_src => img, :noSelect => true, :noMove => true) do |image|
  #  image.width=100
  #  image.height=50
  #  image.start_at 0, 0
  # end

  sheet.add_row [nil, nil, nil, nil, nil, nil, nil, nil, nil], :style => [gray_cell, nil, nil, nil, nil, nil, nil, nil, gray_cell], :height => 12
  sheet.add_row [nil, lease_information.try(:tenant_name), nil, nil, nil, nil, nil, 'Lease Abstract', nil], :height => 17, :style => [gray_cell, property_style, nil, nil, nil, nil, nil, property_style, gray_cell], width: 10
  sheet.merge_last_row columns:["B","G"]

  sheet.add_row [nil, "PARTIES:", nil, nil, nil, nil, nil, nil, nil], :height => 12, :style => [gray_cell, sub_header_style, nil, nil, nil, nil, nil, nil, gray_cell]
  sheet.merge_last_row columns:["B","H"]
  # sheet.column_info.first.width = 30
  sheet.add_row [nil, nil, nil, nil, nil, nil, nil, nil, nil], :style => [gray_cell, nil, nil, nil, nil, nil, nil, nil, gray_cell], :height => 8
    sheet.add_row [nil, "Tenant Name:", lease_information.try(:tenant_name), nil, nil, "DBA:", lease_information.try(:dba), nil, nil], :style => [gray_cell, content_title_style, content_value_style, nil, nil, content_title_style, content_value_style, nil, gray_cell]
    sheet.merge_last_row columns:["C","E"]
    sheet.merge_last_row columns:["G","H"]
    # sheet.column_info.first.width = 30
    sheet.add_row [nil, nil, nil, nil, nil, nil, nil, nil, nil], :style => [gray_cell, nil, nil, nil, nil, nil, nil, nil, gray_cell], :height => 8
end

How to fix this format to look same in all the os.

Consumption answered 23/7, 2018 at 7:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.