如何在c#.net控制台应用程序中从word中获取特定页面?
我试过了,
但不幸的是,我的应用程序出错了。
以下是我的代码:
{
object what = WdGoToItem.wdGoToPage;
object which = WdGoToDirection.wdGoToFirst;
object count = 0;
const string fileName = @"C:\..\..\test.doc";
object fileNameAsObject = fileName;
Application wordApplication = new Application();
object readOnly = false;
object missing = System.Reflection.Missing.Value;
wordApplication.Documents.Open(ref fileNameAsObject, ref missing, ref readOnly, 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);
// here on this following line I have got error "This method or property is not available because this command is not available for reading."
Range startRange = wordApplication.Selection.GoTo(ref what, ref which, ref count, ref missing);
object count2 = (int)count + 1;
Range endRange = wordApplication.Selection.GoTo(ref what, ref which, ref count2, ref missing);
endRange.SetRange(startRange.Start, endRange.End);
endRange.Select();
;
}
所以请给我任何解决方案.. 提前致谢..
最佳答案
您使用的是 Office 2013 吗?针对新安装的 Office 2013 运行我们的互操作代码时,我们遇到了相同错误消息的问题。这似乎是由于提到的 Office 2013 的默认“阅读模式”here .
尝试通过将 Application.ActiveWindow.View.ReadingLayout
设置为 false 来关闭阅读模式(如文章评论中所述)。此调用必须在打开文档后执行。否则,调用将失败并显示消息:System.Runtime.InteropServices.COMException : This command is not available because no document is opened.
关于c# - 从 Word 获取特定页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21623865/