【问题标题】:Insert image in word file in ASP在 ASP 中的 word 文件中插入图像
【发布时间】:2015-02-25 08:33:14
【问题描述】:

我正在尝试使用 ASP Classic 在服务器上自动制作一些 word 文件。它工作正常,但唯一的问题是当我下载文件时,其中没有图片,而是我得到了类似占位符的东西。这是我的代码:

set fso = createobject("scripting.filesystemobject")
Set act = fso.CreateTextFile(server.mappath("/") & file_being_created, true)

act.WriteLine("<html xmlns:v=""urn:schemas-microsoft-com:vml""")
act.WriteLine("xmlns:o=""urn:schemas-microsoft-com:office:office""")
act.WriteLine("xmlns:w=""urn:schemas-microsoft-com:office:word""")
act.WriteLine("xmlns:m=""http://schemas.microsoft.com/office/2004/12/omml""")
act.WriteLine("xmlns:css=""http://macVmlSchemaUri"" xmlns=""http://www.w3.org/TR/REC-html40"">")
act.WriteLine("<title>testing</title>")
act.WriteLine("<body> " )
act.WriteLine("<img src='http://mysite.com/images/pic.jpg' width='800' height='200'/><br />" )
act.WriteLine(rsInvoices("invoiceClientID") & "<br />" )
act.WriteLine(rsInvoices("invoiceNumber") )
act.WriteLine("</body></html>")"
act.close

有什么想法可以在word文件中添加图片吗? 提前致谢。

【问题讨论】:

  • 看起来不错。您确定该图片确实存在于该网址中吗?
  • @是的,图片在那里。只是它没有嵌入到 word 文件中。
  • 在此代码中,您链接到图像,而不是嵌入图像。我的建议是生成一个 PDF 文件,它更容易,而且你有很多开源组件和资源来做。​​

标签: asp-classic ms-word


【解决方案1】:

好的,我为得到这个答案所做的是创建一个新的 Word 文档(使用 Word 2010),从我的硬盘插入一张图片,然后将文件保存为 HTML 文件。然后我查看了生成的页面并尝试解构 Word 正在做什么。我发现除了 HTML <img> 标记之外,Word 还创建了一个 <v:shape> 元素,被 conditional comment 隐藏。这是我根据您的示例提出的:

<!--[if gte vml 1]>
<v:shape id="Picture1" style="width:800px;height:200px;">
 <v:imagedata src="http://mysite.com/images/pic.jpg"/>
</v:shape>
<![endif]-->
<![if !vml]>
<img src='http://mysite.com/images/pic.jpg' width='800' height='200' v:shapes="Picture1"/>
<![endif]>

如果您将此文件作为 .doc 文件提供,您可以通过仅包含 &lt;v:shape&gt; 元素并省略条件 cmets 来节省一些空间和重复内容。

<v:shape id="Picture1" style="width:800px;height:200px;">
 <v:imagedata src="http://mysite.com/images/pic.jpg"/>
</v:shape>

【讨论】:

  • @Thanks Cheran,这是可以带图片的。唯一的问题是,当您在线时,您可以看到图片,否则不会。那是因为你从word文件里面的链接中看到了图片。
  • @Jay,没错。我确实尝试使用 binData 元素嵌入图像,如here 所述,但至少在 Word 2010 中,这显然只适用于 XML 文件而不适用于 HTML。到目前为止,我还没有找到一种将图像嵌入 HTML 以便 Word 理解的方法。
猜你喜欢
  • 1970-01-01
  • 2020-09-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-21
  • 2011-07-20
  • 1970-01-01
  • 2010-09-26
相关资源
最近更新 更多