OFFICE 编程希望对你有用
private Word.ApplicationClass oWordApplic; // a reference to Word application
private Word.Document oDoc; // a reference to the documentpublic CCWordApp()
{
// activate the interface with the COM object of Microsoft Word
oWordApplic = new Word.ApplicationClass();
}
// Open a file (the file must exists) and activate it
public void Open( string strFileName)
{
object fileName = strFileName;
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
object format = Word.WdOpenFormat.wdOpenFormatWebPages;
oDoc = oWordApplic.Documents.Open(ref fileName, ref missing,ref readOnly,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref format, ref missing, ref isVisible, ref missing, ref missing, ref missing);
oDoc.Activate();
}
// Open a new document
public void Open( )
{
object missing = System.Reflection.Missing.Value;
oDoc = oWordApplic.Documents.Add(ref missing, ref missing,ref missing, ref missing);
oDoc.Activate();
}
public void Quit( )
{
object missing = System.Reflection.Missing.Value;
oWordApplic.Application.Quit(ref missing, ref missing, ref missing);
}
public void Save( )
{
oDoc.Save();
}
public void SaveAs(string strFileName )
{
object missing = System.Reflection.Missing.Value;
object fileName = strFileName;
object format = Word.WdSaveFormat.wdFormatDocument;
oDoc.SaveAs(ref fileName, ref format, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing,ref missing,ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
}
// Save the document in HTML format
public void SaveAsHtml(string strFileName )
{
object missing = System.Reflection.Missing.Value;
object fileName = strFileName;
object Format = (int)Word.WdSaveFormat.wdFormatHTML;
oDoc.SaveAs(ref fileName, ref Format,ref missing, ref missing,ref missing,ref missing,ref missing,
ref missing,ref missing,ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
}
public void InsertText( string strText)
{
oWordApplic.Selection.TypeText(strText);
}
public void InsertLineBreak( )
{
oWordApplic.Selection.TypeParagraph();
}
public void InsertLineBreak( int nline)
{
for (int i=0; i<nline; i++)
oWordApplic.Selection.TypeParagraph();
}
[此贴子已经被作者于2006-12-21 23:18:09编辑过]