0

I am using Powertools (Open-Xml-PowerTools Version 4.4.0) -> DocumentBuilder -> BuildDocument to merge multiple Docx files into a single file.

Below is the scenario:-

  • Merging 140 Docx files into a single document.
  • File size ranging from 60 to 350 kb.
  • Takes approx 16 - 17 mins to merge all the files.

Code:-

public class HomeController : Controller
{ 
    public void DocMerger()
    {
        var source1 = Server.MapPath(Url.Content("~/App_Data/1.docx")); //source 1
        var source2 = Server.MapPath(Url.Content("~/App_Data/2.docx")); //source 2
        var source3 = Server.MapPath(Url.Content("~/App_Data/3.docx")); //source 3
        var source4 = Server.MapPath(Url.Content("~/App_Data/4.docx")); //source 4
        var merged =  Server.MapPath(Url.Content("~/App_Data/merged.docx")); //merged

        var f1 = new FileInfo(source1);
        var f2 = new FileInfo(source2);
        var f3 = new FileInfo(source3);
        var f4 = new FileInfo(source4);

        //Use DocumentBuilder and merge the files
        var sources = new List<Source>()
        {
            new Source(new WmlDocument(f1.FullName),false),
              new Source(new WmlDocument(f2.FullName),false),
                new Source(new WmlDocument(f3.FullName),false),
                  new Source(new WmlDocument(f4.FullName),false)
        };
        var mergedDocument = DocumentBuilder.BuildDocument(sources, merged); //save merged data as merged.docx

    }

}

Any possible solutions for the performance issue?

uvcreation
  • 91
  • 1
  • 9

0 Answers0