Formular una preguntaFormular una pregunta
 

RespondidaConvert HTML to Word Document

  • martes, 02 de septiembre de 2008 1:00Yuen Li Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
     Hi! I wish to convert a HTML file to Word Document file. Is there anyway to save it as (*.doc) using Microsoft.Office.Interop library? Or is there any alternative method beside changing the file extension from (*.html) to (*.doc) because I wish to do it programmatically in C#. Thanks.

Respuestas

  • martes, 23 de septiembre de 2008 0:22Yuen Li Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     RespondidaTiene código
     Hi! I did found a solution from somewhere else. You can try to open HTML file in word using Microsoft.Office.Interop.Word and save it in *.doc file type. Here are the sample codes that I used:-

    object filename1 = filename;
    object oMissing = System.Reflection.Missing.Value;
    object readOnly = false;
    object oFalse = false;

    Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
    Microsoft.Office.Interop.Word.
    Document oDoc = new Microsoft.Office.Interop.Word.Document();
    oDoc = oWord.Documents.Add(
    ref oMissing, ref oMissing, ref oMissing, ref oMissing);
    oWord.Visible =
    false;

    oDoc = oWord.Documents.Open(ref filename1, ref oMissing, ref readOnly, ref oMissing, ref oMissing, ref oMissing,ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,ref oMissing, ref oMissing);

    filename1 = @"D:\FileConverter\Temp\new.doc";
    object fileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument;
    oDoc.SaveAs(
    ref filename1, ref fileFormat, ref oMissing, ref oMissing,ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,ref oMissing, ref oMissing, ref oMissing);

    oDoc.Close(ref oFalse, ref oMissing, ref oMissing);
    oWord.Quit(
    ref oMissing, ref oMissing, ref oMissing);

    Regards,
    Yuen Li

    • Marcado como respuestaYuen Li martes, 23 de septiembre de 2008 0:22
    •  

Todas las respuestas

  • lunes, 22 de septiembre de 2008 22:33cs0kalom Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    Hi,  I am new here to this website.   There is a lot of great information on here.  

    I was wondering if you ever found a way to do this, perhaps through another avenue.  I am curious about doing this myself.

    Thank you for your help.

    Best wishes to you.

    Bea
  • martes, 23 de septiembre de 2008 0:22Yuen Li Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     RespondidaTiene código
     Hi! I did found a solution from somewhere else. You can try to open HTML file in word using Microsoft.Office.Interop.Word and save it in *.doc file type. Here are the sample codes that I used:-

    object filename1 = filename;
    object oMissing = System.Reflection.Missing.Value;
    object readOnly = false;
    object oFalse = false;

    Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
    Microsoft.Office.Interop.Word.
    Document oDoc = new Microsoft.Office.Interop.Word.Document();
    oDoc = oWord.Documents.Add(
    ref oMissing, ref oMissing, ref oMissing, ref oMissing);
    oWord.Visible =
    false;

    oDoc = oWord.Documents.Open(ref filename1, ref oMissing, ref readOnly, ref oMissing, ref oMissing, ref oMissing,ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,ref oMissing, ref oMissing);

    filename1 = @"D:\FileConverter\Temp\new.doc";
    object fileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument;
    oDoc.SaveAs(
    ref filename1, ref fileFormat, ref oMissing, ref oMissing,ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,ref oMissing, ref oMissing, ref oMissing);

    oDoc.Close(ref oFalse, ref oMissing, ref oMissing);
    oWord.Quit(
    ref oMissing, ref oMissing, ref oMissing);

    Regards,
    Yuen Li

    • Marcado como respuestaYuen Li martes, 23 de septiembre de 2008 0:22
    •  
  • viernes, 26 de septiembre de 2008 2:25cs0kalom Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    Yikes!! This looks scarey.  i'll have to try it.

    Thanks! 

    Bea
    Thanks! Bea
  • martes, 26 de mayo de 2009 7:10Kaushal.NET Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    Hello,

           I have done that much task as well as applying some of the formatting to document object also as like to create header,footer,border,

    document created successfully,but now my problem is my content is in html format now i want to display that content as a html formatted

    on my created word document,for that i have use

    object fileFormat = Microsoft.Office.Interop.Word. WdSaveFormat .wdFormatFilteredHTML;

    then i can get proper document,but at that time document cound't affect with applied formatting means it doesn't disply header

    and footer, while i have change above syntax as like below

    object fileFormat = Microsoft.Office.Interop.Word. WdSaveFormat .wdFormatDocument;

    then header and footer wil display but agin i m not getting html formated text on word document.

    now my problem is vise versa if i want to solve one problem then its create second one ....please help me to short out problem

    Thanks,

    Kaushal Pathak.