Hi,
I am trying to merge two documents, using the c# method below :
public static void InsertAckTemplate(string filename, string template)
{
if (!File.Exists(filename))
{
throw new AsConfException(string.Format("Unable to open file {0}", filename), filename);
}
if (!File.Exists(template))
{
throw new AsConfException(string.Format("Unable to open template file {0}", template), filename);
}
//Get section from template
var tmpDoc = new Spire.Doc.Document();
tmpDoc.LoadFromFile(template, FileFormat.Docx);
var doc = new Spire.Doc.Document();
doc.LoadFromFile(filename, FileFormat.Docx);
doc.AcceptChanges();
if (doc.Sections.Count > 0)
{
Paragraph p = doc.LastSection.AddParagraph();
Break stun = new Break(doc, BreakType.PageBreak);
p.ChildObjects.Insert(0, stun);
foreach (Paragraph item in tmpDoc.Sections[0].Paragraphs)
{
p.ChildObjects.Add(item.Clone());
}
}
else
{
Section sec = doc.AddSection();
sec.AddParagraph().ChildObjects.Insert(0, tmpDoc);
}
SaveDocument(filename, doc);
doc.Close();
tmpDoc.Close();
}
When i try to add each paragraph of the template to the file, i have an error : index is out of the bounds of the table.
I attached the filename and template.
Can you help me please ? thanks