思路总结:
1. 工程中添加引用-->Com-->Microsoft Word 10.0。
2. Dcomcnfg-->ms Word -->Security--> Launch and Activation Permission ; Access Permission-->customize-->add Asp.net or Everyone and set Permission.
3. 编码.在www.codeproject.com 上有个Word Test Application例子可以参考。以下是相关的类和方法:
|
CCWord Class
|
|
Private Members
|
|
|
private Word.ApplicationClass WordApplic
|
it's a reference to the COM object of Microsoft Word Application
|
|
|
private Word.Document oDoc
|
it's a reference to the document in use
|
|
Public functio
|
|
|
CCWordApp ()
|
Activate the interface with the COM object of Microsoft Word
|
|
|
Open ()
|
Open a new document
|
|
|
Open (string strFileName)
|
Open an existing file or open a new file based on a template
|
|
|
Quit ()
|
Deactivate the interface with the COM object of Microsoft Word
|
|
|
Save ()
|
Save the document
|
|
|
SaveAs(string strFileName)
|
Save the document with a new name
|
|
|
CCWordApp SaveAsHtml(string strFileName)
|
Save the document with a new name as HTML document
|
|
|
InsertText( string strText)
|
Insert text
|
|
|
InsertLineBreak( )
|
Insert Line Break
|
|
|
InsertLineBreak( int nline)
|
Insert multiple Line Break
|
|
|
SetAlignment(string strType )
|
Set the paragraph alignement. Possible values of strType : "Center", "Right", "Left", "Justfy".
|
|
|
SetFont( string strType )
|
Set the font style. Possible values of strType : "Bold","Italic,"Underlined".
|
|
|
SetFontName( string strType )
|
Set the font name.
|
|
|
SetFontSize( int nSize )
|
Set the font dimension.
|
|
|
InsertPagebreak()
|
Insert a page break.
|
|
|
GotoBookMark(string strBookMarkName)
|
Go to a specific bookmark.
|
|
|
GoToTheEnd( )
|
Go to the end of document.
|
|
|
GoToTheBeginning( )
|
Go to the beginning of document.
|
|