在ASP中的Word文件中插入图像 [英] Insert image in word file in ASP

查看:81
本文介绍了在ASP中的Word文件中插入图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ASP Classic在服务器上自动制作一些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)

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

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文件中添加图片的想法? 预先感谢.

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

推荐答案

好吧,要得到这个答案,我要做的是创建一个新的Word文档(使用Word 2010),从硬盘中插入图片,然后保存该文件为HTML文件.然后,我查看了结果页面,并试图解构Word所做的事情.我发现的是,除了HTML <img>标记外,Word还创建了一个<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]>

如果将此文件作为.doc文件提供,则可以通过仅包含<v:shape>元素并省略条件注释来节省一些空间和重复项.

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>

这篇关于在ASP中的Word文件中插入图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆