Rails Gem “Axlsx” / “Rails-Axlsx” - Adding Image

前端 未结 3 745
甜味超标
甜味超标 2021-01-28 11:57

I try to add one image to my workbook/worksheet.

The Code :

    wb.add_worksheet(:name => \"Doc1\", :page_setup => setup, :print_options => opt         


        
相关标签:
3条回答
  • 2021-01-28 12:49

    An example on https://pramodbshinde.wordpress.com/2013/12/29/design-spreadsheets-using-axlsx-in-rails/ show the following line of code

    img = File.expand_path(Rails.root+'app/assets/images/result.png')
    
    0 讨论(0)
  • 2021-01-28 12:52

    In the lines where you set the image width and height you have them very small and you could be overlooking the image as this number is in pixels. Try setting them to higher number.

    the following worked for me:

    img = File.expand_path(Rails.root+'app/assets/images/result.png')
            sheet.add_image(:image_src => img, :noMove => true) do |image|
                image.width = 100
                image.height = 150
                image.start_at 2, 2
            end
    
    0 讨论(0)
  • 2021-01-28 13:00

    Here is another way you can achieve this:

    Code:

    img = File.open(Dir.glob("#{Rails.root}/app/assets/images/result.png, "r")
    
    0 讨论(0)
提交回复
热议问题