Free Support Forum - aspose.com

How to merge html and word into one word document

This given below code shows how to merge two word documnts into one word document.But now i want how to merge html and word document into one word document?

public static void MergeTwoWordDoc()

{

Document dstDoc = new Document(@"C:\Test.docx");//Paper size of this document is A4
Document srcDoc = new Document(@"C:\Test1.docx");//Paper size of this document is Letter
srcDoc.FirstSection.PageSetup.SectionStart = SectionStart.Continuous;
foreach (Section srcSection in srcDoc)
{
srcSection.PageSetup.PageWidth = dstDoc.LastSection.PageSetup.PageWidth;
srcSection.PageSetup.PageHeight = dstDoc.LastSection.PageSetup.PageHeight;
//Import section
Section newSection = (Section)dstDoc.ImportNode(srcSection, true, ImportFormatMode.KeepSourceFormatting);
dstDoc.Sections.Add(newSection);
}
//Save output
dstDoc.Save(@"C:\TestResult.docx");
}

how to merge html and word document into one word document,pls let me know asap?

Hi

Thanks for your inquiry. The code is the same. You can also simplify it to the following:

Document dst = new Document("dst.doc");

Document src = new Document("src.html");

dst.AppendDocument(src, ImportFormatMode.KeepSourceFormatting);

dst.Save("out.doc");

Best regards,

iam getting error as unknown file format

Document dst = new Document(@"C:\Test.docx");

Document src = new Document(@"C:\Htmlfile.html");--eror in this line unknown file format

dst.AppendDocument(src, ImportFormatMode.KeepSourceFormatting);

dst.Save("out.doc");

iam getting error as unknown file format

Document dst = new Document(@"C:\Test.docx");

Document src = new Document(@"C:\Htmlfile.html");--eror in this line unknown file format

dst.AppendDocument(src, ImportFormatMode.KeepSourceFormatting);

dst.Save("out.doc");

Hi

Thanks for your request. Have you tried explicitly specify load format. Please see the code below:

LoadOptions opt = new LoadOptions(LoadFormat.Html, "", "");

Document doc = new Document("in.html", opt);

Also, please make sure your file is a valid HTML file.

Best regards,