求教了C#里调用WORD2003文档,文档里有文本框取值不到
求教了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);
}