我们如何打开具有特定页码的word文件?
这是我用来打开文件的代码:
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#
等效来获取我想要的页面?还是其他任何建议?
答案 0 :(得分:4)
等效的C#interop将是:
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);