求教了C#里调用WORD2003文档,文档里有文本框取值不到

nightyoung 2009-03-06 05:43:53
求教了C#里调用WORD2003文档,文档里有文本框取值不到。有谁能帮一下忙。找了一个下午没有结果,看过了MSDN上的只写怎么添加。
代码如下:

ApplicationClass cls = null;
Document doc = null;
Microsoft.Office.Interop.Word.Table table = null;
object missing = System.Reflection.Missing.Value;
int rowIndex = 2, colIndex =3 ;

object path = @"C:\a.doc";
object textbox = "\\Textbox1";
cls = new ApplicationClass();
cls.Visible = true;
try
{
doc = cls.Documents.Open(ref path, 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, ref missing);

table = doc.Tables[1];
string text = table.Cell(rowIndex, colIndex).Range.Text;
ultraTextEditor1.Text =doc.Shapes.get_Item(ref textbox).TextFrame.TextRange.Text;//怎么取道textbox的值//text.Substring(0, text.Length - 2); //去除尾部的mark
}
catch (Exception ex)
{
if (ex is System.Runtime.InteropServices.COMException)
{
MessageBox.Show(((System.Runtime.InteropServices.COMException)(ex)).ErrorCode.ToString());
}
}
finally
{
if( doc != null ) doc.Close(ref missing, ref missing, ref missing);
cls.Quit(ref missing, ref missing, ref missing);
}
...全文
88 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
nightyoung 2009-03-07
  • 打赏
  • 举报
回复
up
nightyoung 2009-03-06
  • 打赏
  • 举报
回复
up
nightyoung 2009-03-06
  • 打赏
  • 举报
回复
http://download.csdn.net/source/1076803,用到的WORD文档

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧