none
VSTO : How to convert content control WordOpenXML to Html format ? RRS feed

  • Question

  • Hi,

    I want to convert WordOpenXML to Html in content control . I am using VSTO. I have tried with Clipboard see the following code

    contentControl.Range.Copy();

    if (Clipboard.ContainsData(DataFormats.Html))
    {

    string enclosedHTML = Clipboard.GetText(TextDataFormat.Html);

    Clipboard.Clear();


    }

    But some time the above code is throws an  following exception

    System.Runtime.InteropServices.COMException (0x800401D0): OpenClipboard Failed (Exception from HRESULT: 0x800401D0 (CLIPBRD_E_CANT_OPEN))

    at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
       at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
       at System.Windows.Clipboard.GetDataObjectInternal()
       at System.Windows.Clipboard.GetDataInternal(String format)
       at System.Windows.Clipboard.GetText(TextDataFormat format)

    Is there another way to convert in to Html or any solution on above exception?


    • Edited by VBPP Monday, April 1, 2013 2:46 PM
    Monday, April 1, 2013 2:43 PM

Answers

  • It would probably be better to take this question to OpenXMLDeveloper.org. As you're not using the VSTO technology you're not going to find people here who can help you much further.

    FWIW I can tell you that the Open XML on the Clipboard is going to be in the OPC flat file format, meaning it will be "pure" XML rather than a ZIP package. That should make it easier to work with for your purpose, but you will need to write your own "transform" to deal with the "richness" of a complete Word document.

    Or you can, perhaps, find a third-party product from a company like Aspose. These will be expensive because, as you can see, this is not a simple thing to do. The question will be whether it will cost you more to figure out the code on your own...


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, April 8, 2013 7:19 AM
    Moderator

All replies

  • Hi VBPP,

    Your request: I want to convert WordOpenXML to Html in content control.

    I cannot see any thing related to OpenXML in your code.

    If you mean it, you can refer to Conversion of OpenXML (WordProcessingML) to HTML using XSLT : Part 1

    OpenXML to HTML (Again and Again)

    HTH


    with regards, Yuri

    Tuesday, April 2, 2013 2:38 PM
  • Hi Yuri,

    Thanks for reply.

     Actually I am using Rich Text control in VSTO . The following code line copy WordOpenXML into to clipboard

    richTextControl.Range.Copy(); (I cannot see any thing related to OpenXML in your code(Yuri))

    I had tried with link which is given by you here 

     but this XSLT is not worked with rich text WordOpenXML when WordOpenXML contains hyperlink,images, chart etc .

    Friday, April 5, 2013 9:55 AM
  • It would probably be better to take this question to OpenXMLDeveloper.org. As you're not using the VSTO technology you're not going to find people here who can help you much further.

    FWIW I can tell you that the Open XML on the Clipboard is going to be in the OPC flat file format, meaning it will be "pure" XML rather than a ZIP package. That should make it easier to work with for your purpose, but you will need to write your own "transform" to deal with the "richness" of a complete Word document.

    Or you can, perhaps, find a third-party product from a company like Aspose. These will be expensive because, as you can see, this is not a simple thing to do. The question will be whether it will cost you more to figure out the code on your own...


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, April 8, 2013 7:19 AM
    Moderator