public class CCWordApp
{
//it's a reference to the COM object of Microsoft Word Application
private Word.ApplicationClass oWordApplic;
// it's a reference to the document in use
private Word.Document oWordDoc;
// Activate the interface with the COM object of Microsoft Word
public CCWordApp();
// Open an existing file or open a new file based on a template
public void Open( string strFileName);
// Open a new document
public void Open( );
// Deactivate the interface with the COM object of Microsoft Word
public void Quit( );
// Save the document
public void Save( );
//Save the document with a new name as HTML document
public void SaveAs(string strFileName );
// Save the document in HTML format
public void SaveAsHtml(string strFileName );
// Insert Text
public void InsertText( string strText);
// Insert Line Break
public void InsertLineBreak( );
// Insert multiple Line Break
public void InsertLineBreak( int nline);
// Set the paragraph alignment
// Possible values of strType :"Centre", "Right", "Left", "Justify"
public void SetAlignment(string strType );
// Set the font style
// Possible values of strType :"Bold","Italic,"Underlined"
public void SetFont( string strType );
// Disable all the style
public void SetFont( );
// Set the font name
public void SetFontName( string strType );
// Set the font dimension
public void SetFontSize( int nSize );
// Insert a page break
public void InsertPagebreak();
// Go to a predefined bookmark
public void GotoBookMark( string strBookMarkName);
// Go to the end of document
public void GoToTheEnd( );
// Go to the beginning of document
public void GoToTheBeginning( );
打开一个存在的文件的代码将是这样的:
CCWordApp test ;
test = new CCWordApp();
test.Open ("c:\\database\\test.doc");
test.InsertText("This is the text");
test.InsertLineBreak;
test.Save ();
test.Quit();