none
Replacement for HTMLProject.HTMLProjectItems in Office 2007

    Question

  • Hi ,
         We are developing applications using the following tools
    Microsoft Dotnet platform(Framework 2.0).Microsoft SQL Server 2005 & Microsoft Office 2003 /2007.

    Operating System: Windows Vista

    We are experiencing an issue while converting the application from Office 2003 office 2007. The application is reading the data from the word template file and storing it in the SQL database with all the formats by converting to HTML using the HTMLProject object . Again we are reading the data from the database and displaying it in the Word files. With office 2003 we were able to do it successfully using the object HTMLProject . But with Office 2007 this feature is not available/supporting.

    Could you please suggest a better alternative for this.

    Thanks,
    Rajesh

    Wednesday, June 16, 2010 12:59 PM

Answers

  • Hi Rajesh

    The HTMLProject and the related round-trip Word HTML file format was never really supported or documented for the versions of Word in which it was supported.

    Since Word 2003, the XML file formats have supplanted HTML as the standard "open" file format. In office 2007 the Open XML Format was introduced.

    Depending on what these documents contain (text, graphics, other kinds of objects) you should be able to use the Range.XML or Range.WordOpenXML properties to get the document content from the opened document. Writing it back to a document is another proposition, entirely. Range.InsertXML works fine (and is the pendent to Range.XML) if you don't need anything that's new in Word 2007.

    If you need this in HTML, you'd need to run a Transform (XSLT) on the XML to convert it to HTML, and then back to WordProcessingML.

    The best place to get more information on this is OpenXMLDeveloper.org, plus the OpenXML SDK forum on these MSDN servers.


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Bessie Zhao Monday, June 21, 2010 7:36 AM
    Wednesday, June 16, 2010 5:46 PM
    Moderator
  • The thread http://social.msdn.microsoft.com/forums/en-us/vsto/thread/E798D6FC-6E0F-489F-9D87-4250096D4C60 also suggests saving the document as HTML by using Document.SaveAs and passing the WdSaveFormat.wdFormatHTML value to the FileFormat parameter.

    If you don't want to save a copy of the document, you could also try copying the document contents to the Clipboard and extracting the HTML by using GetDataObject (see http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/157f552d-1771-4adc-b5e0-e39acb52c5b3). Here's a brief code example for a Word Document project created using VSTO - note that this is not fully tested, and there might be better ways to do this, but this should illustrate the basic mechanics.

    Globals.ThisDocument.Select();
    Globals.ThisDocument.Application.Selection.Copy();
    Globals.ThisDocument.Application.Selection.Collapse();
    
    System.Windows.Forms.IDataObject dataObject = System.Windows.Forms.Clipboard.GetDataObject();
    if (dataObject != null && dataObject.GetDataPresent(System.Windows.Forms.DataFormats.Html))
    {
     string htmlText = (string)dataObject.GetData(System.Windows.Forms.DataFormats.Html);
     System.Windows.Forms.MessageBox.Show(htmlText);
    }

     


    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by Bessie Zhao Monday, June 21, 2010 7:36 AM
    Wednesday, June 16, 2010 6:13 PM

All replies

  • Hi Rajesh

    The HTMLProject and the related round-trip Word HTML file format was never really supported or documented for the versions of Word in which it was supported.

    Since Word 2003, the XML file formats have supplanted HTML as the standard "open" file format. In office 2007 the Open XML Format was introduced.

    Depending on what these documents contain (text, graphics, other kinds of objects) you should be able to use the Range.XML or Range.WordOpenXML properties to get the document content from the opened document. Writing it back to a document is another proposition, entirely. Range.InsertXML works fine (and is the pendent to Range.XML) if you don't need anything that's new in Word 2007.

    If you need this in HTML, you'd need to run a Transform (XSLT) on the XML to convert it to HTML, and then back to WordProcessingML.

    The best place to get more information on this is OpenXMLDeveloper.org, plus the OpenXML SDK forum on these MSDN servers.


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Bessie Zhao Monday, June 21, 2010 7:36 AM
    Wednesday, June 16, 2010 5:46 PM
    Moderator
  • The thread http://social.msdn.microsoft.com/forums/en-us/vsto/thread/E798D6FC-6E0F-489F-9D87-4250096D4C60 also suggests saving the document as HTML by using Document.SaveAs and passing the WdSaveFormat.wdFormatHTML value to the FileFormat parameter.

    If you don't want to save a copy of the document, you could also try copying the document contents to the Clipboard and extracting the HTML by using GetDataObject (see http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/157f552d-1771-4adc-b5e0-e39acb52c5b3). Here's a brief code example for a Word Document project created using VSTO - note that this is not fully tested, and there might be better ways to do this, but this should illustrate the basic mechanics.

    Globals.ThisDocument.Select();
    Globals.ThisDocument.Application.Selection.Copy();
    Globals.ThisDocument.Application.Selection.Collapse();
    
    System.Windows.Forms.IDataObject dataObject = System.Windows.Forms.Clipboard.GetDataObject();
    if (dataObject != null && dataObject.GetDataPresent(System.Windows.Forms.DataFormats.Html))
    {
     string htmlText = (string)dataObject.GetData(System.Windows.Forms.DataFormats.Html);
     System.Windows.Forms.MessageBox.Show(htmlText);
    }

     


    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by Bessie Zhao Monday, June 21, 2010 7:36 AM
    Wednesday, June 16, 2010 6:13 PM