Axlsx Gem在合并细胞内移动图像

时间:2016-03-11 21:32:51

标签: ruby axlsx

我试图在使用axlsx gem创建的电子表格上设置标题。在标题中我想要一个徽标和图像与文本。当我将start_at设置为[0,0]时,如果我使用[1,0],图像会转到合并单元格的左上角,它会向远处向下移动。有没有办法可以调整单元格内的图像,如边距或填充?

index.xlsx.axlsx

wb = xlsx_package.workbook
wb.add_worksheet(name: "Sites") do |sheet|

# Styles
styles = wb.styles
    header = styles.add_style(:bg_color => "282C87", :fg_color => 'FFFFFF')
    logo_image = styles.add_style alignment: {horizontal: :center}

img = File.expand_path(Rails.root+'public/images/mobile-logo.png')
name_img = File.expand_path('app/assets/images/name.png')
sheet.add_row [""],:height => 100
sheet.add_row ['SITE INFORMATION'], :height => 35
sheet.merge_cells("A1:L1")
sheet.merge_cells("A2:L2")

sheet.add_image(:image_src => img, :noSelect => true, :noMove => true, :style => logo_image) do |image|
      image.width=190
      image.height=90
end

sheet.add_image(:image_src => name_img, :noSelect => true, :noMove => true) do |image|
      image.width=600
      image.height=60
      image.start_at 2,0
end
 sheet.add_row ["ID", "Latitude", "Longitude", "Building Height", "Zoning Class", "State", "Town", "Zipcode", "County", "First Name", "Last Name", "Company Name"], :style => header
  @sites.each do |site|
    sheet.add_row [site.id, site.latitude, site.longitude, site.building_height, site.zoning_class, site.state, site.town, site.zipcode, site.county, site.first_name, site.last_name, site.company_name]
  end
end

1 个答案:

答案 0 :(得分:0)

是的,您可以添加行或列偏移量。像这样:

sheet.add_image(:image_src => img, :noSelect => true, :noMove => true, :style => logo_image) do |image|
    image.width=190
    image.height=90
    image.start_at 0, 0
    image.anchor.from.rowOff = 100000
    image.anchor.from.colOff = 100000
end