首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Word互操作使用表

问Word互操作使用表
EN

Stack Overflow用户
提问于 2013-07-05 16:29:30
回答 2查看 9.8K关注 0票数 0

我有一个word文档与文本段落以及表格。我想搜索一个文本以"This Act has been update to“开头的表。该表有一个单元格。第1行,第1列。如何使用代码查找此表。不熟悉使用表格和word interop。谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-07-05 17:08:24

我已经从我的一个项目中部分复制了这个示例(替换/删除了一些代码-因此它可能包含语法错误),但如果您已经在使用互操作和早期绑定-它可能会有所帮助

代码语言:javascript
复制
using Word = Microsoft.Office.Interop.Word;

var wordApplication = new Word.Application();
var filename = "C:\test.doc";
Word.Application wordApp = null;

if (wordApplication != null)
    wordApp = wordApplication as Word.ApplicationClass;

Word.Document wordDoc = null;
if (File.Exists(fileName.ToString()) && wordApp != null)
        {
            object readOnly = isReadonly;
            object isVisible = true;
            object missing = System.Reflection.Missing.Value;
            wordDoc = wordApp.Documents.Open(ref fileName, ref missing,
                                             ref readOnly, ref missing, ref missing, ref missing,
                                             ref missing, ref missing, ref missing, ref missing,
                                             ref missing, ref isVisible, ref missing, ref missing, ref missing,
                                             ref missing);
        }

Word.Document wordDocument = wordDoc as Word.Document;
int tablecount = wordDocument.Tables.Count;
wordDocument.Activate();
for (int i = 1; i <= tablecount; i++)
{
Word.Table wTable = wordDocument.Tables[i];
Word.Cell pCell = wTable.Cell(1, 1);
if (pCell.Range.Text == "This Act has been update to") 
    {
        MessageBox.Show("Bingo !!!");
        break;
    }
}
票数 4
EN

Stack Overflow用户

发布于 2013-07-05 16:40:56

NetOffice有一些东西要提供给你。另一种解决方案是将word文件保存为HTML格式,然后使用HTML Agility Pack。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17484422

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档