敛于心,勤于行

我是一粒沙,不羁的风任我在技术的天空遨游
  博客园  :: 首页  :: 新随笔  :: 管理

利用C#配合word模板生成word文档

Posted on 2006-11-01 14:18  大漠狂沙  阅读(931)  评论(0)    收藏  举报

思路总结:
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.