| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 583 人关注过本帖
标题:c#与word的问题?
只看楼主 加入收藏
huangzhuo
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2006-10-30
收藏
 问题点数:0 回复次数:4 
c#与word的问题?
c#如何操作word?
搜索更多相关主题的帖子: word 
2006-12-21 16:29
moderndai
Rank: 1
等 级:新手上路
帖 子:104
专家分:0
注 册:2006-1-25
收藏
得分:0 

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编辑过]


ROCK AND ROCK PROGRAMING dai--yl@&&espricle@
2006-12-21 23:15
huangzhuo
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2006-10-30
收藏
得分:0 

如何将数据库的数据导入到word?

2006-12-22 08:44
moderndai
Rank: 1
等 级:新手上路
帖 子:104
专家分:0
注 册:2006-1-25
收藏
得分:0 

数据库操作呀


ROCK AND ROCK PROGRAMING dai--yl@&&espricle@
2006-12-22 10:20
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
写入到Word里面就行了.

飘过~~
2006-12-23 00:43
快速回复:c#与word的问题?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.031007 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved