Adding image to Excel file generated by Axlsx.?

前端 未结 1 955
醉梦人生
醉梦人生 2021-01-24 23:49

I am using Axlsx for generating Excel file.

I need to add image to the Excel File. I have used this code :

ws.add_image(:image_src =>         


        
相关标签:
1条回答
  • 2021-01-24 23:53

    This looks correct to me as well, and is inline with the example in the gem.

    wb.add_worksheet(:name => "Image with Hyperlink") do |sheet|
      img = File.expand_path('../image1.jpeg', __FILE__)
      # specifying the :hyperlink option will add a hyper link to your image.
      # @note - Numbers does not support this part of the specification.
      sheet.add_image(:image_src => img, :noSelect => true, :noMove => true, :hyperlink=>"http://axlsx.blogspot.com") do |image|
        image.width = 7
        image.height = 6
        image.hyperlink.tooltip = "Labeled Link"
        image.start_at 2, 2
      end
    end
    

    There is a possibility that a bug was introduced in the version you are using.

    As we discussed on #axlsx, lets try this against master on github and if it does prove to be a bug in the version you are using, I'll push out a new release.

    Best,

    randym

    0 讨论(0)
提交回复
热议问题