질문하기질문하기
 

답변됨Convert HTML to Word Document

  • 2008년 9월 2일 화요일 오전 1:00Yuen Li 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
     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.

답변

  • 2008년 9월 23일 화요일 오전 12:22Yuen Li 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨코드 있음
     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

    • 답변으로 표시됨Yuen Li 2008년 9월 23일 화요일 오전 12:22
    •  

모든 응답

  • 2008년 9월 22일 월요일 오후 10:33cs0kalom 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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
  • 2008년 9월 23일 화요일 오전 12:22Yuen Li 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨코드 있음
     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

    • 답변으로 표시됨Yuen Li 2008년 9월 23일 화요일 오전 12:22
    •  
  • 2008년 9월 26일 금요일 오전 2:25cs0kalom 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Yikes!! This looks scarey.  i'll have to try it.

    Thanks! 

    Bea
    Thanks! Bea
  • 2009년 5월 26일 화요일 오전 7:10Kaushal.NET 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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.