I have wrote some code in C# using .NET 5.0 with Nuget package openXML tools and for some reason when I merge the files together the font it merges itself in changes into Times New Roman on its own when the documents before merging were in calibri. Here is my code:
public static void MergeDocuments(string[] fileNames, string outputFilePath)
{
using (var outputFileStream = new FileStream(outputFilePath, FileMode.Create, FileAccess.ReadWrite))
{
var sources = new List<Source>();
foreach (string fileName in fileNames)
{
byte[] allBytes = File.ReadAllBytes(fileName);
var openXmlPowerToolsDocument = new OpenXmlPowerToolsDocument(allBytes);
var source = new Source(new WmlDocument(openXmlPowerToolsDocument), true);
sources.Add(source);
}
MergeXmlDocuments(outputFileStream, sources);
}
}
public static void MergeXmlDocuments(Stream outStream, List<Source> sources)
{
WmlDocument buildDocument = DocumentBuilder.BuildDocument(sources);
buildDocument.WriteByteArray(outStream);
}
static void Main(string[] args)
{
string[] files = {"cover.docx", "q3_0_0_5_0.docx", "q2.docx"};
string outFileName = "merged.docx";
List<Source> sources = null;
sources = new List<Source>() // initialize sources that would like to be merged
{
new Source(new WmlDocument("../../cover.docx"), true),
new Source(new WmlDocument("../../q3_0_0_5_0.docx"), true),
new Source(new WmlDocument("../../q2.docx"), true),
};
MergeDocuments(files, outFileName);
}