我有一个文本段落以及表格的文档。我想搜索一个文本以“此法已更新到”开头的表格。该表有一个单元格。第1行,第1列。如何使用代码找到此表。不熟悉使用表格和单词互操作。谢谢。Word互操作使用表
0
A
回答
1
我已经部分地从我的项目之一 复制这个例子(更换/删除一些代码 - 因此它可能包含语法错误),但如果你已经与互操作和早期绑定工作 - 这可能是有益的
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;
}
}
0
NetOffice有东西可以为您提供。另一种解决方案是将您的word文件保存为HTML格式,然后使用HTML Agility Pack。
相关问题
- 1. 使用互操作.word用asp.net
- 2. 使用互操作
- 3. MS Word互操作C#RPC_E_SERVERCALL_RETRYLATER错误
- 4. 歧义在Word中互操作代码
- 5. 从Word中互操作使用C#中TCSCConverter
- 6. 灌装领域使用C#和Microsoft Word互操作
- 7. 从资源中使用互操作词打开Word模板
- 8. Word自动化使用微软Word互操作为一个Web应用程序没有交互式用户
- 9. Word 2010中的互操作:编辑word文档页眉
- 10. 互操作 - 阻止表包装两页Word中
- 11. C#Office Word中互操作得到的表格样式
- 12. C#互操作使用Ghostscript
- 13. InvalidComObjectException使用Excel互操作
- 14. 创建使用互操作
- 15. Word 2010使用VBA操作目录
- 16. 使用C#操作Word文档
- 17. 使用互操作或vsto向Word添加消息栏或信息栏
- 18. Powerpoint互操作
- 19. 互操作性
- 20. Word 2010 VBA - 操作编号列表
- 21. 转换Word互操作对象为byte [],不保存物理
- 22. 如何正确关闭/终止WINWORD.EXE/Word互操作?
- 23. Word互操作单元格自定义文本选择
- 24. C#互操作Word中插入文件,而无需更换
- 25. 如何关注通过互操作打开的Word文档?
- 26. Word互操作 - 只处理页眉和页脚一次
- 27. “80040154类没有注册”与C#的Word互操作#
- 28. WCF:是否使用WsHttpBinding可互操作?
- 29. 使用互操作的构造(Clojure的)
- 30. CryptoAPI C++使用AES与Java互操作