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

前端 未结 3 744
甜味超标
甜味超标 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: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
    

提交回复
热议问题