/// <summary> /// Start with filename /// </summary> /// <param name="filename"></param> /// <param name="defaultModules"></param> public TemplBuilder(string filename, bool defaultModules = true) : this(defaultModules) { Doc = DocX.Load(filename); Doc.SaveAs(Stream); Filename = filename; }
/// <summary> /// Start with passed-in doc /// </summary> /// <param name="document"></param> /// <param name="defaultModules"></param> public TemplBuilder(DocX document, bool defaultModules = true) : this(defaultModules) { Doc = document; Doc.SaveAs(Stream); }
static void Main(string[] args) { // Store a global reference to the executing assembly. g_assembly = Assembly.GetExecutingAssembly(); // Try to load the template 'InvoiceTemplate.docx'. try { // Store a global reference to the loaded document. g_document = DocX.Load(@"Content/letterheadpad_template.docx"); /* * The template 'InvoiceTemplate.docx' exists, * so lets use it to create an invoice for a factitious company * called "The Happy Builder" and store a global reference it. */ g_document = CreateInvoiceFromTemplate(DocX.Load(@"Content/letterheadpad_template.docx")); // Save all changes made to this template as Invoice_The_Happy_Builder.docx (We don't want to replace InvoiceTemplate.docx). g_document.SaveAs("Report_print.docx"); } // The template 'InvoiceTemplate.docx' does not exist, so create it. catch (FileNotFoundException) { // Create a store a global reference to the template 'InvoiceTemplate.docx'. Console.WriteLine("FILE NOT FOUNDDDDDDDDDDDDDDDDDDDDDDDD"); } }
private void SaveDoc(DocX doc, string dir, string fileName) { doc.SaveAs(dir + fileName); }
/// <summary> /// New document from filename /// </summary> /// <param name="filename"></param> public TemplDoc(string filename) { Filename = filename; Docx = DocX.Load(Filename); Docx.SaveAs(Stream); }
/// <summary> /// Start with passed-in doc /// </summary> /// <param name="document"></param> public TemplDoc(DocX document) { Docx = document; Docx.SaveAs(Stream); }