将图像添加到Axlsx生成的Excel文件中。 [英] Adding image to Excel file generated by Axlsx.?

查看:178
本文介绍了将图像添加到Axlsx生成的Excel文件中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Axlsx 生成Excel文件。

I am using Axlsx for generating Excel file.

我需要将图像添加到Excel文件中。我使用过这段代码:

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

ws.add_image(:image_src => '../something',:noSelect => true, :noMove => true) do |image|
  image.width=1000
  image.height=200
  image.start_at 0,0
end

其中' ws '是工作表。

它添加了所需的图像,但我我无法设置'宽度'&使用此代码的图像的高度
即使我给 width = 2000 height = 1000 ,它也不会影响Excel中的图像文件。

It adds the required image, but i am not able to set the 'width' & 'height' of the image with this code. Even if i give width=2000 and height=1000, it does not affect the image in Excel file.

任何人都可以告诉我,我做错了什么。?

Can anybody tell , what i doing wrong.?

推荐答案

这对我来说也是正确的,并且与gem中的示例内联。

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.

正如我们在#axlsx上讨论的那样,让我们​​在github上对master进行尝试,如果它确实是你正在使用的版本中的一个bug,我会推出新版本。

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.

最佳,

randym

这篇关于将图像添加到Axlsx生成的Excel文件中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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