在ASP中将图像插入word文件

发布于 2024-10-15 03:09:38 字数 1140 浏览 4 评论 0原文

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

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

act.WriteLine("
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/oml""")
act.WriteLine("xmlns:css=""http://macVmlSchemaUri"" xmlns=""http://www.w3.org/TR/REC-html40"">")
act.WriteLine("测试")
act.WriteLine(" ")
act.WriteLine("
>" )< /代码>
act.WriteLine(rsInvoices("invoiceClientID") & "
" )

act.WriteLine(rsInvoices("invoiceNumber") )
act.WriteLine("")"
act.close

你知道在Word文件中添加图片吗? 提前致谢。

Im trying to automatically make some word file on server using ASP Classic. It works fine but the only problem is when I download the files there is no picture in them instead I get something like place holder. Here is my code:

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

Any idea to have picture in word file?
Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只等公子 2024-10-22 03:09:38

好的,为了得到这个答案,我所做的就是创建一个新的 Word 文档(使用 Word 2010),插入硬盘中的图片,然后将该文件另存为 HTML 文件。然后我查看了生成的页面并尝试解构 Word 正在做什么。我发现除了 HTML 标记之外,Word 还创建了一个 元素,该元素被 条件注释。以下是我根据您的示例得出的结论:

<!--[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 文件提供,则可以通过仅包含 元素和省略有条件的评论。

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

Okay, what I did to get to this answer was to create a new Word document (using Word 2010), insert a picture from my hard drive, then save the file as an HTML file. Then I looked at the resulting page and tried to deconstruct what Word was doing. What I found was that in addition to the HTML <img> tag, Word also created a <v:shape> element, hidden by a conditional comment. Here is what I came up based on your example:

<!--[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]>

If you're serving this file as a .doc file, you could save some space and duplication by only including the <v:shape> element and leaving out the conditional comments.

<v:shape id="Picture1" style="width:800px;height:200px;">
 <v:imagedata src="http://mysite.com/images/pic.jpg"/>
</v:shape>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文