/// <summary> /// Copy the template, add the data and print, save or open the report. /// </summary> /// <remarks> /// This method takes a single object and uses reflection to check it's /// properties for tags with the same name in the template from which the document /// is generated. /// </remarks> /// <param name="record">The record for which this report is created.</param> /// <param name="templateFileOrFolder"> /// The folder where to look for the template, or the name of the template to use. /// <remarks> /// If this is an existing file, the template selection is skipped and the /// given file is used as the template for the document to generate. /// </remarks> /// </param> /// <param name="docxFileName">Filename of the document to generate.</param> /// <param name="action">Determines what to do after the document has been generated.</param> public static void CreateReportFromObject(object record, string templateFileOrFolder, string docxFileName, DocumentAction action = DocumentAction.OpenAction) { DocxReport report = new DocxReport(); if (report.OpenTemplate(templateFileOrFolder, docxFileName)) { foreach (string path in report.Tags.Keys) { if (string.IsNullOrEmpty(path)) { foreach (TagInfo tag in report.Tags[path]) { tag.InsertText("%"); } } else { foreach (TagInfo tag in report.Tags[path]) { report.AddData(record, path, tag); } } } report.SaveReport(action); } }
/// <summary> /// Copy the template, add the data and print, save or open the report. /// </summary> /// <remarks> /// This method takes a collection of objects and uses reflection to check their /// properties for tags with the same name in the template from which the document /// is generated. /// </remarks> /// <param name="records">The list of records for which this report is created.</param> /// <param name="templateFileOrFolder"> /// The folder where to look for the template, or the name of the template to use. /// <remarks> /// If this is an existing file, the template selection is skipped and the /// given file is used as the template for the document to generate. /// </remarks> /// </param> /// <param name="docxFileName">Filename of the document to generate.</param> /// <param name="action">Determines what to do after the document has been generated.</param> public static void CreateReportFromList(IEnumerator records, string templateFileOrFolder, string docxFileName, DocumentAction action = DocumentAction.OpenAction) { DocxReport report = new DocxReport(); if (report.OpenTemplate(templateFileOrFolder, docxFileName)) { while (records.MoveNext()) { foreach (string path in report.Tags.Keys) { foreach (TagInfo tag in report.Tags[path]) { report.AddData(records.Current, path, tag); } } } report.SaveReport(action); } }