在C#的例子中就有,你如果安装了VS.net的话,你可以在帮助里找到这个例子。
解决方案 »
- 关于 jquery ajax 传接送格式 到 webservice 的问题!!!!
- 自定义控件如何才在设计模式下修改当前代码?
- 求教notifyIcon1 托盘单击最小化按钮 未知退出系统
- C#中窗体转到代码快捷键是什么呢?
- picturebox控件paint事件
- C#:当HTML代码中含数学符号时的过滤问题
- 哪位能完整写出一个WPF显示数据库表的应用,送100分!
- 使用datagrid修改数据之后,保存时遇到“并发冲突”
- 直接刪除dataGrid中的數據 而不是對他的數據源進行操作 下面為何報錯 可正確編譯 但無法執行 怪哉啦!
- 我想请教个问题
- 我用c#调用其他厂家的DLL总是不成,大家帮忙看看
- 如何获得文件的扩展名描述?例如:在资源管理器中 .cs 的类型显示为:C# Source file
Process.Start("c:\\*.doc");
就可以用word打开要编辑的文件
能不能说得详细些呢?谢谢
有没有中文的?..:(
{
Object Nothing=System.Reflection.Missing.Value;
object filename=@"c:\test.doc"; Word.Application wordApp=new Word.ApplicationClass();
Word.Document wordDoc=wordApp.Documents.Open(ref filename,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing);
this.textBox1.Text+="\r\n"+wordDoc.Paragraphs.Last.Range.Text.ToString();
this.textBox1.Text+="\r\n"+wordDoc.Tables.Item(1).Cell(1,1).Range.Text.ToString(); wordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
}private void menuItem3_Click(object sender, System.EventArgs e)
{
Object Nothing=System.Reflection.Missing.Value;
object filename=@"c:\test.doc"; Word.Application wordApp=new Word.ApplicationClass();
Word.Document wordDoc=wordApp.Documents.Add(ref Nothing,ref Nothing,ref Nothing,ref Nothing);
Word.Table table=wordDoc.Tables.Add(wordApp.Selection.Range,2,3,ref Nothing,ref Nothing);
table.Cell(1,1).Range.Text="1892730987098";
wordDoc.Paragraphs.Last.Range.Text="Hello"; wordDoc.SaveAs(ref filename,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing,ref Nothing);
wordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
}在这段例子里面,menuItem3_Click()函数新建了一个Word文档,并在里面插入了一个表格和一段文字。表格的大小是两行三列,最左上的cell里面的内容是"1892730987098",后面一段文字的内容是"Hello"。其大致如下:+---------------+--------------+--------------+
| 1892730987098 | | |
+---------------+--------------+--------------+
| | | |
+---------------+--------------+--------------+
Hello上面的例子代码中,menuItem2_Click()完成的工作就是打开上面创建的Word文档,并读取表格的第一个cell的内容以及下面一段文字的内容,然后将其显示在this.textBox1中。您可以试试看上面这段例子代码,运行前需要在项目的Reference里面添加Microsoft Word 10.0 Object Library。
Word.ApplicationClass oWord = new Word.ApplicationClass();
Word.Document oDoc;
Word.Range oRange;
Word.Table otable;
Word.Selection oselection;
object a = Missing.Value;
object b = Missing.Value;
object filename=@"c:\test.doc";
oDoc = oWord.Documents.Open(ref filename,ref a,ref a,ref a,ref
//or oDoc = oWord.Documents.Add(ref a,ref a,ref a,ref a);
a,ref a,ref a,ref a,ref a,ref a,ref a,ref a);
oWord.Visible = true;
oDoc = oWord.ActiveDocument
oRange = oDoc.Range(ref a,ref b);
oRange.Rows.Count = 9;
oRange.Select;
xx =oRange.Text;
otable = oDoc.Tables.Item(1);
otable.Select;
yy = otable.Cell(0,1).Range.Text;
太感谢了!!我下去试试,等一下给你回话:)