/// <summary> /// Defines page setup, headers, and footers. /// </summary> static void DefineContentSection(Document document) { Section section = document.AddSection(); section.PageSetup.OddAndEvenPagesHeaderFooter = true; section.PageSetup.StartingNumber = 1; HeaderFooter header = section.Headers.Primary; header.AddParagraph("\tOdd Page Header"); header = section.Headers.EvenPage; header.AddParagraph("Even Page Header"); // Create a paragraph with centered page number. See definition of style "Footer". Paragraph paragraph = new Paragraph(); paragraph.AddTab(); paragraph.AddPageField(); // Add paragraph to footer for odd pages. section.Footers.Primary.Add(paragraph); // Add clone of paragraph to footer for odd pages. Cloning is necessary because an object must // not belong to more than one other object. If you forget cloning an exception is thrown. section.Footers.EvenPage.Add(paragraph.Clone()); }
private void CriaIdentificacao() { HeaderFooter headers = _document.LastSection.Headers.Primary; headers.AddParagraph($"Empresa: {_Quarentena.Lote.NotaFiscal.Empresa.RazaoSocial} | {_Quarentena.Lote.NotaFiscal.Empresa.Sigla}"); headers.AddParagraph($"Usuário: {_request.NomeUsuario}"); headers.AddParagraph($"Data: {DateTime.Now.ToString("dd/MM/yyyy HH:mm")}"); headers.AddParagraph($"COD: {_Quarentena.CodigoConfirmacao}"); }
/// <summary> /// Defines page setup, headers, and footers. /// </summary> private void DefineContentSection(Document document, Report report) { Section section = document.AddSection(); section.PageSetup.OddAndEvenPagesHeaderFooter = true; section.PageSetup.StartingNumber = 1; section.PageSetup.Orientation = (this.Landscape ? Orientation.Landscape : Orientation.Portrait); HeaderFooter header = section.Headers.Primary; header.AddParagraph(report.TextFields.Footer); header = section.Headers.EvenPage; header.AddParagraph(report.TextFields.Footer); // Create a paragraph with centered page number. See definition of style "Footer". Paragraph paragraph = new Paragraph(); paragraph.AddTab(); paragraph.AddPageField(); // Add paragraph to footer for odd pages. section.Footers.Primary.Add(paragraph); // Add clone of paragraph to footer for odd pages. Cloning is necessary because an object must // not belong to more than one other object. If you forget cloning an exception is thrown. section.Footers.EvenPage.Add(paragraph.Clone()); paragraph = document.LastSection.AddParagraph(); paragraph.Format.Alignment = ParagraphAlignment.Center; paragraph.Format.Font.Bold = true; paragraph.Format.Font.Color = Colors.DarkBlue; paragraph.Format.Font.Size = 14; paragraph.AddText(report.TextFields.Title); paragraph = document.LastSection.AddParagraph(); paragraph.AddText(""); paragraph = document.LastSection.AddParagraph(); paragraph.Format.Alignment = ParagraphAlignment.Center; paragraph.Format.Font.Bold = true; paragraph.Format.Font.Size = 12; paragraph.Format.Font.Color = Colors.DarkBlue; paragraph.AddText(report.TextFields.SubTitle); paragraph = document.LastSection.AddParagraph(); paragraph.AddText(""); paragraph = document.LastSection.AddParagraph(); paragraph.Format.Alignment = ParagraphAlignment.Left; paragraph.Format.Font.Bold = true; paragraph.AddText(report.TextFields.Header); paragraph = document.LastSection.AddParagraph(); paragraph.AddText(""); }
private void FormEmail_Load(object sender, EventArgs e) { txtHost.Text = settings.Host; txtForm.Text = settings.From; txtName.Text = settings.Name; txtPassword.Text = settings.Password; txtSubjec.Text = settings.EmailSubject; txtPort.Text = settings.Port; if (settings.Encryption == "SSL") { comboBox1.SelectedIndex = 1; } else if (settings.Encryption == "") { comboBox1.SelectedIndex = 0; } DirectoryInfo d = new DirectoryInfo(textBox2.Text + "\\"); //Assuming Test is your Folder FileInfo[] Files = d.GetFiles(".\\" + "email*.dotx"); //Getting Text files if (Files.Length == 0) { //Create word document Document document = new Document(); Paragraph p = document.AddSection().AddParagraph(); TextRange txtRang = p.AppendText("H63TWX11072"); txtRang.CharacterFormat.FontName = "C39HrP60DlTt"; txtRang.CharacterFormat.FontSize = 80; txtRang.CharacterFormat.TextColor = Color.SeaGreen; Section section = document.AddSection(); //Initialize a Header Instance HeaderFooter header = document.Sections[0].HeadersFooters.Header; //Add Header Paragraph and Format Paragraph paragraph = header.AddParagraph(); paragraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Left; //Append Picture for Header Paragraph and Format Spire.Doc.Fields.DocPicture headerimage = paragraph.AppendPicture(Image.FromFile(@"dackeasy_logo.png")); headerimage.VerticalAlignment = ShapeVerticalAlignment.Bottom; paragraph = section.AddParagraph(); string str = "Dear <CONTACT PERSON>," + "\r\n"; paragraph.AppendText(str); str = "As an independent Word .NET component, Spire.Doc for .NET doesn't need Microsoft Word to be installed on the machine. However, it can incorporate Microsoft Word document creation capabilities into any developers.NET applications.As an independent Word .NET component, Spire.Doc for .NET doesn't need Microsoft Word to be installed on the machine. However, it can incorporate Microsoft Word document creation capabilities into any developers’.NET applications." + "\r\n"; paragraph.AppendText(str); document.SaveToFile("email.dotx", FileFormat.Dotx); d = new DirectoryInfo(Directory.GetCurrentDirectory());//Assuming Test is your Folder Files = d.GetFiles("email*.dotx"); } comboBox2.DataSource = Files; comboBox2.DisplayMember = "demo"; //Center(this); }
private void InsertHeaderAndFooter(Section section) { HeaderFooter header = section.HeadersFooters.Header; HeaderFooter footer = section.HeadersFooters.Footer; //Insert picture and text to header. Paragraph headerParagraph = header.AddParagraph(); DocPicture headerPicture = headerParagraph.AppendPicture(Image.FromFile(@"..\..\..\..\..\..\Data\Header.png")); //Header text. TextRange text = headerParagraph.AppendText("Demo of Spire.Doc"); text.CharacterFormat.FontName = "Arial"; text.CharacterFormat.FontSize = 10; text.CharacterFormat.Italic = true; headerParagraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Right; //Border. headerParagraph.Format.Borders.Bottom.BorderType = Spire.Doc.Documents.BorderStyle.Single; headerParagraph.Format.Borders.Bottom.Space = 0.05F; //Header picture layout - text wrapping. headerPicture.TextWrappingStyle = TextWrappingStyle.Behind; //Header picture layout - position. headerPicture.HorizontalOrigin = HorizontalOrigin.Page; headerPicture.HorizontalAlignment = ShapeHorizontalAlignment.Left; headerPicture.VerticalOrigin = VerticalOrigin.Page; headerPicture.VerticalAlignment = ShapeVerticalAlignment.Top; //Insert picture to footer. Paragraph footerParagraph = footer.AddParagraph(); DocPicture footerPicture = footerParagraph.AppendPicture(Image.FromFile(@"..\..\..\..\..\..\Data\Footer.png")); //Footer picture layout. footerPicture.TextWrappingStyle = TextWrappingStyle.Behind; footerPicture.HorizontalOrigin = HorizontalOrigin.Page; footerPicture.HorizontalAlignment = ShapeHorizontalAlignment.Left; footerPicture.VerticalOrigin = VerticalOrigin.Page; footerPicture.VerticalAlignment = ShapeVerticalAlignment.Bottom; //Insert page number. footerParagraph.AppendField("page number", FieldType.FieldPage); footerParagraph.AppendText(" of "); footerParagraph.AppendField("number of pages", FieldType.FieldNumPages); footerParagraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Right; //Border. footerParagraph.Format.Borders.Top.BorderType = Spire.Doc.Documents.BorderStyle.Single; footerParagraph.Format.Borders.Top.Space = 0.05F; }
private void button1_Click(object sender, EventArgs e) { Document doc = new Document(); doc.AddSection(); Section sec = doc.Sections[0]; Paragraph Para = sec.AddParagraph(); Para.AppendText("Welcome to the Document created by Ram!"); doc.SaveToFile("SampleDoc.docx", FileFormat.Docx); doc.AddSection(); //Add Header Section section = doc.Sections[1]; HeaderFooter header = section.HeadersFooters.Header; Paragraph HeaderParagraph = header.AddParagraph(); TextRange HeaderText = HeaderParagraph.AppendText("Restaurant for everyone \n"); //Set Header Text Format HeaderText.CharacterFormat.FontName = "Cambria"; HeaderText.CharacterFormat.FontSize = 11; HeaderText.CharacterFormat.TextColor = Color.OrangeRed; //Set Header Paragraph Format HeaderParagraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Left; HeaderParagraph.Format.Borders.Bottom.BorderType = Spire.Doc.Documents.BorderStyle.ThickThinMediumGap; HeaderParagraph.Format.Borders.Bottom.Space = 0.05f; HeaderParagraph.Format.Borders.Bottom.Color = Color.DarkGray; DocPicture headerimage = HeaderParagraph.AppendPicture(Image.FromFile(@"G:\RameshKartik\Tech\C# Samples\SpireDoc\WorkingWithMsWord\WorkingWithMsWord\bin\Debug\test.png")); headerimage.VerticalAlignment = ShapeVerticalAlignment.Bottom; doc.SaveToFile("SampleDoc.docx", FileFormat.Docx); //Add Footer HeaderFooter footer = section.HeadersFooters.Footer; Paragraph FooterParagraph = footer.AddParagraph(); TextRange FooterText = FooterParagraph.AppendText("My Company.,Footer Information"); //Set Footer Text Format FooterText.CharacterFormat.FontName = "Calibri"; FooterText.CharacterFormat.FontSize = 12; FooterText.CharacterFormat.TextColor = Color.Brown; //Set Footer Paragrah Format FooterParagraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Right; FooterParagraph.Format.Borders.Top.BorderType = Spire.Doc.Documents.BorderStyle.ThinThinSmallGap; FooterParagraph.Format.Borders.Top.Space = 0.15f; FooterParagraph.Format.Borders.Color = Color.DarkGray; doc.SaveToFile("SampleDoc.docx", FileFormat.Docx); MessageBox.Show("Document Created!"); }
private static void ToWord() { //Configure path. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); string filePath = desktopPath + @"\test.docx"; string picPath = desktopPath + @"\wang.jpg"; //Create a word document. Document doc = new Document(); //Add a section. Section section = doc.AddSection(); //Add a paragraph. Paragraph paragraph = section.AddParagraph(); paragraph.AppendText("Spire is me."); //Add a comment. string content = "CNblog:http://www.cnblogs.com/LanTianYou/"; Comment comment = paragraph.AppendComment(content); comment.Format.Author = "Tylan"; //Set font style for the paragraph. ParagraphStyle style = new ParagraphStyle(doc); style.Name = "TylanFontStyle"; style.CharacterFormat.FontName = "Batang"; style.CharacterFormat.FontSize = 36; style.CharacterFormat.TextColor = Color.Green; doc.Styles.Add(style); paragraph.ApplyStyle(style.Name); //Insert a picture. DocPicture pic = paragraph.AppendPicture(Image.FromFile(picPath)); pic.Width = 500; pic.Height = 500; //Add header. HeaderFooter header = doc.Sections[0].HeadersFooters.Header; Paragraph headerParagraph = header.AddParagraph(); TextRange headerText = headerParagraph.AppendText("Spire header"); headerText.CharacterFormat.FontSize = 18; headerText.CharacterFormat.TextColor = Color.Tomato; headerParagraph.Format.Borders.Bottom.BorderType = BorderStyle.ThinThinSmallGap; headerParagraph.Format.Borders.Bottom.Space = 0.15f; headerParagraph.Format.Borders.Color = Color.DarkGray; //Add footer. HeaderFooter footer = doc.Sections[0].HeadersFooters.Footer; Paragraph footerParagraph = footer.AddParagraph(); TextRange footerText = footerParagraph.AppendText("Spire footer"); footerText.CharacterFormat.FontSize = 18; footerText.CharacterFormat.TextColor = Color.Tomato; footerParagraph.Format.Borders.Top.BorderType = BorderStyle.ThinThinSmallGap; footerParagraph.Format.Borders.Top.Space = 0.15f; footerParagraph.Format.Borders.Color = Color.DarkGray; //Save the file. doc.SaveToFile(filePath, FileFormat.Docx); }
static void AddCustomFooter(string text, ref Section section) { HeaderFooter footer = new HeaderFooter(); footer.AddParagraph(text); footer.Format.Font.Size = 10; footer.Format.Font.Name = "Times-Roman"; footer.Format.Alignment = ParagraphAlignment.Center; section.Footers.Primary = footer.Clone(); }
public void AddTitle(string pTitle, Font pFont) { section.PageSetup.OddAndEvenPagesHeaderFooter = true; section.PageSetup.StartingNumber = 1; HeaderFooter header = section.Headers.Primary; header.Format.Font = pFont; header.Format.Alignment = ParagraphAlignment.Center; header.AddParagraph(pTitle); }
public string Create() { string resultFile = null; var utcNow = DateTime.UtcNow; var seasonEntity = SeasonsRepository.Get(utcNow); if (seasonEntity == null) { throw new Exception($"There is no Fantasy Football Season covering the Date = {utcNow:yyyy-MMM-dd}."); } _seasonId = seasonEntity.SeasonId; _weekOffset = DateTimeHelper.GetWeekOffset(seasonEntity, utcNow); var firstResultsSet = TeamsRepository.GetFirstOrDefault(entity => (entity.SeasonId == _seasonId) && (entity.WeekOffset == _weekOffset)); if (firstResultsSet == null) { throw new Exception($"There is no Weekly Results Set covering the Date = {utcNow:yyyy-MMM-dd}, otherwise known as Season Id = {_seasonId} and Week Offset = {_weekOffset}."); } _document = new Document(); var teamEntities = TeamsRepository .GetAll(_seasonId, _weekOffset); foreach (var teamEntity in teamEntities) { AddTeam(teamEntity); } HeaderFooter footer = _document.Sections[0].HeadersFooters.Footer; Paragraph footerParagraph = footer.AddParagraph(); var textRange = footerParagraph.AppendText($"Season Id = {_seasonId} : Week Offset = {_weekOffset} : Page "); textRange.CharacterFormat.FontName = "Calibri"; textRange = footerParagraph.AppendField("page number", FieldType.FieldPage); textRange.CharacterFormat.FontName = "Calibri"; footerParagraph.Format.HorizontalAlignment = HorizontalAlignment.Center; resultFile = $"Fantasy Football Assistant - {DateTime.UtcNow:yyyy-MMM-dd}.docx"; _document.SaveToFile($"wwwroot\\{resultFile}", FileFormat.Docx2013); return(resultFile); }
private void button1_Click(object sender, EventArgs e) { //Load the document from disk string input = @"..\..\..\..\..\..\Data\Template.docx"; Document doc = new Document(); doc.LoadFromFile(input); //Get the header of the first page HeaderFooter header = doc.Sections[0].HeadersFooters.Header; //Add a paragraph for the header Paragraph paragraph = header.AddParagraph(); //Set the format of the paragraph paragraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Right; //Append a picture in the paragraph DocPicture headerimage = paragraph.AppendPicture(Image.FromFile(@"..\..\..\..\..\..\Data\E-iceblue.png")); headerimage.VerticalAlignment = ShapeVerticalAlignment.Bottom; //Get the footer of the first section HeaderFooter footer = doc.Sections[0].HeadersFooters.Footer; //Add a paragraph for the footer Paragraph paragraph2 = footer.AddParagraph(); //Set the format of the paragraph paragraph2.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Left; //Append a picture in the paragraph DocPicture footerimage = paragraph2.AppendPicture(Image.FromFile(@"..\..\..\..\..\..\Data\logo.png")); //Append text in the paragraph TextRange TR = paragraph2.AppendText("Copyright © 2013 e-iceblue. All Rights Reserved."); TR.CharacterFormat.FontName = "Arial"; TR.CharacterFormat.FontSize = 10; TR.CharacterFormat.TextColor = Color.Black; //Save and launch document string output = "ImageHeaderAndFooter.docx"; doc.SaveToFile(output, FileFormat.Docx); Viewer(output); }
private void setHeaderFont(ref HeaderFooter header, string value, int fontSize, string fontName, bool isBold = false, bool isBorder = false) { Paragraph paragraph = header.AddParagraph(); TextRange tRange = paragraph.AppendText(value); tRange.CharacterFormat.FontName = fontName; tRange.CharacterFormat.FontSize = fontSize; tRange.CharacterFormat.Bold = isBold; tRange.CharacterFormat.TextColor = Color.Black; paragraph.Format.HorizontalAlignment = HorizontalAlignment.Center; paragraph.Format.TextAlignment = TextAlignment.Center; if (isBorder) { paragraph.Format.Borders.Bottom.BorderType = BorderStyle.ThickThinMediumGap; paragraph.Format.Borders.Bottom.Space = 0.05f; paragraph.Format.Borders.Bottom.Color = Color.Black; } }
private void createFooter(ref Section section) { //Add Header HeaderFooter footer = section.HeadersFooters.Footer; Paragraph FParagraph = footer.AddParagraph(); TextRange FText = FParagraph.AppendText("PARAMASHETTI, MULTI SPECIALITY HOSPITAL"); FText.CharacterFormat.FontName = "Calibri"; //Set Footer Text Format FText.CharacterFormat.FontSize = 12; FText.CharacterFormat.TextColor = Color.DarkGray; //Set Footer Paragrah Format FParagraph.Format.HorizontalAlignment = HorizontalAlignment.Right; FParagraph.Format.Borders.Top.BorderType = BorderStyle.Single; FParagraph.Format.Borders.Top.Space = 0.15f; FParagraph.Format.Borders.Color = Color.DarkGray; }
/// <summary> /// Defines page setup, headers, and footers. /// </summary> static void DefineContentSection(Document document, ArticlesWithWordMigra article) { Section section = document.AddSection(); section.PageSetup.OddAndEvenPagesHeaderFooter = false; section.PageSetup.StartingNumber = 1; HeaderFooter header = section.Headers.Primary; header.AddParagraph(article.EditionName + "\t" + article.Url); // Create a paragraph with centered page number. See definition of style "Footer". Paragraph paragraph = new Paragraph(); paragraph.AddTab(); paragraph.AddPageField(); // Add paragraph to footer for odd pages. section.Footers.Primary.Add(paragraph); }
private void createHeader() { Section currentSection = (Section)serviceSheetDoc.Sections.LastObject; HeaderFooter header = currentSection.Headers.Primary; Paragraph headerPara = header.AddParagraph("Report No. " + currentSheet.SubmissionNumber); headerPara.Format.Alignment = ParagraphAlignment.Right; header.Style = "Normal"; //Separate header for first page HeaderFooter firstPageHeader = currentSection.Headers.FirstPage; Paragraph headerParaFirstPage = firstPageHeader.AddParagraph(); headerParaFirstPage.Format.Alignment = ParagraphAlignment.Right; //RT 30/1/17 - Adding US logo Image imgHeaderLogo = null; if (currentSheet.UkServiceSheet == true) { imgHeaderLogo = Service_Reader.Properties.Resources.MTTHeaderLogo; } else if (currentSheet.UkServiceSheet == false) { imgHeaderLogo = Service_Reader.Properties.Resources.MTTIncHeaderlogo; } else { Console.WriteLine("UK/US job not identified"); } string headerLogoStr = imageToMigradocString(imgHeaderLogo); var headerFirstPage = headerParaFirstPage.AddImage(headerLogoStr); if (currentSheet.UkServiceSheet == false) { headerFirstPage.Height = new Unit(1.31, UnitType.Centimeter); headerFirstPage.LockAspectRatio = true; } headerFirstPage.Top = MigraDoc.DocumentObjectModel.Shapes.ShapePosition.Top; headerFirstPage.Left = MigraDoc.DocumentObjectModel.Shapes.ShapePosition.Right; }
/// <summary> /// Defines page setup, headers, and footers. /// </summary> static void DefineContentSection(Document document) { Section section = document.AddSection(); section.PageSetup.StartingNumber = 1; HeaderFooter header = section.Headers.Primary; header.Format.Alignment = ParagraphAlignment.Right; header.AddParagraph("\t Page Header"); // Create a paragraph with centered page number. See definition of style "Footer". Paragraph paragraph = new Paragraph(); paragraph.AddTab(); paragraph.AddPageField(); // Add paragraph to footer for odd pages. section.Footers.Primary.Add(paragraph); }
private static void footer(Document document) { Section section2 = document.LastSection; section2.PageSetup.OddAndEvenPagesHeaderFooter = false; section2.PageSetup.StartingNumber = 1; section2.PageSetup.BottomMargin = new Unit(1, UnitType.Centimeter); HeaderFooter footer = section2.Footers.Primary; ////TextFrame framefooter = new TextFrame(); ////framefooter.Width = new Unit(500); ////framefooter.Height = new Unit(5); ////framefooter.WrapFormat.DistanceBottom= new Unit(-200); ////var par = framefooter.AddParagraph(); ////par.AddFormattedText("Para consultar el documento ingrese a portal.factura.com.pe/corpora"); ////par.Format.Alignment = ParagraphAlignment.Left; ////var parr = framefooter.AddParagraph(); ////parr.AddFormattedText("Powered"); ////parr.Format.Alignment = ParagraphAlignment.Right; ////parr.Format.RightIndent = new Unit(100); ////var parrr = framefooter.AddParagraph(); ////parrr.AddFormattedText("\t\t\tby VIDA.SOFTWARE"); ////parrr.Format.Alignment = ParagraphAlignment.Right; //section2.Add(framefooter); var paragraph = footer.AddParagraph(); //paragraph.AddFormattedText("\n\n\n\n\n"); paragraph.AddFormattedText("Para consultar el documento ingrese a portal.factura.com.pe/corpora\n\t\t\t\tPowered\n\t\t\t\t\tby VIDA.SOFTWARE"); paragraph.Format.Alignment = ParagraphAlignment.Left; //NumToWords totalWord = new NumToWords(); //string numero = "57.60"; //Console.WriteLine(totalWord.Convertir(numero,true)); //Console.ReadLine(); }
private void button1_Click(object sender, EventArgs e) { //Create Word document. Document document = new Document(); //Load the file from disk. document.LoadFromFile(@"..\..\..\..\..\..\Data\Template_Docx_4.docx"); //Repeat step2 and Step3 for the rest sections, so change the code with for loop. for (int i = 0; i < 3; i++) { HeaderFooter footer = document.Sections[i].HeadersFooters.Footer; Paragraph footerParagraph = footer.AddParagraph(); footerParagraph.AppendField("page number", FieldType.FieldPage); footerParagraph.AppendText(" of "); footerParagraph.AppendField("number of pages", FieldType.FieldSectionPages); footerParagraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Right; if (i == 2) { break; } else { document.Sections[i + 1].PageSetup.RestartPageNumbering = true; document.Sections[i + 1].PageSetup.PageStartingNumber = 1; } } String result = "Result-AddPageNumbersInSections.docx"; //Save to file. document.SaveToFile(result, FileFormat.Docx2013); //Launch the Ms Word file. WordDocViewer(result); }
private void Form1_Load(object sender, EventArgs e) { ////List<template_wd_mesa_coverpage> coverpages = template_wd_mesa_coverpage.FindAllBySampleID(2726); ////List<template_wd_mesa_img> refImg = template_wd_mesa_img.FindAllBySampleID(2726); //Create Table Document doc = new Document(); Section s = doc.AddSection(); #region "PAGE SETUP" s.PageSetup.PageSize = PageSize.A4; s.PageSetup.Orientation = PageOrientation.Portrait; s.PageSetup.Margins.Top = 100.0f; s.PageSetup.Margins.Bottom = 72.0f; //s.PageSetup.Margins.Left = 89.85f; //s.PageSetup.Margins.Right = 89.85f; #endregion #region "FONT FORMAT" CharacterFormat format = new CharacterFormat(doc); format.FontName = "Arial"; format.FontSize = 15; format.Bold = false; format.UnderlineStyle = UnderlineStyle.Single; CharacterFormat format2 = new CharacterFormat(doc); format2.FontName = "Arial"; format2.FontSize = 11; format2.Bold = false; format2.UnderlineStyle = UnderlineStyle.Single; #endregion //Initialize a Header Instance HeaderFooter header = doc.Sections[0].HeadersFooters.Header; //Add Header Paragraph and Format Paragraph paragraph1 = header.AddParagraph(); paragraph1.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Right; //Append Picture for Header Paragraph and Format DocPicture headerimage = paragraph1.AppendPicture(Image.FromFile(@"C:\Users\icnsk\Documents\Visual Studio 2015\Projects\ALS.ALSI.Web\ALS.ALSI.Web\images\images.png")); headerimage.VerticalAlignment = ShapeVerticalAlignment.Bottom; #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 table = s.AddTable(true); //Create Header and Data String[] Header = { "", "", }; String[][] data = { new String[] { "CUSTOMER PO NO.:", "" }, new String[] { "ALS THAILAND REF NO.:", "ATT/ELP/16/3148-MB" }, new String[] { "DATE:", "13 January 2017" }, new String[] { "COMPANY:", "Thai Dai-Ichi Seiko Co., Ltd." }, new String[] { "", "700/390 Moo.6 T.Donhuaroh, A.Muang Chonburi" }, new String[] { "", "Chonburi 20000 Thailand" }, new String[] { "", "" }, new String[] { "DATE SAMPLE RECEIVED:", "13 January 2017" }, new String[] { "DATE ANALYZED:", "13 January 2017" }, new String[] { "DATE TEST COMPLETED:", "13 January 2017" }, new String[] { "", "" }, new String[] { "SAMPLE DESCRIPTION:", "One lot of sample was received with references:" }, new String[] { "", "Description: Ramp Shrek (2063-778130-000) M.2" }, new String[] { "", "Lot No.7D2063778130000AASDI0200006Z1400100" }, new String[] { "", "Surface Area: 7.73 sq.cm" }, }; //Add Cells table.ResetCells(data.Length, Header.Length); //Header Row //TableRow FRow = table.Rows[0]; //FRow.IsHeader = false; ////Row Height //FRow.Height = 23; ////Header Format //FRow.RowFormat.BackColor = Color.AliceBlue; //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 = Spire.Doc.Documents.HorizontalAlignment.Center; // //Data Format // TextRange TR = p.AppendText(Header[i]); // TR.CharacterFormat.FontName = "Calibri"; // TR.CharacterFormat.FontSize = 14; // TR.CharacterFormat.TextColor = Color.Teal; // TR.CharacterFormat.Bold = true; //} //Data Row for (int r = 0; r < data.Length; r++) { TableRow DataRow = table.Rows[r]; //Row Height DataRow.Height = 11; DataRow.Cells[0].SetCellWidth(30, CellWidthType.Percentage); DataRow.Cells[1].SetCellWidth(70, CellWidthType.Percentage); //C Represents Column. for (int c = 0; c < data[r].Length; c++) { //Cell Alignment DataRow.Cells[c].CellFormat.VerticalAlignment = VerticalAlignment.Middle; //Fill Data in Rows Paragraph p2 = DataRow.Cells[c].AddParagraph(); TextRange TR2 = p2.AppendText(data[r][c]); //Format Cells p2.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Left; TR2.CharacterFormat.FontName = "Arial"; TR2.CharacterFormat.FontSize = 11; TR2.CharacterFormat.TextColor = Color.Black; DataRow.Cells[c].CellFormat.Borders.Bottom.BorderType = Spire.Doc.Documents.BorderStyle.None; DataRow.Cells[c].CellFormat.Borders.Top.BorderType = Spire.Doc.Documents.BorderStyle.None; DataRow.Cells[c].CellFormat.Borders.Left.BorderType = Spire.Doc.Documents.BorderStyle.None; DataRow.Cells[c].CellFormat.Borders.Right.BorderType = Spire.Doc.Documents.BorderStyle.None; } } table.TableFormat.Borders.Bottom.BorderType = Spire.Doc.Documents.BorderStyle.None; table.TableFormat.Borders.Top.BorderType = Spire.Doc.Documents.BorderStyle.None; table.TableFormat.Borders.Left.BorderType = Spire.Doc.Documents.BorderStyle.None; table.TableFormat.Borders.Right.BorderType = Spire.Doc.Documents.BorderStyle.None; #endregion #region "Method/Procedure" Paragraph pBlank = s.AddParagraph(); pBlank.AppendText(""); Paragraph pMethodProcedure = s.AddParagraph(); pMethodProcedure.AppendText("METHOD/PROCEDURE:").ApplyCharacterFormat(format2); #endregion //Save and Launch doc.SaveToFile("WordTable.docx"); System.Diagnostics.Process.Start("WordTable.docx"); //string[] lines; //var list = new List<string>(); //var fileStream = new FileStream(@"C:\Users\icnsk\Downloads\sky_room_ad\JSON_MUIC_Room_List.txt FileMode.Open, FileAccess.Read); //using (var streamReader = new StreamReader(fileStream, Encoding.UTF8)) //{ // string line; // while ((line = streamReader.ReadLine()) != null) // { // if (line.IndexOf("room_number") != -1) // { // Console.WriteLine(line); // list.Add(line); // } // } //} //lines = list.ToArray(); //Document sourceDoc = new Document(@"C:\Users\icnsk\Downloads\ELP-1362A-DB1.doc"); //Document destinationDoc = new Document(@"C:\Users\icnsk\Downloads\Blank Letter Head - EL.doc"); //foreach (Section sec in sourceDoc.Sections) //{ // foreach (DocumentObject obj in sec.Body.ChildObjects) // { // destinationDoc.Sections[0].Body.ChildObjects.Add(obj.Clone()); // } //} //destinationDoc.SaveToFile("target.docx"); ////System.Diagnostics.Process.Start("target.docx"); //Document document = new Document(); //document.LoadFromFile(@"target.docx"); ////Convert Word to PDF //document.SaveToFile("toPDF.PDF FileFormat.PDF); ////Launch Document //System.Diagnostics.Process.Start("toPDF.PDF"); }
static void Cabecera(Document document, Documento doc, List <Detalle> listadetalle) { Section section = document.AddSection(); section.PageSetup.PageFormat = PageFormat.A4; section.PageSetup.TopMargin = new Unit(10, UnitType.Millimeter); section.PageSetup.LeftMargin = new Unit(10, UnitType.Millimeter); section.PageSetup.RightMargin = new Unit(10, UnitType.Millimeter); section.PageSetup.OddAndEvenPagesHeaderFooter = false; section.PageSetup.StartingNumber = 1; HeaderFooter header = section.Headers.Primary; //header.AddParagraph("\tOdd Page Header"); //string ii = Path.Combine(cr, "logo.jpg"); string cr = @"E:\ProgramaC#\senddocs\logo.jpg"; if (File.Exists(cr)) { Section sectionlogo = document.LastSection; TextFrame logo = new TextFrame(); logo.RelativeHorizontal = RelativeHorizontal.Margin; logo.RelativeVertical = RelativeVertical.Margin; var serienn = doc.serienumero.Substring(0, 1); if (doc.tipodocumento == "01") { logo.WrapFormat.DistanceTop = new Unit(-230); } else if (doc.tipodocumento == "03") { logo.WrapFormat.DistanceTop = new Unit(-180); } else if (doc.tipodocumento == "07") { logo.WrapFormat.DistanceTop = new Unit(-200); } var im = logo.AddImage(@"E:\ProgramaC#\senddocs\logo.jpg"); im.Width = new Unit(75); section.Add(logo); } TextFrame textFrame = new TextFrame(); //textFrame.MarginTop = new Unit(100, UnitType.Millimeter); textFrame.Width = new Unit(200); textFrame.Height = new Unit(100); textFrame.RelativeHorizontal = RelativeHorizontal.Margin; textFrame.RelativeVertical = RelativeVertical.Margin; textFrame.WrapFormat.DistanceLeft = new Unit(320); if (doc.tipodocumento == "01") { textFrame.WrapFormat.DistanceTop = new Unit(-260); } else if (doc.tipodocumento == "03") { textFrame.WrapFormat.DistanceTop = new Unit(-210); } else if (doc.tipodocumento == "07") { textFrame.WrapFormat.DistanceTop = new Unit(-230); } textFrame.LineFormat.Width = new Unit(1); textFrame.LineFormat.Color = MigraDoc.DocumentObjectModel.Colors.Black; //textFrame.FillFormat.Color = MigraDoc.DocumentObjectModel.Colors.Green; var texto = textFrame.AddParagraph("RUC:" + doc.rucempresa); texto.Format.Alignment = ParagraphAlignment.Center; texto.Style = "Heading1"; if (doc.tipodocumento == "01") { texto = textFrame.AddParagraph("FACTURA ELECTRÓNICA"); texto.Format.Alignment = ParagraphAlignment.Center; texto.Style = "Heading1"; } else if (doc.tipodocumento == "03") { texto = textFrame.AddParagraph("BOLETA ELECTRÓNICA"); texto.Format.Alignment = ParagraphAlignment.Center; texto.Style = "Heading1"; } else if (doc.tipodocumento == "07") { texto = textFrame.AddParagraph("Nota de Credito Electronica"); texto.Format.Alignment = ParagraphAlignment.Center; texto.Style = "Heading1"; } texto = textFrame.AddParagraph("\n" + doc.serienumero); texto.Format.Alignment = ParagraphAlignment.Center; texto.Style = "Heading1"; header.Add(textFrame); //string cr = @"E:\ProgramaC#\senddocs\logo.jpg"; var paragraph = header.AddParagraph(doc.razonsocialempresa); paragraph.Style = "Heading2"; paragraph = header.AddParagraph(); if (!File.Exists(cr)) { paragraph.AddText(doc.direccionempresa + "\n"); paragraph.AddText(doc.departamentoempresa + "," + doc.provinciaempresa + "," + doc.distritoempresa + "\n"); paragraph.AddText(doc.telefono1Empresa + "\n"); } else { TextFrame tflogo = new TextFrame(); var tl = tflogo.AddParagraph(); tflogo.Width = new Unit(250); tflogo.Height = new Unit(100); //tflogo.RelativeHorizontal = RelativeHorizontal.Margin; //tflogo.RelativeVertical = RelativeVertical.Margin; tflogo.WrapFormat.DistanceTop = new Unit(-10); tflogo.WrapFormat.DistanceLeft = new Unit(80); tflogo.WrapFormat.DistanceBottom = new Unit(-60); tflogo.AddParagraph(doc.direccionempresa + "\n"); tflogo.AddParagraph(doc.departamentoempresa + "," + doc.provinciaempresa + "," + doc.distritoempresa + "\n"); tflogo.AddParagraph(doc.telefono1Empresa + "\n"); //paragraph.AddText(doc.direccionempresa + "\n"); //paragraph.AddText(doc.departamentoempresa + "," + doc.provinciaempresa + "," + doc.distritoempresa + "\n"); //paragraph.AddText(doc.telefono1Empresa + "\n"); header.Add(tflogo); } if (doc.tipodocumento == "03") { paragraph = header.AddParagraph("\n\n\n"); paragraph.Style = "TOC"; paragraph.AddFormattedText("\nSEÑOR(es)\t", TextFormat.Bold); paragraph.AddText(doc.razonsocialcliente); paragraph.AddFormattedText("\nDNI No\t", TextFormat.Bold); paragraph.AddText(doc.numerodocumentocliente); paragraph.AddFormattedText("\nDIRECCIÓN\t", TextFormat.Bold); paragraph.AddText(doc.direccioncliente); paragraph.AddFormattedText("\nPARTIDA\t", TextFormat.Bold); paragraph.AddText(doc.puntopartida); } else if (doc.tipodocumento == "01") { paragraph = header.AddParagraph("\n\n\n"); paragraph.Style = "TOC"; paragraph.AddFormattedText("\nSEÑOR(es)\t", TextFormat.Bold); paragraph.AddText(doc.razonsocialcliente); paragraph.AddFormattedText("\nRUC No\t", TextFormat.Bold); paragraph.AddText(doc.numerodocumentocliente); paragraph.AddFormattedText("\nDIRECCIÓN\t", TextFormat.Bold); paragraph.AddText(doc.direccioncliente); paragraph.AddFormattedText("\nPARTIDA\t", TextFormat.Bold); paragraph.AddText(doc.puntopartida); paragraph.AddFormattedText("\nLLEGADA\t", TextFormat.Bold); paragraph.AddText(doc.puntollegada); paragraph.AddFormattedText("\nTRASNPORTE\t", TextFormat.Bold); paragraph.AddText(doc.codigochofer); paragraph.AddFormattedText("\nCOD.VEND\t", TextFormat.Bold); paragraph.AddText(doc.codigovendedor); paragraph.AddFormattedText("\nNOM.VEND\t", TextFormat.Bold); paragraph.AddText(doc.nombrevendedor); } if (doc.tipodocumento == "07") { paragraph = header.AddParagraph("\n\n\n"); paragraph.Style = "TOC"; paragraph.AddFormattedText("\nSEÑOR(es)\t", TextFormat.Bold); paragraph.AddText(doc.razonsocialcliente); paragraph.AddFormattedText("\nRUC No\t", TextFormat.Bold); paragraph.AddText(doc.numerodocumentocliente); paragraph.AddFormattedText("\nDIRECCIÓN\t", TextFormat.Bold); paragraph.AddText(doc.direccioncliente); paragraph.AddFormattedText("\nDOC.AFECTADO\t", TextFormat.Bold); paragraph.AddText(doc.serienumeroafectado + "\n"); paragraph.AddText(doc.sustentonotacredeb); } //Agregar Tabla paragraph.AddText("\n"); header.AddParagraph(""); Table table = new Table(); table.Borders.Width = 0.75; Column column = table.AddColumn(Unit.FromCentimeter(4)); column = table.AddColumn(Unit.FromCentimeter(4)); column = table.AddColumn(Unit.FromCentimeter(4)); column = table.AddColumn(Unit.FromCentimeter(4)); column.Format.Alignment = ParagraphAlignment.Center; table.AddColumn(Unit.FromCentimeter(4)); Row row = table.AddRow(); row.Shading.Color = Colors.LightGray; row.Format.Alignment = ParagraphAlignment.Center; Cell cell = row.Cells[0]; cell.AddParagraph("NO INTERNO"); cell = row.Cells[1]; cell.AddParagraph("FECHA EMISION"); cell = row.Cells[2]; cell.AddParagraph("FECHA VENCIMIENTO"); cell = row.Cells[3]; cell.AddParagraph("CONDICIONES"); cell = row.Cells[4]; cell.AddParagraph("GUIA REMISION"); row = table.AddRow(); row.Format.Alignment = ParagraphAlignment.Center; cell = row.Cells[0]; cell.AddParagraph(); cell = row.Cells[1]; cell.AddParagraph(doc.fechaemision); cell = row.Cells[2]; cell.AddParagraph(); cell = row.Cells[3]; cell.AddParagraph(doc.condicion); cell = row.Cells[4]; cell.AddParagraph(); //table.SetEdge(0, 0, 2, 3, Edge.Box, BorderStyle.Single, 1.5, Colors.Black); //string cr = @"E:\ProgramaC#\senddocs\logo.jpg"; //if (File.Exists(cr)) //{ // Section sectionlogo = document.LastSection; // TextFrame logo = new TextFrame(); // logo.WrapFormat.DistanceTop = new Unit(-475); // var im = logo.AddImage(@"E:\ProgramaC#\senddocs\logo.jpg"); // im.Width = new Unit(75); // section.Add(logo); //} header.Add(table); }
public Paragraph CreateHeaderParagraph(HeaderFooter header) { return(header.AddParagraph()); }
private void test() { System.Text.StringBuilder strBody = new System.Text.StringBuilder(""); strBody.Append("<table border=1 width=90% style='border-collapse: collapse;' bordercolor='black'><tr><td align=center><b>Food Group</b></td><td align=center><b>Servings</b></td></tr>"); strBody.Append("<tr><td>Grains and Cereals</td><td>4 - 5 serving /day Chapathi 1 or phulka 1 and half or any other grain raw handfist like Pasta or Rice or rawa or poha or Bread 2 slice ( domestic)</td></tr>"); strBody.Append("<tr><td>Dals, Pulses and Legumes</td><td>2 servings/day Thick or sprouts or Soya etc</td></tr>"); strBody.Append("<tr><td>Milk and Milk Products</td><td>300ml/day can be curd - 2 bowls/day</td></tr>"); strBody.Append("<tr><td>Egg and Non-veg</td><td>3 eggs / week Fish / Chicken twice week ( 100gm each time)</td></tr>"); strBody.Append("<tr><td>Vegetables</td><td>4 serving /day Any vegetable except potato 2 handful is one serving</td></tr>"); strBody.Append("<tr><td>Fruits</td><td>2 whole : any Fruit should be size of Tennis ball / size or whole</td></tr>"); strBody.Append("<tr><td>Sugar</td><td>2 tsp /day. If sweet tooth , Then avoid visible sugar in beverages</td></tr>"); strBody.Append("<tr><td>Fat</td><td>500ml/person/month Presently the type of oil which you are using is perfect.</td></tr>"); strBody.Append("<tr><td>Water</td><td>3 liters/day</td></tr>"); strBody.Append("</table><br/>"); strBody.Append("<table width=90%><tr><td><b>Things to Remember :</b></td></tr>"); strBody.Append("<tr><td><ol><li>Suspected food allergens are dairy, soy, gluten . ( you need to be cautious with these foods.) eat small meals if it does'nt bother you can increase the intake</li>"); strBody.Append("<li>Take adequate rest</li><li>Drink water</li><li>If you feel muscle spasms include calcium supplments/ and monitor vitamin D and B12</li><li>Reduce your exercise to normal walk/swim 45 minutes /daily</li></td></tr></table>"); strBody.Append("<table width=90%><tr><td><b>Supplements Advised:</b></td></tr></table><br/><br/><br/>"); strBody.Append("<table width=90%><tr><td><b>Investigation Advised:</b></td></tr></table><br/><br/><br/>"); strBody.Append("<table width=90%><tr><td><b>Follow up date :</b></td></tr><tr><td>After 15 days with weight and improvement symptoms.</td></tr></table><br/><br/>"); strBody.Append("<table width=90%><tr><td>PH_USER</td></tr><tr><td>Consultant Nutritionist & Registered Dietician</td></tr><tr><td>PH_CLINIC</td></tr><tr><td>Mob No: PH_MOB</td></tr></table><br/><br/>"); //Create word document Document document = new Document(); document.LoadFromFile(@"C:\Users\PATIL\Downloads\Alka_16Feb2017.doc"); //Get Paragraph var s = document.Sections[0]; Paragraph p = s.Paragraphs[1]; ParagraphStyle style = new ParagraphStyle(document); style.Name = "FontStyle"; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 10; document.Styles.Add(style); p.ApplyStyle(style.Name); Section section = document.AddSection(); //Add Header HeaderFooter header = section.HeadersFooters.Header; Paragraph HParagraph = header.AddParagraph(); //HParagraph.Format.HorizontalAlignment=HorizontalAlignment.Right; DocPicture footerimage = HParagraph.AppendPicture(System.Drawing.Image.FromFile(@"D:\Intrepidians\Diet Project\Diet_20160422_1\Diet_20160422_1\Diet\GNHClientUI\Images\header-1.png")); footerimage.Height = 100; footerimage.Width = 100; TextRange HText = HParagraph.AppendText("Right Nutrition for Health"); HText.CharacterFormat.FontName = "Calibri"; HText.CharacterFormat.FontSize = 20; HText.CharacterFormat.Italic = true; HText.CharacterFormat.TextColor = Color.Green; footerimage.TextWrappingStyle = TextWrappingStyle.Inline; //Add Footer HeaderFooter footer = section.HeadersFooters.Footer; Paragraph FParagraph = footer.AddParagraph(); HText = FParagraph.AppendText("+91 7722 0070 68 | [email protected] |www.geetanutriheal.com"); //Set Footer Paragrah Format FParagraph.Format.HorizontalAlignment = HorizontalAlignment.Center; FParagraph.Format.Borders.Top.BorderType = Spire.Doc.Documents.BorderStyle.ThinThinSmallGap; FParagraph.Format.Borders.Top.Space = 0.15f; FParagraph.Format.Borders.Color = Color.DarkGray; //Append Picture for Footer Paragraph HText.CharacterFormat.FontName = "Calibri"; HText.CharacterFormat.FontSize = 12; HText.CharacterFormat.Italic = true; HText.CharacterFormat.TextColor = Color.DodgerBlue; //document.Replace("") ////Save doc file. document.SaveToFile(Server.MapPath("~/Download") + "\\" + "Sample.doc", FileFormat.Doc); //return strBody.ToString(); }
public void printpage(bool printed) { document.Sections.Clear(); section = document.AddSection(); SizeF sf = new SizeF(); for (int i = 0; i < mReportApp.mPagelist.Count; i++) { if (mReportApp.mPagelist[i].Name == mReportApp.pagesize) { sf = mReportApp.mPagelist[i].size; } } section.PageSetup.PageSize = sf; section.PageSetup.Margins.Top = mReportApp.Margins; section.PageSetup.Margins.Bottom = mReportApp.Margins / 2; section.PageSetup.Margins.Left = mReportApp.Margins; section.PageSetup.Margins.Right = mReportApp.Margins; if (mReportApp.Landscape == true) { section.PageSetup.Orientation = PageOrientation.Landscape; } else { section.PageSetup.Orientation = PageOrientation.Portrait; } HeaderFooter header = section.HeadersFooters.Header; HeaderFooter footer = section.HeadersFooters.Footer; Paragraph headerParagraph = header.AddParagraph(); if (mReportApp.headerposition == 0) { headerParagraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Left; } else if (mReportApp.headerposition == 1) { headerParagraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center; } else if (mReportApp.headerposition == 2) { headerParagraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Right; } headerParagraph.Format.Borders.Bottom.BorderType = Spire.Doc.Documents.BorderStyle.Single; headerParagraph.Format.Borders.Bottom.Space = 0.05F; mReportApp.ChangeReportValue(); for (int i = 0; i < mReportApp.mreportheader.Count; i++) { if (mReportApp.mreportheader[i].kind == 0) { string s = ""; s = s.PadLeft(Convert.ToInt16(mReportApp.mreportheader[i].mspace), Convert.ToChar(" ")); if (mReportApp.mreportheader[i].showcaption == false) { s = s + mReportApp.mreportheader[i].txtresult; } else { s = s + mReportApp.mreportheader[i].Name + ":" + mReportApp.mreportheader[i].txtresult; } TextRange text = headerParagraph.AppendText(s); text.CharacterFormat.FontName = mReportApp.mreportheader[i].font.Name; text.CharacterFormat.FontSize = mReportApp.mreportheader[i].font.Size; text.CharacterFormat.Italic = mReportApp.mreportheader[i].font.Italic; text.CharacterFormat.Bold = mReportApp.mreportheader[i].font.Bold; } if (mReportApp.mreportheader[i].kind == 2) { if (mReportApp.mreportheader[i].filename.Trim() == "") { } else { string s = ""; s = s.PadLeft(Convert.ToInt16(mReportApp.mreportheader[i].mspace), Convert.ToChar(" ")); TextRange text = headerParagraph.AppendText(s); text.CharacterFormat.FontName = mReportApp.mreportheader[i].font.Name; text.CharacterFormat.FontSize = mReportApp.mreportheader[i].font.Size; text.CharacterFormat.Italic = mReportApp.mreportheader[i].font.Italic; text.CharacterFormat.Bold = mReportApp.mreportheader[i].font.Bold; DocPicture headerPicture = headerParagraph.AppendPicture(Image.FromFile(System.Windows.Forms.Application.StartupPath + "\\AppleLabJ\\bmp\\" + mReportApp.mreportheader[i].filename)); headerPicture.HorizontalAlignment = ShapeHorizontalAlignment.Left; } } if (mReportApp.mreportheader[i].kind == 1) { string s = ""; s = s.PadLeft(Convert.ToInt16(mReportApp.mreportheader[i].mspace), Convert.ToChar(" ")); s = s + mReportApp.mreportheader[i].txtresult; TextRange text = headerParagraph.AppendText(s); text.CharacterFormat.FontName = mReportApp.mreportheader[i].font.Name; text.CharacterFormat.FontSize = mReportApp.mreportheader[i].font.Size; text.CharacterFormat.Italic = mReportApp.mreportheader[i].font.Italic; text.CharacterFormat.Bold = mReportApp.mreportheader[i].font.Bold; } } for (int i = 0; i < mReportApp.mreportbody.Count; i++) { Paragraph paragraph = section.AddParagraph(); if (mReportApp.mreportbody[i].align == 0) { paragraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Left; } else if (mReportApp.mreportbody[i].align == 1) { paragraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center; } else if (mReportApp.mreportbody[i].align == 2) { paragraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Right; } for (int j = 0; j < mReportApp.mreportbody[i].vspace; j++) { paragraph.AppendBreak(BreakType.LineBreak); } if (mReportApp.mreportbody[i].kind == 0) { string s = ""; s = s.PadLeft(Convert.ToInt16(mReportApp.mreportbody[i].mspace), Convert.ToChar(" ")); if (mReportApp.mreportbody[i].showcaption == false) { s = s + mReportApp.mreportbody[i].txtresult; } else { s = s + mReportApp.mreportbody[i].Name + ":" + mReportApp.mreportbody[i].txtresult; } TextRange text = paragraph.AppendText(s); text.CharacterFormat.FontName = mReportApp.mreportbody[i].font.Name; text.CharacterFormat.FontSize = mReportApp.mreportbody[i].font.Size; text.CharacterFormat.Italic = mReportApp.mreportbody[i].font.Italic; text.CharacterFormat.Bold = mReportApp.mreportbody[i].font.Bold; } if (mReportApp.mreportbody[i].kind == 3) { string s = ""; s = s.PadLeft(Convert.ToInt16(mReportApp.mreportbody[i].mspace), Convert.ToChar(" ")); if (mReportApp.mreportbody[i].showcaption == false) { } else { s = s + mReportApp.mreportbody[i].Name + ":"; } TextRange text = paragraph.AppendText(s); text.CharacterFormat.FontName = mReportApp.mreportbody[i].font.Name; text.CharacterFormat.FontSize = mReportApp.mreportbody[i].font.Size; text.CharacterFormat.Italic = mReportApp.mreportbody[i].font.Italic; text.CharacterFormat.Bold = mReportApp.mreportbody[i].font.Bold; if (mReportApp.mreportbody[i].Name == "曲线图1") { InsertImage(section, 1); } if (mReportApp.mreportbody[i].Name == "曲线图2") { InsertImage(section, 2); } } if (mReportApp.mreportbody[i].kind == 4) { string s = ""; s = s.PadLeft(Convert.ToInt16(mReportApp.mreportbody[i].mspace), Convert.ToChar(" ")); if (mReportApp.mreportbody[i].showcaption == false) { } else { s = s + mReportApp.mreportbody[i].Name + ":"; } TextRange text = paragraph.AppendText(s); text.CharacterFormat.FontName = mReportApp.mreportbody[i].font.Name; text.CharacterFormat.FontSize = mReportApp.mreportbody[i].font.Size; text.CharacterFormat.Italic = mReportApp.mreportbody[i].font.Italic; text.CharacterFormat.Bold = mReportApp.mreportbody[i].font.Bold; if (mReportApp.mreportbody[i].Name == "结果表格1") { addTable(section, 1); } if (mReportApp.mreportbody[i].Name == "结果表格2") { addTable(section, 2); } } } Paragraph footerParagraph = footer.AddParagraph(); footerParagraph.Format.Borders.Bottom.BorderType = Spire.Doc.Documents.BorderStyle.Single; Paragraph FParagraph = footer.AddParagraph(); for (int i = 0; i < mReportApp.mreportfooter.Count; i++) { if (mReportApp.mreportfooter[i].kind == 0) { string s = ""; s = s.PadLeft(Convert.ToInt16(mReportApp.mreportfooter[i].mspace), Convert.ToChar(" ")); if (mReportApp.mreportfooter[i].showcaption == false) { s = s + mReportApp.mreportfooter[i].txtresult; } else { s = s + mReportApp.mreportfooter[i].Name + ":" + mReportApp.mreportfooter[i].txtresult; } TextRange text = FParagraph.AppendText(s); text.CharacterFormat.FontName = mReportApp.mreportfooter[i].font.Name; text.CharacterFormat.FontSize = mReportApp.mreportfooter[i].font.Size; text.CharacterFormat.Italic = mReportApp.mreportfooter[i].font.Italic; text.CharacterFormat.Bold = mReportApp.mreportfooter[i].font.Bold; } if (mReportApp.mreportfooter[i].kind == 2) { if (mReportApp.mreportfooter[i].filename.Trim() == "") { } else { string s = ""; s = s.PadLeft(Convert.ToInt16(mReportApp.mreportfooter[i].mspace), Convert.ToChar(" ")); TextRange text = footerParagraph.AppendText(s); text.CharacterFormat.FontName = mReportApp.mreportfooter[i].font.Name; text.CharacterFormat.FontSize = mReportApp.mreportfooter[i].font.Size; text.CharacterFormat.Italic = mReportApp.mreportfooter[i].font.Italic; text.CharacterFormat.Bold = mReportApp.mreportfooter[i].font.Bold; DocPicture footerPicture = FParagraph.AppendPicture(Image.FromFile(System.Windows.Forms.Application.StartupPath + "\\AppleLabJ\\bmp\\" + mReportApp.mreportfooter[i].filename)); footerPicture.HorizontalAlignment = ShapeHorizontalAlignment.Left; } } if (mReportApp.mreportfooter[i].kind == 1) { string s = ""; s = s.PadLeft(Convert.ToInt16(mReportApp.mreportfooter[i].mspace), Convert.ToChar(" ")); s = s + mReportApp.mreportfooter[i].txtresult; TextRange text = FParagraph.AppendText(s); text.CharacterFormat.FontName = mReportApp.mreportfooter[i].font.Name; text.CharacterFormat.FontSize = mReportApp.mreportfooter[i].font.Size; text.CharacterFormat.Italic = mReportApp.mreportfooter[i].font.Italic; text.CharacterFormat.Bold = mReportApp.mreportfooter[i].font.Bold; } } FParagraph.AppendText(" "); FParagraph.AppendField("page number", FieldType.FieldPage); FParagraph.AppendText(" of "); FParagraph.AppendField("number of pages", FieldType.FieldNumPages); if (mReportApp.footerposition == 0) { FParagraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Left; } else if (mReportApp.footerposition == 1) { FParagraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center; } else if (mReportApp.footerposition == 2) { FParagraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Right; } //Set Footer Paragrah Format FParagraph.Format.Borders.Top.BorderType = Spire.Doc.Documents.BorderStyle.Hairline; FParagraph.Format.Borders.Top.Space = 0.01f; FParagraph.Format.Borders.Color = Color.Black; dialog.AllowCurrentPage = true; dialog.AllowSomePages = true; dialog.UseEXDialog = true; dialog.PrinterSettings.DefaultPageSettings.Landscape = mReportApp.Landscape; document.PrintDialog = dialog; if (printed == false) { if (UserControl报告常规1 == null) { PrintPreviewControl m1 = new PrintPreviewControl(); m1.Document = document.PrintDocument; m1.InvalidatePreview(); } else { UserControl报告常规1.printPreviewControl1.Document = document.PrintDocument; UserControl报告常规1.printPreviewControl1.InvalidatePreview(); } } else { document.PrintDialog = dialog; document.PrintDocument.Print(); } }
public Paragraph CreateFooterParagraph(HeaderFooter footer) { return(footer.AddParagraph()); }
// create the headers and footers void CreateHeadersAndFooters(Document doc, TestResult testResult) { // ok so heres the main title of the header, should be the battery name Section section = doc.AddSection(); HeaderFooter headers = section.Headers.Primary; Paragraph para = headers.AddParagraph(testResult.batteryName); para.Style = "Heading2"; para.Format.Font.Color = Colors.Black; para.Format.Alignment = ParagraphAlignment.Center; // now to add the table so that its got 3 columns, this is just the column spacings Table table = headers.AddTable(); table.Format.Alignment = ParagraphAlignment.Center; table.Borders.Visible = false; Column col = table.AddColumn("5cm"); col.Format.Alignment = ParagraphAlignment.Left; col = table.AddColumn("6cm"); col.Format.Alignment = ParagraphAlignment.Center; col = table.AddColumn("5cm"); col.Format.Alignment = ParagraphAlignment.Right; // now we have to add rows to these columns, but only going to populate the left and right, for the first row Row row = table.AddRow(); Paragraph rowPara = row.Cells[0].AddParagraph("Battery Dataset Detail Report"); rowPara.Format.Font.Color = Colors.DarkBlue; rowPara.Format.Font.Size = 11; rowPara.Format.Font.Bold = true; rowPara.Format.Font.Italic = true; rowPara = row.Cells[2].AddParagraph("Install Date : " + GetDateString(testResult.installDate)); rowPara.Format.Font.Color = Colors.Black; rowPara.Format.Font.Size = 11; rowPara.Format.Font.Bold = true; // now for the second row, using all three column cells, batt Tag, block type, Location row = table.AddRow(); rowPara = row.Cells[0].AddParagraph(testResult.fileName); rowPara.Format.Font.Size = 11; rowPara.Format.Font.Color = Colors.Black; rowPara.Format.Font.Bold = true; rowPara = row.Cells[1].AddParagraph(testResult.modelNumber); rowPara.Format.Font.Size = 11; rowPara.Format.Font.Color = Colors.Black; rowPara.Format.Font.Bold = true; rowPara = row.Cells[2].AddParagraph(testResult.location); rowPara.Format.Font.Size = 11; rowPara.Format.Font.Color = Colors.Black; rowPara.Format.Font.Bold = true; // now add a blank colored bar across page, cant mind what its called so para = headers.AddParagraph(); para.Format.Alignment = ParagraphAlignment.Center; Border border = para.Format.Borders.Bottom; border.Width = 2; border.Color = Colors.DarkRed; table = headers.AddTable(); headers.Format.Alignment = ParagraphAlignment.Center; table.Borders.Visible = false; col = table.AddColumn("8cm"); col.Format.Alignment = ParagraphAlignment.Left; col = table.AddColumn("8cm"); col.Format.Alignment = ParagraphAlignment.Center; row = table.AddRow(); rowPara = row.Cells[0].AddParagraph("Readings Taken : " + testResult.dateFileCreated); rowPara = row.Cells[1].AddParagraph("Overall Float Voltage : " + testResult.overallVoltage + " V"); // stick another line below everything in the header // now add a blank colored bar across page, cant mind what its called so para = headers.AddParagraph(); para.Format.Alignment = ParagraphAlignment.Center; border = para.Format.Borders.Top; border.Width = 2; border.Color = Colors.DarkRed; }
public void ExportDocument(DataGridView dataGridView) { // Create a MigraDoc document Document document = new Document(); //string ddl = MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToString(document); MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(document, "MigraDoc.mdddl"); PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always); renderer.Document = document; Section section = document.AddSection(); section.PageSetup.OddAndEvenPagesHeaderFooter = true; section.PageSetup.StartingNumber = 1; HeaderFooter header = section.Headers.Primary; header.AddParagraph("\tCheck"); header = section.Headers.EvenPage; header.AddParagraph("Even Page Header"); // Create a paragraph with centered page number. See definition of style "Footer". Paragraph paragraph = new Paragraph(); paragraph.AddTab(); paragraph.AddPageField(); // Add paragraph to footer for odd pages. section.Footers.Primary.Add(paragraph); // Add clone of paragraph to footer for odd pages. Cloning is necessary because an object must // not belong to more than one other object. If you forget cloning an exception is thrown. section.Footers.EvenPage.Add(paragraph.Clone()); document.LastSection.AddParagraph("Simple Tables", "Heading2"); Table table = new Table(); table.Borders.Width = 0.75; for (int i = 0; i < dataGridView.ColumnCount; i++) { if (dataGridView.Columns[i].Visible && dataGridView.Columns[i].Name != "btnDel" && dataGridView.Columns[i].Name != "DiscountInfo") { table.AddColumn(60); } } Column column = table.Columns[0]; column.Format.Alignment = ParagraphAlignment.Center; Row row = table.AddRow(); row.Shading.Color = Colors.PaleGoldenrod; Cell cell; int j = 0; for (int i = 0; i < dataGridView.ColumnCount; i++) { if (dataGridView.Columns[i].Visible && dataGridView.Columns[i].Name != "btnDel" && dataGridView.Columns[i].Name != "DiscountInfo") { cell = row.Cells[j]; cell.AddParagraph(dataGridView.Columns[i].HeaderText); j++; } } for (int i = 0; i < dataGridView.RowCount; i++) { int m = 0; row = table.AddRow(); for (int k = 0; m < j; k++) { if (dataGridView.Columns[k].Visible && dataGridView.Columns[k].Name != "btnDel" && dataGridView.Columns[k].Name != "DiscountInfo") { if (dataGridView.Rows[i].Cells[k].Value == null) { row.Cells[m].AddParagraph(" "); m++; continue; } row.Cells[m].AddParagraph(dataGridView.Rows[i].Cells[k].Value.ToString()); m++; } } } table.SetEdge(0, 0, j, dataGridView.RowCount + 1, Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.Single, 1.5, Colors.Black); document.LastSection.Add(table); renderer.RenderDocument(); string filename = "Report.pdf"; renderer.PdfDocument.Save(filename); Process.Start(filename); }
private void button1_Click(object sender, EventArgs e) { //Create a new word document and add new section Document doc = new Document(); Section sec = doc.AddSection(); //Get header HeaderFooter header = doc.Sections[0].HeadersFooters.Header; //Add new paragraph on header and set HorizontalAlignment of the paragraph as left Paragraph paragraph = header.AddParagraph(); paragraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Left; //Load an image for the paragraph DocPicture headerimage = paragraph.AppendPicture(Image.FromFile(@"..\..\..\..\..\..\Data\Word.png")); //Add a table of 4 rows and 2 columns Table table = header.AddTable(); table.ResetCells(4, 2); //Set the position of the table to the right of the image table.TableFormat.WrapTextAround = true; table.TableFormat.Positioning.HorizPositionAbs = HorizontalPosition.Outside; table.TableFormat.Positioning.VertRelationTo = VerticalRelation.Margin; table.TableFormat.Positioning.VertPosition = 43; //Add contents for the table String[][] data = { new string[] { "Spire.Doc.left", "Spire XLS.right" }, new string[] { "Spire.Presentatio.left", "Spire.PDF.right" }, new string[] { "Spire.DataExport.left", "Spire.PDFViewe.right" }, new string [] { "Spire.DocViewer.left", "Spire.BarCode.right" } }; for (int r = 0; r < 4; r++) { TableRow dataRow = table.Rows[r]; for (int c = 0; c < 2; c++) { if (c == 0) { Paragraph par = dataRow.Cells[c].AddParagraph(); par.AppendText(data[r][c]); par.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Left; dataRow.Cells[c].Width = 180; } else { Paragraph par = dataRow.Cells[c].AddParagraph(); par.AppendText(data[r][c]); par.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Right; dataRow.Cells[c].Width = 180; } } } //Save and launch document string output = "SetOutsidePosition.docx"; doc.SaveToFile(output, FileFormat.Docx); Viewer(output); }
public void DocCreate() { string DocName = Tb_DocName.Text; string titleName = Tb_CoreTitle.Text; //创建部分/区域 Section section = ApiDoc.AddSection(); HeaderFooter headeraaa = section.HeadersFooters.Header; Paragraph paragraph = headeraaa.AddParagraph(); if (section.HeadersFooters.Header.Count == 1) { //页眉 TextRange HText = paragraph.AppendText("青岛雨诺网络信息股份有限公司"); //Set Header Text Format HText.CharacterFormat.FontName = "Ya Hei"; HText.CharacterFormat.FontSize = 10; HText.CharacterFormat.TextColor = Color.RoyalBlue; //Set Header Paragraph Format paragraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center; paragraph.Format.Borders.Bottom.BorderType = Spire.Doc.Documents.BorderStyle.DashSmallGap; paragraph.Format.Borders.Bottom.Space = 0.05f; paragraph.Format.Borders.Bottom.Color = Color.DarkGray; //页脚 HeaderFooter footer = section.HeadersFooters.Footer; paragraph = footer.AddParagraph(); TextRange FText = paragraph.AppendText("青岛雨诺网络信息股份有限公司"); FText.CharacterFormat.FontName = "Ya Hei"; FText.CharacterFormat.FontSize = 10; FText.CharacterFormat.TextColor = Color.RoyalBlue; paragraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center; paragraph.Format.Borders.Top.BorderType = Spire.Doc.Documents.BorderStyle.DashSmallGap; paragraph.Format.Borders.Top.Space = 0.15f; paragraph.Format.Borders.Color = Color.DarkGray; } paragraph = section.AddParagraph(); #region 文档主标题 //追加文本 paragraph.AppendText($"《{titleName}》"); paragraph.ApplyStyle(MainTietleStyle); //对齐方式 paragraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center; #endregion #region 1.版本号 //标题 Paragraph pVerson = section.AddParagraph(); pVerson.AppendText("版本号"); pVerson.ApplyStyle(BuiltinStyle.Heading1); pVerson = section.AddParagraph(); pVerson.AppendText(Environment.NewLine); pVerson.ApplyStyle(BuiltinStyle.Normal); //表格 string[] header = { "版本号", "更新时间", "更新人", "更新内容" }; string[][] data = { new string[] { "V1.0", DateTime.Now.ToString("yyyy年MM月dd日"), Tb_Author.Text, Tb_zygn.Text } }; Table table = section.AddTable(true); table.ResetCells(data.Length + 1, header.Length); TableRow row = table.Rows[0]; row.IsHeader = true; row.Height = 20; //unit: point, 1point = 0.3528 mm row.HeightType = TableRowHeightType.Exactly; row.RowFormat.BackColor = Color.SkyBlue; for (int i = 0; i < header.Length; i++) { row.Cells[i].CellFormat.VerticalAlignment = VerticalAlignment.Middle; Paragraph p = row.Cells[i].AddParagraph(); p.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center; TextRange txtRange = p.AppendText(header[i]); txtRange.CharacterFormat.Bold = true; } for (int r = 0; r < data.Length; r++) { TableRow dataRow = table.Rows[r + 1]; //dataRow.Height = 20; dataRow.HeightType = TableRowHeightType.Auto; dataRow.RowFormat.BackColor = Color.Empty; for (int c = 0; c < data[r].Length; c++) { dataRow.Cells[c].CellFormat.VerticalAlignment = VerticalAlignment.Middle; paragraph = dataRow.Cells[c].AddParagraph(); paragraph.AppendText(data[r][c]); paragraph.ApplyStyle(CellStyleName); paragraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center; } } #endregion #region 2.介绍 //标题 paragraph = section.AddParagraph(); paragraph.AppendText("介绍"); paragraph.ApplyStyle(BuiltinStyle.Heading1); //详细内容 NewLine(section, paragraph); paragraph = section.AddParagraph(); paragraph.AppendText(Tb_Desc.Text); paragraph.ApplyStyle(BuiltinStyle.Normal); //首行缩进 paragraph.Format.FirstLineIndent = 30; //需要阅读该文档的角色: paragraph = section.AddParagraph(); NewLine(section, paragraph); paragraph.AppendText($"需要阅读该文档的角色:{Tb_Reader.Text??"开发者、项目经理"}"); pVerson.ApplyStyle(BuiltinStyle.Normal); #endregion #region 3.接口约定 //标题 paragraph = section.AddParagraph(); paragraph.AppendText("接口约定"); paragraph.ApplyStyle(BuiltinStyle.Heading1); NewLine(section, paragraph); //详细内容 paragraph = section.AddParagraph(); paragraph.AppendText(Tb_RulerDesc.Text); paragraph.ApplyStyle(FontStyleName); //首行缩进 paragraph.Format.FirstLineIndent = 30; #endregion paragraph = section.AddParagraph(); paragraph.AppendText("Api说明"); paragraph.ApplyStyle(BuiltinStyle.Heading1); NewLine(section, paragraph); NewLine(section, paragraph); NewLine(section, paragraph); //保存Doc ApiDoc.SaveToFile($"{DocName}.docx", FileFormat.Doc); //文件预览 //UtilityHelper.WordDocView($"{DocName}.docx"); }