问题
I am using Axlsx for generating Excel file.
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
where 'ws' is the worksheet.
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.?
回答1:
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.
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.
Best,
randym
来源:https://stackoverflow.com/questions/10714193/adding-image-to-excel-file-generated-by-axlsx