Is it possible to use the OpenXml API to open a document file in a specific spot, like, for instance, in specific comment location, with the default application to open .docx files (or other application if specified)? I know you can use either Microsoft.Office.Interop.Word
to open a word file or the Process.Start
, but I need to open the document in a specific location.
It is not possible. Explanation given in the following MSDN forum thread:
As far as I know, you could not open a word application with Open XML SDK, Open XML SDK is used to operate the data which stored in the file. I suggest you use Word automation to open a word file.
I think you could create a bookmark named as “B1” in the position of the comment, you then use “word.Selection.GoTo(WdGoToItem.wdGoToBookmark,Type.Missing,Type.Missing,"B1");” to go to the comment after you open the file. A simple code as below:
public static void goToBookMark() { Word.Application word = new Word.Application(); word.Documents.Open(@"D:\OfficeDev\Word\Edward.docm",true); word.Visible = true; word.Selection.GoTo(WdGoToItem.wdGoToBookmark,Type.Missing,Type.Missing,"B1"); }
For more information about Selection.GoTo, you could refer the link below:
Selection.GoTo method: https://msdn.microsoft.com/en-us/library/office/microsoft.office.interop.word.selection.goto(v=office.15).aspx