2010-10-06 5 views
1

comment peut-on ouvrir un fichier word avec un numéro de page spécifique en c sharp? Comment ouvrir un fichier word avec un numéro de page précis?

C'est le code je pour ouvrir le fichier:

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; 
    } 
} 

Comment puis-je utiliser le code VbaSelection.GoTo What:=wdGoToPage, Which:=wdGoToFirst, Count:=3, Name:="" équivalent en C# pour obtenir la page que je veux? Ou d'autres suggestions?

Répondre

4

L'équivalent C# Interop serait:

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); 
Questions connexes