精华区 [关闭][返回]

当前位置:月光软件>>讨论区精华>>〖软件开发〗>>● ASP>>★ASP的延伸★>>ASP.NET>>Re:如何用ASP+读WORD文档

主题:Re:如何用ASP+读WORD文档
发信人: dongbao(似水流年ζ教皇)
整理人: dongbao(2001-05-27 09:17:29), 站内信件
【 在 ahata2001 的大作中提到:】
:在ASP+中怎样读取WORD文档,并把他存为HTML!!急急!
:......
 
找了一篇英文的文章,讲解如何用asp操作word。
其实应用于asp.net也是同样的道理

Here is a new tutorial on how to write to a word document, change the contents of a word document and print it out. There will also be an update to this one and the excel one with more things you can do. Most of it comes from the the microsoft office VB help. But you have to do some fiddling with the code to get the VBscript code.

First we set the type of script

<%@ LANGUAGE="VBSCRIPT" %>

Make the object, and set the object to a word document

Dim MyDoc
Set MyDoc = CreateObject("Word.Document")
MyDoc.Application.Visible = True

Now lets write the rest of the script, see the comments

' Set the font properties
MyDoc.content.Font.Bold = True
MyDoc.content.Font.Italic = True
MyDoc.content.Font.Underline = True
MyDoc.content.Font.Name = "Comic Sans MS"
MyDoc.content.Font.Size = 25


' Insert some text
MyDoc.content.insertAfter "word1 word2 word3 word4"
MyDoc.content.InsertParagraphAfter


' Now lets change the colors and fontsize of the induvidual words that were just added, just look closely to the opened word document and you will see it change dynamically
MyDoc.Words(1).Font.Size = 10
MyDoc.Words(1).Font.ColorIndex = 1
MyDoc.Words(2).Font.Size = 20
MyDoc.Words(2).Font.ColorIndex = 2
MyDoc.Words(3).Font.Size = 30
MyDoc.Words(3).Font.ColorIndex = 3
MyDoc.Words(4).Font.Size = 40
MyDoc.Words(4).Font.ColorIndex = 4


' Print the document
MyDoc.PrintOut
' Release the object variable.
Set MyDoc = Nothing 
%>


Now lets complete the HTML tags.

<HTML>
<HEAD>
<TITLE>Excelface</TITLE>
</HEAD>
<BODY>
</BODY>
</HTML>

This completes yer ASP page, look below for the complete code of mydoc.asp

<%@ LANGUAGE="VBSCRIPT" %>
<%
Dim MyDoc
Set MyDoc = CreateObject("Word.Document")
MyDoc.Application.Visible = True
MyDoc.content.Font.Bold = True
MyDoc.content.Font.Italic = True
MyDoc.content.Font.Underline = True
MyDoc.content.Font.Name = "Comic Sans MS"
MyDoc.content.Font.Size = 25
MyDoc.content.insertAfter "word1 word2 word3 word4"
MyDoc.content.InsertParagraphAfter
MyDoc.Words(1).Font.Size = 10
MyDoc.Words(1).Font.ColorIndex = 1
MyDoc.Words(2).Font.Size = 20
MyDoc.Words(2).Font.ColorIndex = 2
MyDoc.Words(3).Font.Size = 30
MyDoc.Words(3).Font.ColorIndex = 3
MyDoc.Words(4).Font.Size = 40
MyDoc.Words(4).Font.ColorIndex = 4
MyDoc.PrintOut
Set MyDoc = Nothing
%>
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
</BODY>
</HTML>



----

ICQ:43395237 OICQ:126132(read-only)    
我自豪我用正版,我骄傲我用盗版!!!

[关闭][返回]






转载请注明:转载自 月光程序代码网 [ http://www.moon-soft.com ]