Rails Gem “Axlsx"/“Rails-Axlsx" - 添加图像 [英] Rails Gem “Axlsx” / “Rails-Axlsx” - Adding Image

查看:55
本文介绍了Rails Gem “Axlsx"/“Rails-Axlsx" - 添加图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将一张图片添加到我的工作簿/工作表中.

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

代码:

    wb.add_worksheet(:name => "Doc1", :page_setup => setup, :print_options => options) do |sheet|

        img = File.expand_path('../logo.jpg', __FILE__)
        sheet.add_image(:image_src => img, :noMove => true) do |image|
            image.width = 7
            image.height = 6
            image.start_at 2, 2
        end

    ...

    end

但是如果我打开文档,工作表上没有图像,我该如何解决?

But if i open the document there is no image on the worksheet, how can i fix this ?

图片的正确路径如何?对于这个测试,我将 jpg 复制到我的视图文件夹中,但通常是 "app/assets/images/logo.jpg" 中的所有图像.我用 img = File.expand_path('../assets/images/logo.jpg', __FILE__) 尝试它,但它失败了找不到文件!"

And how is the correct path to the image? For this test i copy the jpg in my view folder, but usually all images in "app/assets/images/logo.jpg". I try it with img = File.expand_path('../assets/images/logo.jpg', __FILE__), but it fails with "No file found!"

推荐答案

https://pramodbshinde.wordpress.com/2013/12/29/design-spreadsheets-using-axlsx-in-rails/ 显示以下代码行>

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')

这篇关于Rails Gem “Axlsx"/“Rails-Axlsx" - 添加图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆