none
Open html file by Word.Application.Documents.Open() without run microsoft word ? RRS feed

  • Question

  • Hi there. I should open the html file to do some thing by Word but it run Microsoft Word too.Here my code:

     Word.Application oWord = new Word.Application();
     Word.Document doc1;            
    
    oWord.Visible = false;
                // oWord.Windows[1].Visible = false;
                //oWord.ActiveWindow.Visible = false;
                object objConfirmConversions = false;// false;
                object objReadOnly = false;
                object objAddToRecentFiles = false;
                object objPasswordDocument = missing;
                object objPasswordTemplate = missing;
                object objRevert = false;
                object objWritePasswordDocument = missing;
                object objWritePasswordTemplate = missing;
                object objFormat = missing;//missing;
                object objEncoding = missing;
                object objVisible = false;
                object objOpenAndRepair = false;
                object objDocumentDirection = false;
                object objNoEncodingDialog = missing;
                object objXMLTransform = missing;
    
    
    
                doc1 = oWord.Documents.Open(tempPath + "statictis.html",
                                                      ref objConfirmConversions,
                                                      ref objReadOnly,
                                                      ref objAddToRecentFiles,
                                                      ref objPasswordDocument,
                                                      ref objPasswordTemplate,
                                                      ref objRevert,
                                                      ref objWritePasswordDocument,
                                                      ref objWritePasswordTemplate,
                                                      ref objFormat, ref objEncoding,
                                                      ref objVisible,
                                                      ref objOpenAndRepair,
                                                      ref objDocumentDirection,
                                                      ref objNoEncodingDialog,
                                                      ref objXMLTransform);

    Thanks.

    • Moved by Cindy Meister MVPModerator Monday, July 16, 2012 7:49 AM not using VSTO technology (From:Visual Studio Tools for Office)
    Sunday, July 15, 2012 9:36 AM

Answers

  • If you need to "calculate the page" (I'm assuming you want to know what is on one page and what on another) then you have no choice but to open the file in Word. Only the Word application can calculate page layout. It's a complex interaction of formatting settings, page layout factors and the printer driver installed on the machine. There is no other way to get page information for a Word document.

    Cindy Meister, VSTO/Word MVP

    Monday, July 16, 2012 3:16 PM
    Moderator

All replies

  • Hi se7enbit,

    Thanks for posting in the MSDN Forum.

    I think it will hard to approach if you use Word PIA(Primary Interop Assembly) . I would reommend you handler your issue via FileStream or StringRead/StringWrite due to html is a simple text file in fact if you don't want to use Word.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Monday, July 16, 2012 6:51 AM
    Moderator
  • Hi se7enbit,

    Thanks for posting in the MSDN Forum.

    I think it will hard to approach if you use Word PIA(Primary Interop Assembly) . I would reommend you handler your issue via FileStream or StringRead/StringWrite due to html is a simple text file in fact if you don't want to use Word.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Thanks for reply. My issue is using Word to calculate the page. So have another way to calculate the page without using this?
    Monday, July 16, 2012 1:03 PM
  • If you need to "calculate the page" (I'm assuming you want to know what is on one page and what on another) then you have no choice but to open the file in Word. Only the Word application can calculate page layout. It's a complex interaction of formatting settings, page layout factors and the printer driver installed on the machine. There is no other way to get page information for a Word document.

    Cindy Meister, VSTO/Word MVP

    Monday, July 16, 2012 3:16 PM
    Moderator