我们如何在cSharp中打开具有特定页码的word文件? [英] how can we open a word file with specific page number in c sharp?
本文介绍了我们如何在cSharp中打开具有特定页码的word文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何打开指定页码的word文件?
How can we open a word file with specific page number?
这是我用来打开文件的代码:
This is the the code I used to open the file:
public static Application Open(string fileName)
{
object fileNameAsObject = (object)fileName;
Application wordApplication;
try
{
wordApplication = new Application();
object readnly = false;
object missing = System.Reflection.Missing.Value;
wordApplication.Documents.Open(ref fileNameAsObject, ref missing, ref readnly);
return wordApplication;
}
catch (Exception ex)
{
LogEntry log = new LogEntry();
log.Categories.Add("Trace");
log.Message = ex.ToString();
Logger.Write(log, "Trace");
throw new System.IO.FileLoadException("File cannot be opened");
}
finally
{
wordApplication = null;
}
}
我如何使用 Vba
代码 Selection.GoTo What:=wdGoToPage, which:=wdGoToFirst, Count:=3, Name:=""
在 C#
获取我想要的页面?或者有什么其他建议?
How can I use the Vba
code Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst, Count:=3, Name:=""
equivalent in C#
to get the page that I want? Or any other suggestions?
推荐答案
等效的 C# 互操作是:
The equivalent C# interop would be:
object what = Microsoft.Office.Interop.Word.WdGoToItem.wdGoToPage;
object which = Microsoft.Office.Interop.Word.WdGoToDirection.wdGoToFirst;
object count = 3;
wordApplication.Selection.GoTo(ref what, ref which, ref count, ref missing);
这篇关于我们如何在cSharp中打开具有特定页码的word文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文