質問する質問する
 

回答済み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日 0: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日 0:22
    •  

すべての返信

  • 2008年9月22日 22: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日 0: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日 0: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.