protected void Page_Load(object sender, EventArgs e) { var data = GetDataContext(); var reportTemplate = data.FixedPattern.Customer.Foundry.ReportTemplate; var generationInfo = GetDocumentGenerationInfo("RGReportGenerator", "1.0", data, reportTemplate, false); var sampleDocumentGenerator = new RGReportGenerator(generationInfo); byte[] result = sampleDocumentGenerator.GenerateDocument(); var filePath = WriteOutputToFile("RadiographyReportTemplate_Out" + DateTime.Now.ToString("SSMIHH") + ".docx", result); using (var wordDocument = WordprocessingDocument.Open(filePath, true)) { wordDocument.ChangeDocumentType(WordprocessingDocumentType.Document); var mainDocumentPart = wordDocument.MainDocumentPart; var document = mainDocumentPart.Document; // Clean up: The user will appreciate a clean document! var helper = new OpenXmlHelper(DocumentGenerationInfo.NamespaceUri); helper.RemoveContentControlsAndKeepContents(document); document.Save(); } //download the file to the user var filename = "ReportNo" + Request.Params["ReportNo"] + ".docx"; Response.ContentType = "application/ms-word"; Response.AddHeader("content-disposition", "attachment; filename="+filename); Response.TransmitFile(filePath); Response.Flush(); //clean up the file File.Delete(filePath); Response.End(); }
protected void Page_Load(object sender, EventArgs e) { const string reportTemplateName = "ChangesReportTemplate.docx"; var foundryName = Request.Params["FOUNDRY_NAME"]; var fromDate = Request.Params["FROM_DATE"]; var toDate = Request.Params["TO_DATE"]; //date is expected in dd/MM/yyyy format from the url if (!String.IsNullOrEmpty(fromDate)) { fromDate = DateTime.Parse(fromDate, CustomCulture).ToString("dd-MM-yyyy"); } if(!String.IsNullOrEmpty(toDate)) { toDate = DateTime.Parse(toDate, CustomCulture).ToString("dd-MM-yyyy"); } if (string.IsNullOrEmpty(reportTemplateName)) return; var generationInfo = GetDocumentGenerationInfo("ChangesReportGenerator", "1.0", GetDataContext(), reportTemplateName, false); var sampleDocumentGenerator = new ChangesReportGenerator(generationInfo, String.IsNullOrEmpty(foundryName) ? "All" : foundryName, fromDate, toDate); byte[] result = sampleDocumentGenerator.GenerateDocument(); var filePath = WriteOutputToFile("ChangesReportTemplate" + DateTime.Now.ToString("SSMIHH") + ".docx", result); using (var wordDocument = WordprocessingDocument.Open(filePath, true)) { wordDocument.ChangeDocumentType(WordprocessingDocumentType.Document); var mainDocumentPart = wordDocument.MainDocumentPart; var document = mainDocumentPart.Document; // Clean up: The user will appreciate a clean document! var helper = new OpenXmlHelper(DocumentGenerationInfo.NamespaceUri); helper.RemoveContentControlsAndKeepContents(document); document.Save(); } //download the file to the user string filename = "ChangesReport" + foundryName + ".docx"; Response.ContentType = "application/ms-word"; Response.AddHeader("content-disposition", "attachment; filename="+filename); Response.TransmitFile(filePath); Response.Flush(); //clean up the file File.Delete(filePath); Response.End(); }
protected void Page_Load(object sender, EventArgs e) { var data = GetDataContext(); if (data.StatusID == 2) { if (data.RGReportRows.SelectMany(p => p.Classifications).Count() > 0) data.Status.Status = "CASTING ACCEPTABLE AS PER LEVEL " + data.RGReportRows.SelectMany(p => p.Classifications.Split(',')).Where(m => !string.IsNullOrEmpty(m)).Select(int.Parse).Max(); else data.Status.Status = "CASTING ACCEPTABLE AS PER LEVEL 1"; } var reportTemplate = data.FixedPattern.Customer.Foundry.ReportTemplate; var generationInfo = GetDocumentGenerationInfo("RGReportGenerator", "1.0", data, reportTemplate, false); var IsFilmSizeInCms = Convert.ToBoolean(Request.Params["FilmSize"]); var sampleDocumentGenerator = new RGReportGenerator(generationInfo); sampleDocumentGenerator.IsFilmSizeInCms = IsFilmSizeInCms; byte[] result = sampleDocumentGenerator.GenerateDocument(); var filePath = WriteOutputToFile("RadiographyReportTemplate_Out" + DateTime.Now.ToString("SSMIHH") + ".docx", result); using (var wordDocument = WordprocessingDocument.Open(filePath, true)) { wordDocument.ChangeDocumentType(WordprocessingDocumentType.Document); var mainDocumentPart = wordDocument.MainDocumentPart; var document = mainDocumentPart.Document; // Clean up: The user will appreciate a clean document! var helper = new OpenXmlHelper(DocumentGenerationInfo.NamespaceUri); helper.RemoveContentControlsAndKeepContents(document); document.Save(); } //download the file to the user var filename = "ReportNo" + Request.Params["ReportNo"] + ".docx"; Response.ContentType = "application/ms-word"; Response.AddHeader("content-disposition", "attachment; filename=" + filename); Response.TransmitFile(filePath); Response.Flush(); //clean up the file File.Delete(filePath); Response.End(); }
protected void Page_Load(object sender, EventArgs e) { var reportTemplateName = Request.Params["TEMPLATE_NAME"]; var ReportNumber = Request.Params["REPORT_NUMBER"]; var RGReportID = Request.Params["REPORT_ID"]; var cellNo = Request.Params["CELL_NO"]; //date is expected in dd/MM/yyyy format from the url if (string.IsNullOrEmpty(reportTemplateName)) return; var generationInfo = GetDocumentGenerationInfo("AddressStickerGenerator", "1.0", GetDataContext(), reportTemplateName, false); var addressStickerGenerator = new AddressStickerGenerator(generationInfo); byte[] result = addressStickerGenerator.GenerateDocument(); var filePath = WriteOutputToFile("AddressStickerReport" + DateTime.Now.ToString("SSMIHH") + ".docx", result); using (var wordDocument = WordprocessingDocument.Open(filePath, true)) { wordDocument.ChangeDocumentType(WordprocessingDocumentType.Document); var mainDocumentPart = wordDocument.MainDocumentPart; var document = mainDocumentPart.Document; // Clean up: The user will appreciate a clean document! var helper = new OpenXmlHelper(DocumentGenerationInfo.NamespaceUri); helper.RemoveContentControlsAndKeepContents(document); document.Save(); } //download the file to the user string filename = "AddressStickerReport.docx"; Response.ContentType = "application/ms-word"; Response.AddHeader("content-disposition", "attachment; filename="+filename); Response.TransmitFile(filePath); Response.Flush(); //clean up the file File.Delete(filePath); Response.End(); }
protected void Page_Load(object sender, EventArgs e) { var reportTemplateName = Request.Params["Template"]; var IsFilmSizeInCms = Convert.ToBoolean(Request.Params["FilmSize"]); if (string.IsNullOrEmpty(reportTemplateName)) return; DocumentGenerationInfo generationInfo = GetDocumentGenerationInfo("FinalRGReportGenerator", "1.0", GetDataContext(), reportTemplateName, false); FinalRGReportGenerator sampleDocumentGenerator = new FinalRGReportGenerator(generationInfo); sampleDocumentGenerator.IsFilmSizeInCms = IsFilmSizeInCms; byte[] result = result = sampleDocumentGenerator.GenerateDocument(); var filePath = WriteOutputToFile("RadiographyReportTemplate_Out" + DateTime.Now.ToString("SSMIHH") + ".docx", result); using (var wordDocument = WordprocessingDocument.Open(filePath, true)) { wordDocument.ChangeDocumentType(WordprocessingDocumentType.Document); var mainDocumentPart = wordDocument.MainDocumentPart; var document = mainDocumentPart.Document; // Clean up: The user will appreciate a clean document! var helper = new OpenXmlHelper(DocumentGenerationInfo.NamespaceUri); helper.RemoveContentControlsAndKeepContents(document); document.Save(); } //download the file to the user string filename = "RTNo" + Request.Params["RTNo"] + ".docx"; Response.ContentType = "application/ms-word"; Response.AddHeader("content-disposition", "attachment; filename="+filename); Response.TransmitFile(filePath); Response.Flush(); //clean up the file File.Delete(filePath); Response.End(); }
private byte[] SetContentInPlaceholders() { byte[] output; using (MemoryStream ms = new MemoryStream()) { ms.Write(this.generationInfo.TemplateData, 0, this.generationInfo.TemplateData.Length); using (WordprocessingDocument wordDocument = WordprocessingDocument.Open(ms, true)) { wordDocument.ChangeDocumentType(WordprocessingDocumentType.Document); MainDocumentPart mainDocumentPart = wordDocument.MainDocumentPart; Document document = mainDocumentPart.Document; // The sections that the user decided to remove from the build notes foreach (var exclusion in this.exclusions) { var section = document.Body.Descendants <SdtElement>().FirstOrDefault( r => r.SdtProperties.GetFirstChild <Tag>().Val.HasValue&& r.SdtProperties.GetFirstChild <Tag>().Val.Value == string.Format("{0}ContentControlRow", exclusion)); mainDocumentPart.Document.Body.RemoveChild(section); } if (this.generationInfo.Metadata != null) { this.SetDocumentProperties(mainDocumentPart, this.generationInfo.Metadata); } if (this.generationInfo.IsDataBoundControls) { this.SaveDataToDataBoundControlsDataStore(mainDocumentPart); } foreach (HeaderPart part in mainDocumentPart.HeaderParts) { this.SetContentInPlaceholders(new OpenXmlElementDataContext { Element = part.Header, DataContext = this.generationInfo.DataContext }); part.Header.Save(); } foreach (FooterPart part in mainDocumentPart.FooterParts) { this.SetContentInPlaceholders(new OpenXmlElementDataContext { Element = part.Footer, DataContext = this.generationInfo.DataContext }); part.Footer.Save(); } this.SetContentInPlaceholders(new OpenXmlElementDataContext { Element = document, DataContext = this.generationInfo.DataContext }); OpenXmlHelper.EnsureUniqueContentControlIdsForMainDocumentPart(mainDocumentPart); document.Save(); } ms.Position = 0; output = new byte[ms.Length]; ms.Read(output, 0, output.Length); } return(output); }
/// <summary> /// Sets the content of content control. /// </summary> /// <param name="element">The element.</param> /// <param name="content">The content.</param> protected static void SetContentOfContentControl(SdtElement element, string content) { // Set text without data binding OpenXmlHelper.SetContentOfContentControl(element, content); }
/// <summary> /// Generates the final report by appending documents. /// </summary> private static void MergeBuildNotesAndCreateFinalOutput(List<byte[]> otherDocs) { // Test final report i.e. created by merging documents generation DirectoryInfo di = new DirectoryInfo(System.Reflection.Assembly.GetExecutingAssembly().Location); if (di.Parent != null) { byte[] primaryDoc = File.ReadAllBytes(Path.Combine(di.Parent.FullName, @"Templates\BuildTemplateCover.docx")); // Final report generation OpenXmlHelper openXmlHelper = new OpenXmlHelper(DocumentGenerationInfo.NamespaceUri); byte[] result = openXmlHelper.AppendDocumentsToPrimaryDocument(primaryDoc, otherDocs); // Final Protected report generation using (MemoryStream msfinalDocument = new MemoryStream()) { msfinalDocument.Write(result, 0, result.Length); using (WordprocessingDocument finalDocument = WordprocessingDocument.Open(msfinalDocument, true)) { OpenXmlHelper.ProtectDocument(finalDocument); } msfinalDocument.Position = 0; result = new byte[msfinalDocument.Length]; msfinalDocument.Read(result, 0, result.Length); msfinalDocument.Close(); } WriteOutputToFile("BuildNotes.docx", result); } }
/// <summary> /// Generates the final report by appending documents. /// </summary> private static void GenerateFinalReportByAppendingDocuments() { // Test final report i.e. created by merging documents generation byte[] primaryDoc = File.ReadAllBytes(@"Sample Templates\Test_Template - Final.docx"); List<byte[]> otherDocs = new List<byte[]>(); otherDocs.Add(File.ReadAllBytes(@"Sample Templates\Test_Template1_Out.docx")); otherDocs.Add(File.ReadAllBytes(@"Sample Templates\Test_Template1_BeforeRefresh_Out.docx")); otherDocs.Add(File.ReadAllBytes(@"Sample Templates\Test_Template1_AfterRefresh_Out.docx")); otherDocs.Add(File.ReadAllBytes(@"Sample Templates\Test_Template2_Out.docx")); otherDocs.Add(File.ReadAllBytes(@"Sample Templates\Test_Template2_AfterRefresh_Out.docx")); otherDocs.Add(File.ReadAllBytes(@"Sample Templates\Test_Template2_Databinding_Table_Out.docx")); otherDocs.Add(File.ReadAllBytes(@"Sample Templates\Test_Template1_Databinding_Out_BeforeRefresh.docx")); otherDocs.Add(File.ReadAllBytes(@"Sample Templates\Test_Template1_Databinding_Out_AfterRefresh.docx")); otherDocs.Add(File.ReadAllBytes(@"Sample Templates\Test_Template3_Out.docx")); // Final report generation OpenXmlHelper openXmlHelper = new OpenXmlHelper(DocumentGenerationInfo.NamespaceUri); byte[] result = openXmlHelper.AppendDocumentsToPrimaryDocument(primaryDoc, otherDocs); WriteOutputToFile("FinalReport.docx", "Test_Template - Final.docx", result); // Final Protected report generation using (MemoryStream msfinalDocument = new MemoryStream()) { msfinalDocument.Write(result, 0, result.Length); using (WordprocessingDocument finalDocument = WordprocessingDocument.Open(msfinalDocument, true)) { openXmlHelper.ProtectDocument(finalDocument); } msfinalDocument.Position = 0; result = new byte[msfinalDocument.Length]; msfinalDocument.Read(result, 0, result.Length); msfinalDocument.Close(); } WriteOutputToFile("FinalReport_Protected.docx", "Test_Template - Final.docx", result); }