将图像添加到由Axlsx生成的Excel文件。

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

我需要将图像添加到Excel文件。 我已经使用这个代码:

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=2000height=1000 ,它不会影响Excel文件中的图像。

有人可以告诉我,我做错了什么?

这对我来说也是正确的,并与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 

您正在使用的版本中可能会引入错误。

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

最好,

randym