【问题标题】:How to add an image to word document and download using grails?如何使用grails将图像添加到word文档并下载?
【发布时间】:2014-06-16 21:04:44
【问题描述】:

我使用下面的代码直接下载图片,但我需要将它放在word doc中并想下载文档。

        response.contentType = "application/octet-stream"
        response.setHeader("Content-disposition", "attachment;filename=image.jpg")
        response.outputStream << inputstream
        response.outputStream.flush()

谁能知道如何使用 grails 将图像添加到 word 文档并下载?

感谢任何帮助。 谢谢

【问题讨论】:

  • 我猜 Apache POI 将允许您将图像添加到 word doc poi.apache.org
  • 谢谢,但我找到了解决方案。

标签: grails doc


【解决方案1】:

正如 Dónal 所建议的,Apache POI 可能是一个解决方案。但您也可能想尝试以下方法:

  • 使用图片创建 Word 文档
  • 另存为xml
  • 在 grails 中创建一个这样的 xml 文档并用你自己的替换图像
  • 通过内容类型为“application/msword”的 grails 传递它

至少这适用于 excel 文件...

【讨论】:

  • 谢谢,但我想要的是 microsoft word,我已经找到了解决方案。
  • 您愿意与我们分享您的解决方案吗?
  • 我做到了。无论如何,谢谢。
【解决方案2】:
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-03
  • 2012-06-16
  • 1970-01-01
相关资源
最近更新 更多