Tuesday, April 14, 2015

Convert HTML to WordDocument in C-Sharp


string path = @"D:\HtmlFolder\";
              object filename1 = path + "Sample.Html";
              object oMissing = System.Reflection.Missing.Value;
              object readOnly = false;
              object oFalse = false;

              MSWord.Application oWord = new MSWord.Application();
              MSWord.Document oDoc = new MSWord.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 = path + "Sample.doc";
              object fileFormat = MSWord.WdSaveFormat.wdFormatDocument;
              oDoc.ActiveWindow.View.Type = MSWord.WdViewType.wdPrintView;
              oDoc.PageSetup.Orientation = MSWord.WdOrientation.wdOrientLandscape;
              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);

No comments:

Post a Comment