2011-01-28 90 views
0

我試圖使用ASP Classic自動在服務器上創建一些文字文件。它工作正常,但唯一的問題是,當我下載的文件沒有圖片在他們中,而是我得到像持有人的東西。這裏是我的代碼:在ASP文件中插入圖像

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

任何主意,有字的文件的圖片? 在此先感謝。

+0

看起來不錯。你確定圖片確實存在於該網址中嗎? – 2011-01-28 12:18:39

+0

@是的,圖像在那裏。只是它沒有嵌入到word文件中。 – Jay 2011-01-28 16:44:53

回答

2

好的,我做了這個答案是創建一個新的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文件,你可以節省只包括<v:shape>元素,而忽略了條件註釋一些空間和重複。

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