【问题标题】:Adding image to Excel file generated by Axlsx.?将图像添加到 Axlsx 生成的 Excel 文件中。?
【发布时间】:2012-05-23 05:53:03
【问题描述】:

我正在使用 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”和“height”。 即使我给width=2000height=1000,它也不会影响Excel文件中的图像。

谁能告诉我,我做错了什么?

【问题讨论】:

    标签: ruby image excel xlsx axlsx


    【解决方案1】:

    这对我来说也是正确的,并且与 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 进行尝试,如果它确实证明是您使用的版本中的错误,我将推出一个新版本。

    最好的,

    随意

    【讨论】:

    • 经过一番调查,这在 MS Excel 中可以正常工作,但在 Open Office Ubuntu 中却不行 - 是时候去挖掘差异了!
    • 供参考,OOXML 规范列出:20.5.2.14 ext(形状范围),其中包含 ST_PositiveCoordinate 类型的 cx 和 xy 属性
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-26
    • 2013-01-23
    • 2015-09-18
    • 1970-01-01
    相关资源
    最近更新 更多