none
Microsoft.Office.Interop.Word.Document.SaveAs

    Question

  • Hi all,

    I am not sure if I am posting in the right forum, but here it goes.

    I have an ASP.NET application that uploads Word documents and converts them to HTML and XML using the Microsoft.Office.Interop.Word.Document.SaveAs method.

    To convert to HTML I use the following code:
    Code Snippet

    Protected missing As Object = System.Reflection.Missing.Value
    Dim oDoc As Microsoft.Office.Interop.Word.Document = objWord.ActiveDocument
    oDoc.SaveAs(FileToSave, 10, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing)


    The second parameter is the FileFormat... and 10 represents Filtered HTML Output.

    I was searching on how to convert the file to XML and found that I can use the same code, but have to change the File Format parameter.

    Anyone knows what value I should set?

    Thanks 
    Wednesday, March 05, 2008 6:24 PM

Answers

All replies

  • Hi Nasty,

     

    Here are some references:

     

    WD2000: How to Use Other Converters with the FileFormat Property

    http://support.microsoft.com/kb/209186

     

    MS Word 2003 XML Output

    http://www.codeproject.com/KB/aspnet/word2003.aspx

     

    Walkthrough: Word 2007 XML Format

    http://msdn2.microsoft.com/en-us/library/ms771890.aspx

     

    Office XML Developer Centers on MSDN:

    http://msdn2.microsoft.com/en-us/office/aa905545.aspx

     

    Thread: Converting Word doc into XML

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2598253&SiteID=1

     

    Visual Studio Tools for Office forum

    http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=16&SiteID=1

     

     

    Regards,

    Martin

    Monday, March 10, 2008 11:00 AM
  • Hi Martin,

    Thank you for the links, they were very useful.
    For anyone else who encounters the same problem, all I had to do is change the second parameter of the SaveAs method from 10 to 11      yep, it was that easy!

    Regards
    Monday, March 10, 2008 5:10 PM
  • Thank you Nasty for sharing your solution here.

    It will be very beneficial to other community members having similar questions.

    Tuesday, March 11, 2008 2:02 AM
  • Hello,

    My name Tan Khai, I use Microsoft.Office.Interop.Word.Document.SaveAs to SaveAs a .doc file to .html file (filtered)
    ------------------my code (C#)--------------------------
    //.....
    Word.Document oDoc = objWord.ActiveDocument;
    object Format = (int)Word.WdSaveFormat.wdFormatFilteredHTML;
    oDoc.SaveAs(ref fileName, ref Format, ref missing, ref missing, ref missing, ref missing, ref missing,
    ref missing, ref missing, ref missing, ref missing, ref encoding, ref missing, ref missing, ref missing, ref missing);
    ------------------------------------------------------------
    But in .html file, font of some object such as ClipArt, Textbox, ...is lost (I use font: Times New roman with character set is Unicode

    Please see my demo in .rar file can be download at: http://www.mtools.vn/word_question.rar

    How can I fix this problem?

    Looking for respond.

    Thanks a lot

    tankhai
    Sunday, March 01, 2009 2:14 PM
  • KhaiHuynh said:

    But in .html file, font of some object such as ClipArt, Textbox, ...is lost (I use font: Times New roman with character set is Unicode

    Please see my demo in .rar file can be download at:
    http://www.mtools.vn/word_question.rar

    How can I fix this problem?


    Please check this KB article for reference:
    Limitations when you save a Word document as a Web page
    http://support.microsoft.com/kb/212270/en-us
    • Proposed as answer by KhaiHuynh Sunday, April 26, 2009 1:19 PM
    Monday, March 02, 2009 2:49 AM
  • Hi Guys,

    Could you please help me out!

    All I need to do is to convert a word document (or XML Document) to image file to store it in DB (SQL Server 2005).

    Thanks in advance.
    Tuesday, June 02, 2009 6:46 AM
  • Hi Team,

    I am new to Office Programming. I need to highlight all the  text in a word document that is not in the Font "Arial". Could you please help me?  (I was successful in opening the document and updaing it as a sample as shown below.)

     

    object missing = System.Reflection.Missing.Value;

    Microsoft.Office.Interop.Word.

    Application wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();

    Microsoft.Office.Interop.Word.

    Document wordDoc = null;

     

    object readOnly = false;

     

    object isVisible = false;

    wordApp.Visible =

    false;

    wordDoc = wordApp.Documents.Open(

    ref fileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing);

    wordDoc.Activate();

    wordDoc.Content.InsertAfter(

    "----");

    this

     

    .FindAndReplace(wordApp, originalText, newText);

    wordDoc.SaveAs(

    ref destinationfileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);

    wordDoc.Close(

    ref missing, ref missing, ref missing);

    Tuesday, June 30, 2009 9:18 AM
  • I have the following code

     

    Public

     

    Function convertXMLToFormat(ByVal strDesiredFormat As Integer, ByVal strSourceName As String, ByVal strTargetName As String) As Boolean

     

    Try

     

    Dim wordApp As New Microsoft.Office.Interop.Word.Application

    wordApp.Visible =

    False

     

    Dim wordDocs As Microsoft.Office.Interop.Word.Document = wordApp.Documents.Open(strSourceName, False, True)

     

    Dim outputFileName As Object = strTargetNameDim missing As Object = Type.Missing

    wordDocs.SaveAs(outputFileName, strDesiredFormat, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing)

    ' fails on line above with message  Object reference not set to an instance of an object.

     

     

     

    Try

    wordDocs.Close(

    False)

    wordApp.Quit(

    False)

     

    Catch ex As Exception

     

    End Try

    convertXMLToFormat =

    True

     

    Catch ex As Exception

    m_error = ex.Message + ex.StackTrace

    convertXMLToFormat =

    False

     

    End Try

     

     

    End Function

    Tuesday, March 08, 2011 1:03 PM
  • FYI.. the attached code works fine when run from visual studio...
    Tuesday, March 08, 2011 3:47 PM