public HeaderFooter this[HeaderFooterType A_0] { get { int num = 1; switch (hfType) { case HeaderFooterType.HeaderEven: return(this.EvenHeader); case HeaderFooterType.HeaderOdd: return(this.OddHeader); case HeaderFooterType.FooterEven: return(this.EvenFooter); case HeaderFooterType.FooterOdd: return(this.OddFooter); case HeaderFooterType.HeaderFirstPage: return(this.FirstPageHeader); case HeaderFooterType.FooterFirstPage: return(this.FirstPageFooter); } throw new ArgumentException(BookmarkStart.b("渦䜨崪䰬䌮堰圲ᔴ弶尸娺夼娾㍀求⍄⡆♈㽊⡌㵎煐❒ⱔ❖㱘", num), BookmarkStart.b("伦伨缪听弮吰", num)); } internal set { int num = 8; switch (A_0) { case HeaderFooterType.HeaderEven: this.headerFooter_0 = value; return; case HeaderFooterType.HeaderOdd: this.headerFooter_2 = value; return; case HeaderFooterType.FooterEven: this.headerFooter_3 = value; return; case HeaderFooterType.FooterOdd: this.headerFooter_1 = value; return; case HeaderFooterType.HeaderFirstPage: this.headerFooter_4 = value; return; case HeaderFooterType.FooterFirstPage: this.headerFooter_5 = value; return; } throw new ArgumentException(BookmarkStart.b("札帯䐱唳娵儷帹᰻嘽┿⍁⁃⍅㩇敉⩋⅍㽏♑ㅓ硗⹙╛⹝՟", num), BookmarkStart.b("䘭嘯昱䴳䘵崷", num)); } }
internal HeadersFooters(Section A_0) : base(A_0.Document, A_0) { this.headerFooter_0 = new HeaderFooter(A_0, HeaderFooterType.HeaderEven); this.headerFooter_2 = new HeaderFooter(A_0, HeaderFooterType.HeaderOdd); this.headerFooter_3 = new HeaderFooter(A_0, HeaderFooterType.FooterEven); this.headerFooter_1 = new HeaderFooter(A_0, HeaderFooterType.FooterOdd); this.headerFooter_5 = new HeaderFooter(A_0, HeaderFooterType.FooterFirstPage); this.headerFooter_4 = new HeaderFooter(A_0, HeaderFooterType.HeaderFirstPage); }
internal void method_7() { HeaderFooter footer = null; for (int i = 0; i < 6; i++) { footer = this[i]; footer.method_28(); footer = null; } }
private void button3_Click(object sender, EventArgs e) { Spire.Doc.Document docSpire = new Spire.Doc.Document(@"C:\TEMP\Teste6.docx"); //Spire.Doc.Document docSpire = new Spire.Doc.Document(); Spire.Doc.Section secao = docSpire.Sections[0]; Spire.Doc.HeaderFooter cabecalho = secao.HeadersFooters.Header; Spire.Doc.Documents.Paragraph para1 = cabecalho.AddParagraph(); para1.AppendRTF(richTextBox1.Rtf); //Spire.Doc.Section secao2 = docSpire.AddSection(); Spire.Doc.Documents.Paragraph para2 = secao.AddParagraph(); para2.AppendRTF(richTextBox2.Rtf); docSpire.SaveToFile(@"C:\TEMP\Teste6.docx"); }
//private void ReportHeader() //{ // ReportHeader reportHeader = ReportHeader.getReportHeder(this.jobSample); // #region "PAGE TITLE" // Paragraph paragraph = s.AddParagraph(); // paragraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center; // paragraph.AppendText("REPORT").ApplyCharacterFormat(format); // Paragraph paragraph2 = s.AddParagraph(); // paragraph2.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center; // paragraph2.AppendText(""); // Paragraph paragraph3 = s.AddParagraph(); // paragraph3.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center; // paragraph3.AppendText(""); // #endregion // #region "Information" // Table tableInfo = s.AddTable(true); // //Create Header and Data // String[][] data = { // new String[]{ "CUSTOMER PO NO.:", reportHeader.cusRefNo}, // new String[]{ "ALS THAILAND REF NO.:", reportHeader.alsRefNo}, // new String[]{ "DATE:", reportHeader.cur_date.ToString("dd MMMM yyyy")}, // new String[]{ "COMPANY:", reportHeader.addr1}, // new String[]{ "", reportHeader.addr2}, // new String[]{ "",""}, // new String[]{ "DATE SAMPLE RECEIVED:", reportHeader.dateOfDampleRecieve.ToString("dd MMMM yyyy") }, // new String[]{ "DATE ANALYZED:", reportHeader.dateOfAnalyze.ToString("dd MMMM yyyy") }, // new String[]{ "DATE TEST COMPLETED:", reportHeader.dateOfAnalyze.ToString("dd MMMM yyyy") }, // new String[]{ "","" }, // new String[]{ "SAMPLE DESCRIPTION:", "One lot of sample was received with references:" }, // new String[]{ "", reportHeader.description }, // }; // //Add Cells // tableInfo.ResetCells(data.Length, 2); // //Data Row // for (int r = 0; r < data.Length; r++) // { // TableRow tr = tableInfo.Rows[r]; // //Row Height // tr.Height = fontSize; // tr.Cells[0].SetCellWidth(30, CellWidthType.Percentage); // tr.Cells[1].SetCellWidth(70, CellWidthType.Percentage); // //C Represents Column. // for (int c = 0; c < data[r].Length; c++) // { // //Cell Alignment // tr.Cells[c].CellFormat.VerticalAlignment = VerticalAlignment.Middle; // //Fill Data in Rows // Paragraph p2 = tr.Cells[c].AddParagraph(); // p2.AppendText(data[r][c]).ApplyCharacterFormat(bodyFormat); ; // tr.Cells[c].CellFormat.Borders.Bottom.BorderType = Spire.Doc.Documents.BorderStyle.None; // tr.Cells[c].CellFormat.Borders.Top.BorderType = Spire.Doc.Documents.BorderStyle.None; // tr.Cells[c].CellFormat.Borders.Left.BorderType = Spire.Doc.Documents.BorderStyle.None; // tr.Cells[c].CellFormat.Borders.Right.BorderType = Spire.Doc.Documents.BorderStyle.None; // } // } // tableInfo.TableFormat.Borders.Bottom.BorderType = Spire.Doc.Documents.BorderStyle.None; // tableInfo.TableFormat.Borders.Top.BorderType = Spire.Doc.Documents.BorderStyle.None; // tableInfo.TableFormat.Borders.Left.BorderType = Spire.Doc.Documents.BorderStyle.None; // tableInfo.TableFormat.Borders.Right.BorderType = Spire.Doc.Documents.BorderStyle.None; // #endregion // #region "Method/Procedure" // s.AddParagraph().AppendText(""); // s.AddParagraph().AppendText("METHOD/PROCEDURE:").ApplyCharacterFormat(bodyFormat); // //////////////////////////////////////////////////////////////////////////////////////////////////////////// // Table table = s.AddTable(true); // String[] Header = { "Test", "Procedure No ", "Number of pieces used for extraction ", " Extraction Medium ", "Extraction Volume" }; // List<template_wd_dhs_coverpage> dataList = template_wd_dhs_coverpage.FindAllBySampleID(jobSample.ID); // //Add Cells // table.ResetCells(2, Header.Length); // //Header Row // TableRow FRow = table.Rows[0]; // FRow.IsHeader = true; // //Row Height // FRow.Height = fontSize; // //Header Format // FRow.RowFormat.BackColor = Color.LightGray; // for (int i = 0; i < Header.Length; i++) // { // //Cell Alignment // Paragraph p = FRow.Cells[i].AddParagraph(); // FRow.Cells[i].CellFormat.VerticalAlignment = VerticalAlignment.Middle; // p.Format.HorizontalAlignment = HorizontalAlignment.Center; // //Data Format // p.AppendText(Header[i]).ApplyCharacterFormat(bodyFormat); ; // } // TableRow DataRow = table.Rows[1]; // Paragraph pRow = DataRow.Cells[0].AddParagraph(); // pRow.AppendText("DHS").ApplyCharacterFormat(bodyFormat); // pRow.Format.HorizontalAlignment = HorizontalAlignment.Center; // pRow = DataRow.Cells[1].AddParagraph(); // pRow.AppendText(dataList[0].pm_procedure_no).ApplyCharacterFormat(bodyFormat); // pRow.Format.HorizontalAlignment = HorizontalAlignment.Center; // pRow = DataRow.Cells[2].AddParagraph(); // pRow.AppendText(dataList[0].pm_number_of_pieces_used_for_extraction).ApplyCharacterFormat(bodyFormat); // pRow.Format.HorizontalAlignment = HorizontalAlignment.Center; // pRow = DataRow.Cells[3].AddParagraph(); // pRow.AppendText(dataList[0].pm_extraction_medium).ApplyCharacterFormat(bodyFormat); // pRow.Format.HorizontalAlignment = HorizontalAlignment.Center; // pRow = DataRow.Cells[4].AddParagraph(); // pRow.AppendText(dataList[0].pm_extraction_volume).ApplyCharacterFormat(bodyFormat); // pRow.Format.HorizontalAlignment = HorizontalAlignment.Center; // #endregion //} private void MergeHeaderFooter() { Document doc1 = new Document(); doc1.LoadFromFile(this.server.MapPath("~/template/") + "Blank Letter Head - EL.doc"); Spire.Doc.HeaderFooter header = doc1.Sections[0].HeadersFooters.Header; Spire.Doc.HeaderFooter footer = doc1.Sections[0].HeadersFooters.Footer; //Paragraph paraInserted = new Paragraph(this.doc); //TextRange textRange1 = paraInserted.AppendText("======================= xxx ============================"); //textRange1.CharacterFormat.TextColor = Color.Blue; //textRange1.CharacterFormat.FontSize = 15; //textRange1.CharacterFormat.UnderlineStyle = UnderlineStyle.Dash; //this.doc.Sections[0].Paragraphs.Insert(0, paraInserted); //this.doc.Sections[0].Paragraphs.Insert(1, paraInserted); //document.Sections[0].Paragraphs.Insert(0, paraInserted); // int number_of_pages = this.doc.BuiltinDocumentProperties.PageCount; //] Paragraph paragraph = range.OwnerParagraph; //Body body = paragraph.OwnerTextBody; //int index = body.ChildObjects.IndexOf(paragraph); foreach (Section section in this.doc.Sections) { foreach (DocumentObject obj in header.ChildObjects) { section.HeadersFooters.Header.ChildObjects.Add(obj.Clone()); } //section.Body.AddParagraph().AppendText("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); //foreach (DocumentObject obj in header.ChildObjects) //{ // section.HeadersFooters.Header.ChildObjects.Add(obj.Clone()); //} foreach (DocumentObject obj in footer.ChildObjects) { section.HeadersFooters.Footer.ChildObjects.Add(obj.Clone()); } } this.doc.SaveToFile(this.server.MapPath("~/Report/") + this.jobSample.job_number + ".doc"); }
private void button5_Click(object sender, EventArgs e) { Spire.Doc.Document doc1 = new Spire.Doc.Document(); doc1.LoadFromFile(@"C:\Downloads\Tax_Header_Document.docx"); Spire.Doc.HeaderFooter header = doc1.Sections[0].HeadersFooters.Header; Spire.Doc.Document doc2 = new Spire.Doc.Document(@"C:\Downloads\2301-233608- Tax Cert.docx"); foreach (Spire.Doc.Section section in doc2.Sections) { foreach (DocumentObject obj in header.ChildObjects) { section.HeadersFooters.Header.ChildObjects.Add(obj.Clone()); } } //doc2.SaveToFile(@"C:\Downloads\TAx_Final.docx", Spire.Doc.FileFormat.Docx); }
internal void method_10() { Section ownerBase = base.OwnerBase as Section; if (ownerBase != null) { this.bool_1 = true; if (ownerBase.method_5() > 0) { this.bool_0 = false; this.headerFooter_2 = new HeaderFooter(ownerBase, HeaderFooterType.HeaderOdd); this.headerFooter_1 = new HeaderFooter(ownerBase, HeaderFooterType.FooterOdd); this.headerFooter_0 = new HeaderFooter(ownerBase, HeaderFooterType.HeaderEven); this.headerFooter_3 = new HeaderFooter(ownerBase, HeaderFooterType.FooterEven); this.headerFooter_4 = new HeaderFooter(ownerBase, HeaderFooterType.HeaderFirstPage); this.headerFooter_5 = new HeaderFooter(ownerBase, HeaderFooterType.FooterFirstPage); } } }
private bool method_49(HeaderFooter A_0) { foreach (Paragraph paragraph in A_0.Paragraphs) { foreach (ParagraphBase base2 in paragraph.Items) { if (!(base2 is DocPicture) && !(base2 is TextBox)) { if (base2 is ShapeObject) { return(false); } } else { base2.bool_4 = true; } } } return(true); }
public void InsertPageNumbers(bool fromTopPage, PageNumberAlignment horizontalAlignment) { HeaderFooter footer = fromTopPage ? (base.OwnerBase as Section).HeadersFooters.Header : (base.OwnerBase as Section).HeadersFooters.Footer; IParagraph paragraph = null; IField field2 = null; int num = 0; int count = footer.Paragraphs.Count; while (num < count) { Field field; paragraph = footer.Paragraphs[num]; int num2 = 0; int num3 = paragraph.Items.Count; while (num2 < num3) { if (paragraph.Items[num2].DocumentObjectType == DocumentObjectType.Field) { field = (Field)paragraph.Items[num2]; if (field.Type == FieldType.FieldPage) { goto Label_00A4; } } num2++; } goto Label_00A8; Label_00A4: field2 = field; Label_00A8: num++; } if (field2 == null) { paragraph = footer.AddParagraph(); field2 = paragraph.AppendField("", FieldType.FieldPage); } paragraph.Format.WrapFrameAround = true; paragraph.Format.FrameX = (short)horizontalAlignment; }
private void CreateDocument(object o) { ExcelInfo ei = o as ExcelInfo; dgv_task.Rows[ei._id - 1].Cells[4].Value = "正在准备"; //获得 table DataTable dt_split = ei._data; //读取excel,得到行数 /*生成一个新的word*/ Spire.Doc.Document spdoc = new Spire.Doc.Document(); /*循环把list中的mycu内容添加到word文档*/ for (int rowindex = 0; rowindex < dt_split.Rows.Count; rowindex++) { dgv_task.Rows[ei._id - 1].Cells[4].Value = (100 * Convert.ToDecimal(rowindex + 1) / Convert.ToDecimal(dt_split.Rows.Count)).ToString("00.00") + "%"; //更新状态栏文字 //string str_statue = "正在生成第{0}个,共{1}个……"; //UpdateStatue(string.Format(str_statue, rowindex - 1, lastrow - 1)); ///载入一个空白文档 spdoc.LoadFromFile(Environment.CurrentDirectory + @"\newdoc.docx"); for (int i = Global.list_myuc.Count - 1; i >= 0; i--) { //设置文本 string str_n = string.Empty; //设置空行 for (int ji = 0; ji < Global.list_myuc[i].mysetter.konghang; ji++) { str_n += "\n"; } //添加一个段落 Spire.Doc.Documents.Paragraph parainsert = spdoc.LastSection.AddParagraph(); //Spire.Doc.Documents.Paragraph parainsert = spdoc.CreateParagraph(); TextRange tx = parainsert.AppendText(GetContent(Global.list_myuc[i].mysetter.listcolumn, rowindex, dt_split) + str_n); //字体名称 tx.CharacterFormat.FontName = Global.list_myuc[i].mysetter.fontname; //字体大小 tx.CharacterFormat.FontSize = Global.list_myuc[i].mysetter.fontsize; //设置行距 switch (Global.list_myuc[i].mysetter.hangjustyle) { case "单倍行距": parainsert.Format.LineSpacingRule = Spire.Doc.LineSpacingRule.AtLeast; break; case "1.5倍行距": parainsert.Format.LineSpacingRule = Spire.Doc.LineSpacingRule.Exactly; break; case "2倍行距": parainsert.Format.LineSpacingRule = Spire.Doc.LineSpacingRule.Multiple; break; default: parainsert.Format.LineSpacingRule = Spire.Doc.LineSpacingRule.Exactly; parainsert.Format.LineSpacing = Global.list_myuc[i].mysetter.hangjuvalue; break; } //首行缩进 parainsert.Format.SetFirstLineIndent(Global.list_myuc[i].mysetter.suojin); //首行缩进 //粗体 tx.CharacterFormat.Bold = Global.list_myuc[i].mysetter.bold == 1 ? true : false; switch (Global.list_myuc[i].mysetter.juzhong) { case "左对齐": parainsert.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Left; break; case "居中": parainsert.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center; break; case "右对齐": parainsert.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Right; break; } } SectionCollection sections = spdoc.Sections; //创建一个HeaderFooter类实例,添加页脚 for (int i = 0; i < sections.Count; i++) { sections[i].PageSetup.Margins.Top = 72f; sections[i].PageSetup.Margins.Left = 90f; sections[i].PageSetup.Margins.Bottom = 72f; sections[i].PageSetup.Margins.Right = 90f; Spire.Doc.HeaderFooter footer = sections[i].HeadersFooters.Footer; Spire.Doc.Documents.Paragraph footerPara = footer.AddParagraph(); //添加字段类型为页码,添加当前页、分隔线以及总页数 footerPara.AppendField("页码", FieldType.FieldPage); footerPara.AppendText(" / "); footerPara.AppendField("总页数", FieldType.FieldNumPages); footerPara.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center; } /*保存文档*/ //组成文件名 List <string> strfilename = new List <string>(); for (int i = 0; i < Global.listfilename.Count; i++) { string filename_element = Regex.Replace(dt_split.Rows[rowindex][Global.listfilename[i] + 1].ToString(), @"[\s/\:*?''<>|]", ""); strfilename.Add(filename_element); } spdoc.BuiltinDocumentProperties.Author = "潜挖智库"; spdoc.SaveToFile(tbcunfang.Text + @"\" + string.Join("-", strfilename) + @".docx"); spdoc.Close(); } }
internal void method_9(bool A_0) { Section ownerBase = base.OwnerBase as Section; if (ownerBase != null) { this.bool_1 = true; int num = ownerBase.method_5(); if (num == -1) { this.bool_0 = A_0; if (!A_0) { if ((this.headerFooter_2 != null) && (this.headerFooter_2.ChildObjects.Count <= 0)) { this.headerFooter_2 = new HeaderFooter(ownerBase, HeaderFooterType.HeaderOdd); this.headerFooter_2.AddParagraph().AppendText(string.Empty); } if ((this.headerFooter_1 != null) && (this.headerFooter_1.ChildObjects.Count <= 0)) { this.headerFooter_1 = new HeaderFooter(ownerBase, HeaderFooterType.FooterOdd); this.headerFooter_1.AddParagraph().AppendText(string.Empty); } if ((this.headerFooter_0 != null) && (this.headerFooter_0.ChildObjects.Count <= 0)) { this.headerFooter_0 = new HeaderFooter(ownerBase, HeaderFooterType.HeaderEven); this.headerFooter_0.AddParagraph().AppendText(string.Empty); } if ((this.headerFooter_3 != null) && (this.headerFooter_3.ChildObjects.Count <= 0)) { this.headerFooter_3 = new HeaderFooter(ownerBase, HeaderFooterType.FooterEven); this.headerFooter_3.AddParagraph().AppendText(string.Empty); } if ((this.headerFooter_4 != null) && (this.headerFooter_4.ChildObjects.Count <= 0)) { this.headerFooter_4 = new HeaderFooter(ownerBase, HeaderFooterType.HeaderFirstPage); this.headerFooter_4.AddParagraph().AppendText(string.Empty); } if ((this.headerFooter_5 != null) && (this.headerFooter_5.ChildObjects.Count <= 0)) { this.headerFooter_5 = new HeaderFooter(ownerBase, HeaderFooterType.FooterFirstPage); this.headerFooter_5.AddParagraph().AppendText(string.Empty); } } } else { this.bool_0 = (num != 0) && A_0; if (num != 0) { HeadersFooters footers = this.method_6(); if (A_0) { if (this.method_11(footers)) { this.headerFooter_2 = footers.OddHeader; this.headerFooter_1 = footers.OddFooter; this.headerFooter_0 = footers.EvenHeader; this.headerFooter_3 = footers.EvenFooter; this.headerFooter_4 = footers.FirstPageHeader; this.headerFooter_5 = footers.FirstPageFooter; } } else { if ((this.headerFooter_2 == footers.OddHeader) || ((this.headerFooter_2 != null) && (this.headerFooter_2.ChildObjects.Count <= 0))) { this.headerFooter_2 = new HeaderFooter(ownerBase, HeaderFooterType.HeaderOdd); this.headerFooter_2.AddParagraph().AppendText(string.Empty); } if ((this.headerFooter_1 == footers.OddFooter) || ((this.headerFooter_1 != null) && (this.headerFooter_1.ChildObjects.Count <= 0))) { this.headerFooter_1 = new HeaderFooter(ownerBase, HeaderFooterType.FooterOdd); this.headerFooter_1.AddParagraph().AppendText(string.Empty); } if ((this.headerFooter_0 == footers.EvenHeader) || ((this.headerFooter_0 != null) && (this.headerFooter_0.ChildObjects.Count <= 0))) { this.headerFooter_0 = new HeaderFooter(ownerBase, HeaderFooterType.HeaderEven); this.headerFooter_0.AddParagraph().AppendText(string.Empty); } if ((this.headerFooter_3 == footers.EvenFooter) || ((this.headerFooter_3 != null) && (this.headerFooter_3.ChildObjects.Count <= 0))) { this.headerFooter_3 = new HeaderFooter(ownerBase, HeaderFooterType.FooterEven); this.headerFooter_3.AddParagraph().AppendText(string.Empty); } if ((this.headerFooter_4 == footers.FirstPageHeader) || ((this.headerFooter_4 != null) && (this.headerFooter_4.ChildObjects.Count <= 0))) { this.headerFooter_4 = new HeaderFooter(ownerBase, HeaderFooterType.HeaderFirstPage); this.headerFooter_4.AddParagraph().AppendText(string.Empty); } if ((this.headerFooter_5 == footers.FirstPageFooter) || ((this.headerFooter_5 != null) && (this.headerFooter_5.ChildObjects.Count <= 0))) { this.headerFooter_5 = new HeaderFooter(ownerBase, HeaderFooterType.FooterFirstPage); this.headerFooter_5.AddParagraph().AppendText(string.Empty); } } } } } }
protected void lbDownload_Click(object sender, EventArgs e) { tb_m_specification component = new tb_m_specification().SelectByID(this.coverpages[0].specification_id.Value); DataTable dtHeader = new DataTable("MethodProcedure"); // Define all the columns once. DataColumn[] cols = { new DataColumn("ProcedureNo", typeof(String)), new DataColumn("NumOfPiecesUsedForExtraction", typeof(String)), }; dtHeader.Columns.AddRange(cols); DataRow row = dtHeader.NewRow(); row["ProcedureNo"] = txtProcedureNo.Text; row["NumOfPiecesUsedForExtraction"] = this.coverpages[0].number_of_pieces_used_for_extraction; dtHeader.Rows.Add(row); DataTable dtResult = new DataTable("Result"); DataColumn[] cols1 = { new DataColumn("B", typeof(String)), new DataColumn("C", typeof(String)), new DataColumn("result", typeof(String)) }; dtResult.Columns.AddRange(cols1); DataRow row1 = dtResult.NewRow(); row1["B"] = ddlTemp.SelectedItem.Text; row1["C"] = component.D; row1["result"] = this.coverpages[0].result; dtResult.Rows.Add(row1); ReportHeader reportHeader = ReportHeader.getReportHeder(this.jobSample); ReportParameterCollection reportParameters = new ReportParameterCollection(); reportParameters.Add(new ReportParameter("CustomerPoNo", reportHeader.cusRefNo)); reportParameters.Add(new ReportParameter("AlsThailandRefNo", reportHeader.alsRefNo)); reportParameters.Add(new ReportParameter("Date", reportHeader.cur_date.ToString("dd MMMM yyyy") + "")); reportParameters.Add(new ReportParameter("Company", reportHeader.addr1)); reportParameters.Add(new ReportParameter("Company_addr", reportHeader.addr2)); reportParameters.Add(new ReportParameter("DateSampleReceived", reportHeader.dateOfDampleRecieve.ToString("dd MMMM yyyy") + "")); reportParameters.Add(new ReportParameter("DateAnalyzed", reportHeader.dateOfAnalyze.ToString("dd MMMM yyyy") + "")); reportParameters.Add(new ReportParameter("DateTestCompleted", reportHeader.dateOfTestComplete.ToString("dd MMMM yyyy") + "")); reportParameters.Add(new ReportParameter("SampleDescription", reportHeader.description)); reportParameters.Add(new ReportParameter("Test", "-")); reportParameters.Add(new ReportParameter("ResultDesc", lbResultDesc.Text)); reportParameters.Add(new ReportParameter("AlsSingaporeRefNo", (String.IsNullOrEmpty(this.jobSample.singapore_ref_no) ? String.Empty : this.jobSample.singapore_ref_no))); // Variables Warning[] warnings; string[] streamIds; string mimeType = string.Empty; string encoding = string.Empty; string extension = string.Empty; List <template_wd_corrosion_img> dat = new List <template_wd_corrosion_img>(); template_wd_corrosion_img tmp = new template_wd_corrosion_img(); template_wd_corrosion_img corImg = this.refImg.Where(x => x.img_type.Value == 1).FirstOrDefault(); if (corImg != null) { tmp.img1 = CustomUtils.GetBytesFromImage(corImg.path_img1); } corImg = this.refImg.Where(x => x.img_type.Value == 2).FirstOrDefault(); if (corImg != null) { tmp.img2 = CustomUtils.GetBytesFromImage(corImg.path_img1); } dat.Add(tmp); // Setup the report viewer object and get the array of bytes ReportViewer viewer = new ReportViewer(); viewer.ProcessingMode = ProcessingMode.Local; viewer.LocalReport.ReportPath = Server.MapPath("~/ReportObject/corrosion_wd.rdlc"); viewer.LocalReport.SetParameters(reportParameters); viewer.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", dtHeader)); // Add datasource here viewer.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", dtResult)); // Add datasource here viewer.LocalReport.DataSources.Add(new ReportDataSource("DataSet3", dat.ToDataTable())); // Add datasource here string download = String.Empty; StatusEnum status = (StatusEnum)Enum.Parse(typeof(StatusEnum), this.jobSample.job_status.ToString(), true); switch (status) { case StatusEnum.ADMIN_CONVERT_WORD: if (!String.IsNullOrEmpty(this.jobSample.path_word)) { Response.Redirect(String.Format("{0}{1}", Configurations.HOST, this.jobSample.path_word)); } else { byte[] bytes = viewer.LocalReport.Render("Word", null, out mimeType, out encoding, out extension, out streamIds, out warnings); if (!Directory.Exists(Server.MapPath("~/Report/"))) { Directory.CreateDirectory(Server.MapPath("~/Report/")); } using (FileStream fs = File.Create(Server.MapPath("~/Report/") + this.jobSample.job_number + "_orginal." + extension)) { fs.Write(bytes, 0, bytes.Length); } #region "Insert Footer & Header from template" Document doc1 = new Document(); doc1.LoadFromFile(Server.MapPath("~/template/") + "Blank Letter Head - EL.doc"); Spire.Doc.HeaderFooter header = doc1.Sections[0].HeadersFooters.Header; Spire.Doc.HeaderFooter footer = doc1.Sections[0].HeadersFooters.Footer; Document doc2 = new Document(Server.MapPath("~/Report/") + this.jobSample.job_number + "_orginal." + extension); foreach (Section section in doc2.Sections) { foreach (DocumentObject obj in header.ChildObjects) { section.HeadersFooters.Header.ChildObjects.Add(obj.Clone()); } foreach (DocumentObject obj in footer.ChildObjects) { section.HeadersFooters.Footer.ChildObjects.Add(obj.Clone()); } } doc2.SaveToFile(Server.MapPath("~/Report/") + this.jobSample.job_number + "." + extension); #endregion Response.ContentType = mimeType; Response.AddHeader("Content-Disposition", "attachment; filename=" + this.jobSample.job_number + "." + extension); Response.WriteFile(Server.MapPath("~/Report/" + this.jobSample.job_number + "." + extension)); Response.Flush(); #region "Delete After Download" String deleteFile1 = Server.MapPath("~/Report/") + this.jobSample.job_number + "." + extension; String deleteFile2 = Server.MapPath("~/Report/") + this.jobSample.job_number + "_orginal." + extension; if (File.Exists(deleteFile1)) { File.Delete(deleteFile1); } if (File.Exists(deleteFile2)) { File.Delete(deleteFile2); } #endregion } break; case StatusEnum.LABMANAGER_CHECKING: case StatusEnum.LABMANAGER_APPROVE: case StatusEnum.LABMANAGER_DISAPPROVE: if (!String.IsNullOrEmpty(this.jobSample.path_word)) { Response.Redirect(String.Format("{0}{1}", Configurations.HOST, this.jobSample.path_word)); } break; case StatusEnum.ADMIN_CONVERT_PDF: if (!String.IsNullOrEmpty(this.jobSample.path_word)) { Response.Redirect(String.Format("{0}{1}", Configurations.HOST, this.jobSample.path_word)); } //if (!String.IsNullOrEmpty(this.jobSample.path_word)) //{ // Word2Pdf objWorPdf = new Word2Pdf(); // objWorPdf.InputLocation = String.Format("{0}{1}", Configurations.PATH_DRIVE, this.jobSample.path_word); // objWorPdf.OutputLocation = String.Format("{0}{1}", Configurations.PATH_DRIVE, this.jobSample.path_word).Replace("doc", "pdf"); // try // { // objWorPdf.Word2PdfCOnversion(); // Response.Redirect(String.Format("{0}{1}", Configurations.HOST, this.jobSample.path_word).Replace("doc", "pdf")); // } // catch (Exception ex) // { // Console.WriteLine(); // Response.Redirect(String.Format("{0}{1}", Configurations.HOST, this.jobSample.path_word)); // } //} break; } }