private void InsertFirstPageHeaderFooter(WordDocument doc, IWSection section) { Assembly execAssm = typeof(HeadersAndFootersDemo).GetTypeInfo().Assembly; Stream inputStream = execAssm.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.DocIO.DocIO.Assets.Northwind_logo.png"); // Add a new paragraph for header to the document. IWParagraph headerPar = new WParagraph(doc); // Add a new table to the header. IWTable table = section.HeadersFooters.FirstPageHeader.AddTable(); RowFormat format = new RowFormat(); // Setting cleared table border style. format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Cleared; // Inserting table with a row and two columns. table.ResetCells(1, 2, format, 265); // Inserting logo image to the table first cell. headerPar = table[0, 0].AddParagraph() as WParagraph; headerPar.AppendPicture(inputStream); //Set Image size (headerPar.Items[0] as WPicture).Width = 232.5f; (headerPar.Items[0] as WPicture).Height = 54.75f; // Inserting text to the table second cell. headerPar = table[0, 1].AddParagraph() as WParagraph; IWTextRange txt = headerPar.AppendText("Company Headquarters,\n2501 Aerial Center Parkway,\nSuite 110, Morrisville, NC 27560,\nTEL 1-888-936-8638."); txt.CharacterFormat.FontSize = 12; txt.CharacterFormat.CharacterSpacing = 1.7f; headerPar.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Right; // Add a new paragraph to the header with address text. headerPar = new WParagraph(doc); headerPar.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; txt = headerPar.AppendText("\nFirst Page Header"); txt.CharacterFormat.CharacterSpacing = 1.7f; section.HeadersFooters.FirstPageHeader.Paragraphs.Add(headerPar); // Add a footer paragraph text to the document. WParagraph footerPar = new WParagraph(doc); footerPar.ParagraphFormat.Tabs.AddTab(523f, TabJustification.Right, TabLeader.NoLeader); // Add text. footerPar.AppendText("Copyright Northwind Inc. 2001 - 2015"); // Add page and Number of pages field to the document. footerPar.AppendText("\tFirst Page "); footerPar.AppendField("Page", FieldType.FieldPage); section.HeadersFooters.FirstPageFooter.Paragraphs.Add(footerPar); #region Page Number Settings section.PageSetup.RestartPageNumbering = true; section.PageSetup.PageStartingNumber = Convert.ToInt32(this.numericUpDown1.Value); section.PageSetup.PageNumberStyle = (PageNumberStyle)Enum.Parse(typeof(PageNumberStyle), this.comboBox1.SelectedItem.ToString(), true); #endregion }
private static void AddHeading(WSection section, string styleName, string headingText, string paragraghText) { WParagraph newPara = section.AddParagraph() as WParagraph; WTextRange text = newPara.AppendText(headingText) as WTextRange; newPara.ApplyStyle(styleName); newPara = section.AddParagraph() as WParagraph; newPara.AppendText(paragraghText); section.AddParagraph(); }
private void InsertFirstPageHeaderFooter(WordDocument doc, IWSection section) { // Add a new paragraph for header to the document. IWParagraph headerPar = new WParagraph(doc); // Add a new table to the header. IWTable table = section.HeadersFooters.FirstPageHeader.AddTable(); RowFormat format = new RowFormat(); // Setting cleared table border style. format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Cleared; // Inserting table with a row and two columns. table.ResetCells(1, 2, format, 265); // Inserting logo image to the table first cell. headerPar = table[0, 0].AddParagraph() as WParagraph; string basePath = _hostingEnvironment.WebRootPath; FileStream imageStream = new FileStream(basePath + @"/images/DocIO/Northwind_logo.png", FileMode.Open, FileAccess.Read); headerPar.AppendPicture(imageStream); //Set Image size (headerPar.Items[0] as WPicture).Width = 232.5f; (headerPar.Items[0] as WPicture).Height = 54.75f; // Inserting text to the table second cell. headerPar = table[0, 1].AddParagraph() as WParagraph; IWTextRange txt = headerPar.AppendText("Company Headquarters,\n2501 Aerial Center Parkway,\nSuite 110, Morrisville, NC 27560,\nTEL 1-888-936-8638."); txt.CharacterFormat.FontSize = 12; txt.CharacterFormat.CharacterSpacing = 1.7f; headerPar.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Right; // Add a new paragraph to the header with address text. headerPar = new WParagraph(doc); headerPar.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; txt = headerPar.AppendText("\nFirst Page Header"); txt.CharacterFormat.CharacterSpacing = 1.7f; section.HeadersFooters.FirstPageHeader.Paragraphs.Add(headerPar); // Add a footer paragraph text to the document. WParagraph footerPar = new WParagraph(doc); footerPar.ParagraphFormat.Tabs.AddTab(523f, TabJustification.Right, TabLeader.NoLeader); // Add text. footerPar.AppendText("Copyright Northwind Inc. 2001 - 2017"); // Add page and Number of pages field to the document. footerPar.AppendText("\tFirst Page "); footerPar.AppendField("Page", FieldType.FieldPage); section.HeadersFooters.FirstPageFooter.Paragraphs.Add(footerPar); #region Page Number Settings section.PageSetup.RestartPageNumbering = true; section.PageSetup.PageStartingNumber = 1; section.PageSetup.PageNumberStyle = PageNumberStyle.Arabic; #endregion Page Number Settings }
private void InsertPageHeaderFooter(WordDocument doc, IWSection section1) { // Add a new paragraph for header to the document. IWParagraph headerPar = new WParagraph(doc); // Add a new table to the header IWTable table = section1.HeadersFooters.Header.AddTable(); RowFormat format = new RowFormat(); // Setting Single table border style. format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; // Inserting table with a row and two columns. table.ResetCells(1, 2, format, 265); // Inserting logo image to the table first cell. headerPar = table[0, 0].AddParagraph() as WParagraph; #if NETCORE headerPar.AppendPicture(Image.FromFile(@"..\..\..\..\..\..\..\..\Common\images\DocIO\Northwind_logo.png")); #else headerPar.AppendPicture(Image.FromFile(@"..\..\..\..\..\..\..\Common\images\DocIO\Northwind_logo.png")); #endif //Set Image size. (headerPar.Items[0] as WPicture).Width = 232.5f; (headerPar.Items[0] as WPicture).Height = 54.75f; // Inserting text to the table second cell. headerPar = table[0, 1].AddParagraph() as WParagraph; IWTextRange txt = headerPar.AppendText("Company Headquarters,\n2501 Aerial Center Parkway,\nSuite 110, Morrisville, NC 27560,\nTEL 1-888-936-8638."); txt.CharacterFormat.FontSize = 12; txt.CharacterFormat.CharacterSpacing = 1.7f; headerPar.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Right; // Add a footer paragraph text to the document. WParagraph footerPar = new WParagraph(doc); footerPar.ParagraphFormat.Tabs.AddTab(523f, TabJustification.Right, TabLeader.NoLeader); // Add text. footerPar.AppendText("Copyright Northwind Inc. 2001 - 2017"); // Add page and Number of pages field to the document. footerPar.AppendText("\tPage "); IWField ff = footerPar.AppendField("Page", Syncfusion.DocIO.FieldType.FieldPage); section1.HeadersFooters.Footer.Paragraphs.Add(footerPar); #region Page Number Settings section1.PageSetup.RestartPageNumbering = true; section1.PageSetup.PageStartingNumber = Convert.ToInt32(this.numericUpDown1.Value); section1.PageSetup.PageNumberStyle = (PageNumberStyle)Enum.Parse(typeof(PageNumberStyle), this.comboBox1.SelectedItem.ToString(), true); #endregion }
private void InsertPageHeaderFooter(WordDocument doc, IWSection section1) { // Add a new paragraph for header to the document. IWParagraph headerPar = new WParagraph(doc); // Add a new table to the header IWTable table = section1.HeadersFooters.Header.AddTable(); RowFormat format = new RowFormat(); // Setting Single table border style. format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; // Inserting table with a row and two columns. table.ResetCells(1, 2, format, 265); // Inserting logo image to the table first cell. headerPar = table[0, 0].AddParagraph() as WParagraph; string s = ResolveApplicationDataPath("Northwind_logo.png", "Content\\DocIO"); headerPar.AppendPicture(System.Drawing.Image.FromFile(s)); //Set Image size. (headerPar.Items[0] as WPicture).Width = 232.5f; (headerPar.Items[0] as WPicture).Height = 54.75f; // Inserting text to the table second cell. headerPar = table[0, 1].AddParagraph() as WParagraph; IWTextRange txt = headerPar.AppendText("Company Headquarters,\n2501 Aerial Center Parkway,\nSuite 110, Morrisville, NC 27560,\nTEL 1-888-936-8638."); txt.CharacterFormat.FontSize = 12; txt.CharacterFormat.CharacterSpacing = 1.7f; headerPar.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Right; // Add a footer paragraph text to the document. WParagraph footerPar = new WParagraph(doc); footerPar.ParagraphFormat.Tabs.AddTab(523f, TabJustification.Right, TabLeader.NoLeader); // Add text. footerPar.AppendText("Copyright Northwind Inc. 2001 - 2017"); // Add page and Number of pages field to the document. footerPar.AppendText("\tPage "); IWField ff = footerPar.AppendField("Page", FieldType.FieldPage); section1.HeadersFooters.Footer.Paragraphs.Add(footerPar); #region Page Number Settings section1.PageSetup.RestartPageNumbering = true; section1.PageSetup.PageStartingNumber = 1; section1.PageSetup.PageNumberStyle = PageNumberStyle.Arabic; #endregion Page Number Settings }
/// <summary> /// Creates word document with built - in styles /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, System.EventArgs e) { try { WordDocument document = new WordDocument(); WSection section = document.AddSection() as WSection; WParagraph para = section.AddParagraph() as WParagraph; section.AddColumn(100, 100); section.AddColumn(100, 100); section.MakeColumnsEqual(); #region Built-in styles # region List Style //List para.AppendText("This para is written with style List").CharacterFormat.UnderlineStyle = UnderlineStyle.Double; para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.List); para.AppendText("Google Chrome\n"); para.AppendText("Mozilla Firefox\n"); para.AppendText("Internet Explorer"); //List5 style para = section.AddParagraph() as WParagraph; para.AppendText("\nThis para is written with style List5").CharacterFormat.UnderlineStyle = UnderlineStyle.Double; para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.List5); para.AppendText("Google Chrome\n"); para.AppendText("Mozilla Firefox\n"); para.AppendText("Internet Explorer"); # endregion # region ListNumber Style
/// <summary> /// Inserts Header and Footer to first page. /// </summary> private void InsertFirstPageHeaderFooter(WordDocument doc, IWSection section) { //Adds a new table to the header. IWTable table = section.HeadersFooters.FirstPageHeader.AddTable(); RowFormat format = new(); //Sets cleared table border style. format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Cleared; //Inserts table with a row and two columns. table.ResetCells(1, 2, format, 265); //Inserts logo image to the table first cell. IWParagraph headerPara = table[0, 0].AddParagraph() as WParagraph; Stream imageStream = assembly.GetManifestResourceStream("syncfusion.dociodemos.winui.Assets.DocIO.Northwindlogo.png"); headerPara.AppendPicture(imageStream); //Sets Image size (headerPara.Items[0] as WPicture).Width = 232.5f; (headerPara.Items[0] as WPicture).Height = 54.75f; //Inserts text to the table second cell. headerPara = table[0, 1].AddParagraph() as WParagraph; IWTextRange txt = headerPara.AppendText("Company Headquarters,\n2501 Aerial Center Parkway,\nSuite 110, Morrisville, NC 27560,\nTEL 1-888-936-8638."); txt.CharacterFormat.FontSize = 12; txt.CharacterFormat.CharacterSpacing = 1.7f; headerPara.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Right; //Adds a new paragraph to the header with address text. headerPara = new WParagraph(doc); headerPara.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; txt = headerPara.AppendText("\nFirst Page Header"); txt.CharacterFormat.CharacterSpacing = 1.7f; section.HeadersFooters.FirstPageHeader.Paragraphs.Add(headerPara); //Adds a footer paragraph text to the document. WParagraph footerPara = new(doc); footerPara.ParagraphFormat.Tabs.AddTab(523f, TabJustification.Right, TabLeader.NoLeader); //Adds text. footerPara.AppendText("Copyright Northwind Inc. 2001 - 2021"); //Adds page and Number of pages field to the document. footerPara.AppendText("\tPage "); footerPara.AppendField("Page", FieldType.FieldPage); footerPara.AppendText(" of "); footerPara.AppendField("NumPages", FieldType.FieldNumPages); section.HeadersFooters.FirstPageFooter.Paragraphs.Add(footerPara); #region Page Number Settings section.PageSetup.RestartPageNumbering = true; section.PageSetup.PageStartingNumber = 1; section.PageSetup.PageNumberStyle = PageNumberStyle.Arabic; #endregion Page Number Settings }
static void Main(string[] args) { using (WordDocument document = new WordDocument()) { document.EnsureMinimal(); document.LastSection.PageSetup.Margins.All = 72; WParagraph para = document.LastParagraph; para.AppendText("Essential DocIO - Table of Contents"); para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center; para.ApplyStyle(BuiltinStyle.Heading4); para = document.LastSection.AddParagraph() as WParagraph; //Creates the new custom styles. WParagraphStyle pStyle1 = (WParagraphStyle)document.AddParagraphStyle("MyStyle1"); pStyle1.CharacterFormat.FontSize = 18f; WParagraphStyle pStyle2 = (WParagraphStyle)document.AddParagraphStyle("MyStyle2"); pStyle2.CharacterFormat.FontSize = 16f; WParagraphStyle pStyle3 = (WParagraphStyle)document.AddParagraphStyle("MyStyle3"); pStyle3.CharacterFormat.FontSize = 14f; para = document.LastSection.AddParagraph() as WParagraph; //Insert TOC field in the Word document. TableOfContent toc = para.AppendTOC(1, 3); //Sets the Heading Styles to false, to define custom levels for TOC. toc.UseHeadingStyles = false; //Sets the TOC level style which determines; based on which the TOC should be created. toc.SetTOCLevelStyle(1, "MyStyle1"); toc.SetTOCLevelStyle(2, "MyStyle2"); toc.SetTOCLevelStyle(3, "MyStyle3"); //Adds content to the Word document with custom styles. WSection section = document.LastSection; WParagraph newPara = section.AddParagraph() as WParagraph; newPara.AppendBreak(BreakType.PageBreak); AddHeading(section, "MyStyle1", "Document with custom styles", "This is the 1st custom style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can insert TOC field in a word document. It can refresh or update TOC field by using UpdateTableOfContents method. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC."); AddHeading(section, "MyStyle2", "Section 1", "This is the 2nd custom style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); AddHeading(section, "MyStyle3", "Paragraph 1", "This is the 3rd custom style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text."); AddHeading(section, "MyStyle3", "Paragraph 2", "This is the 3rd custom style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph."); AddHeading(section, "Normal", "Paragraph with normal", "This is the paragraph with normal style. This demonstrates the paragraph with outline level 4 and normal style. This can be attained by formatting outline level of the paragraph."); //Adds a new section to the Word document. section = document.AddSection() as WSection; section.PageSetup.Margins.All = 72; section.BreakCode = SectionBreakCode.NewPage; AddHeading(section, "MyStyle2", "Section 2", "This is the 2nd custom style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); AddHeading(section, "MyStyle3", "Paragraph 1", "This is the 3rd custom style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text."); AddHeading(section, "MyStyle3", "Paragraph 2", "This is the 3rd custom style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph."); //Updates the table of contents. document.UpdateTableOfContents(); //Saves the file in the given path Stream docStream = File.Create(Path.GetFullPath(@"../../../TOC-custom-style.docx")); document.Save(docStream, FormatType.Docx); docStream.Dispose(); } }
static void Main(string[] args) { using (WordDocument document = new WordDocument()) { document.EnsureMinimal(); document.LastSection.PageSetup.Margins.All = 72; WParagraph para = document.LastParagraph; para.AppendText("Essential DocIO - Table of Contents"); para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center; para.ApplyStyle(BuiltinStyle.Heading4); para = document.LastSection.AddParagraph() as WParagraph; para = document.LastSection.AddParagraph() as WParagraph; //Insert TOC field in the Word document. TableOfContent toc = para.AppendTOC(1, 3); //Sets the heading levels 1 to 3, to include in TOC. toc.LowerHeadingLevel = 1; toc.UpperHeadingLevel = 3; //Adds content to the Word document with built-in heading styles. WSection section = document.LastSection; WParagraph newPara = section.AddParagraph() as WParagraph; newPara.AppendBreak(BreakType.PageBreak); AddHeading(section, BuiltinStyle.Heading1, "Document with built-in heading styles", "This is the built-in heading 1 style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can insert TOC field in a word document. It can refresh or update TOC field by using UpdateTableOfContents method. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC."); AddHeading(section, BuiltinStyle.Heading2, "Section 1", "This is the built-in heading 2 style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); AddHeading(section, BuiltinStyle.Heading3, "Paragraph 1", "This is the built-in heading 3 style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text."); AddHeading(section, BuiltinStyle.Heading3, "Paragraph 2", "This is the built-in heading 3 style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph."); //Adds a new section to the Word document. section = document.AddSection() as WSection; section.PageSetup.Margins.All = 72; section.BreakCode = SectionBreakCode.NewPage; AddHeading(section, BuiltinStyle.Heading2, "Section 2", "This is the built-in heading 2 style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); AddHeading(section, BuiltinStyle.Heading3, "Paragraph 1", "This is the built-in heading 3 style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text."); AddHeading(section, BuiltinStyle.Heading3, "Paragraph 2", "This is the built-in heading 3 style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph."); //Updates the table of contents. document.UpdateTableOfContents(); //Saves the file in the given path Stream docStream = File.Create(Path.GetFullPath(@"../../../TOC-creation.docx")); document.Save(docStream, FormatType.Docx); docStream.Dispose(); } }
private void Button_Click_1(object sender, RoutedEventArgs e) { // Create a new document. WordDocument document = new WordDocument(); // Adding a new section to the document. IWSection section = document.AddSection(); section.PageSetup.DifferentFirstPage = true; IWTextRange textRange; IWParagraph paragraph = section.AddParagraph(); // -------------------------------------------- // Table in page header // -------------------------------------------- IWParagraph hParagraph = new WParagraph(document); hParagraph.AppendText("Header text\r\n").CharacterFormat.FontSize = 14; section.HeadersFooters.FirstPageHeader.Paragraphs.Add(hParagraph); IWTable hTable = document.LastSection.HeadersFooters.FirstPageHeader.AddTable(); hTable.ResetCells(2, 2); hTable[0, 0].AddParagraph().AppendText("1"); hTable[0, 1].AddParagraph().AppendText("2"); hTable[1, 0].AddParagraph().AppendText("3"); hTable[1, 1].AddParagraph().AppendText("4"); // -------------------------------------------- // Tiny table // -------------------------------------------- paragraph = section.AddParagraph(); paragraph.AppendText("Tiny table\r\n").CharacterFormat.FontSize = 14; paragraph = section.AddParagraph(); WTextBody textBody = section.Body; IWTable table = textBody.AddTable(); table.ResetCells(2, 2); WTableRow row_0 = table.Rows[0]; row_0.Cells[0].AddParagraph().AppendText("A"); row_0.Cells[0].AddParagraph().AppendText("AA"); row_0.Cells[0].AddParagraph().AppendText("AAA"); WTableRow row_1 = table.Rows[1]; row_1.Cells[1].AddParagraph().AppendText("B"); row_1.Cells[1].AddParagraph().AppendText("BB\r\nBBB"); row_1.Cells[1].AddParagraph().AppendText("BBB"); textBody.AddParagraph().AppendText("Text after table...").CharacterFormat.FontSize = 14; // -------------------------------------------- // Table with different formatting // -------------------------------------------- section.AddParagraph(); paragraph = section.AddParagraph(); paragraph.AppendText("Table with different formatting\r\n").CharacterFormat.FontSize = 14; paragraph = section.AddParagraph(); textBody = section.Body; table = textBody.AddTable(); table.ResetCells(3, 3); /* ------- First Row -------- */ WTableRow row0 = table.Rows[0]; paragraph = (IWParagraph)row0.Cells[0].AddParagraph(); textRange = paragraph.AppendText("1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; textRange.CharacterFormat.FontName = "Arial"; textRange.CharacterFormat.Bold = true; textRange.CharacterFormat.FontSize = 14f; row0.Cells[0].CellFormat.Borders.LineWidth = 2f; row0.Cells[0].CellFormat.Borders.Color = Color.Magenta; paragraph = (IWParagraph)row0.Cells[1].AddParagraph(); textRange = paragraph.AppendText("2"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Right; textRange.CharacterFormat.Emboss = true; textRange.CharacterFormat.FontSize = 15f; row0.Cells[1].CellFormat.Borders.LineWidth = 1.3f; row0.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DoubleWave; paragraph = (IWParagraph)row0.Cells[2].AddParagraph(); textRange = paragraph.AppendText("3"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; textRange.CharacterFormat.Engrave = true; textRange.CharacterFormat.FontSize = 15f; row0.Cells[2].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Emboss3D; /* ------- Second Row -------- */ WTableRow row1 = table.Rows[1]; paragraph = (IWParagraph)row1.Cells[0].AddParagraph(); textRange = paragraph.AppendText("4"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; textRange.CharacterFormat.SmallCaps = true; textRange.CharacterFormat.FontName = "Comic Sans MS"; textRange.CharacterFormat.FontSize = 16; row1.Cells[0].CellFormat.Borders.LineWidth = 2f; row1.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DashDotStroker; paragraph = (IWParagraph)row1.Cells[1].AddParagraph(); textRange = paragraph.AppendText("5"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; textRange.CharacterFormat.FontName = "Times New Roman"; textRange.CharacterFormat.Shadow = true; textRange.CharacterFormat.TextBackgroundColor = Color.Orange; textRange.CharacterFormat.FontSize = 15f; row1.Cells[1].CellFormat.Borders.LineWidth = 2f; row1.Cells[1].CellFormat.Borders.Color = Color.Brown; paragraph = (IWParagraph)row1.Cells[2].AddParagraph(); textRange = paragraph.AppendText("6"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; textRange.CharacterFormat.Bold = true; textRange.CharacterFormat.FontSize = 14f; row1.Cells[2].CellFormat.BackColor = Color.FromArgb(51, 51, 101); row1.Cells[2].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; /* ------- Third Row -------- */ WTableRow row2 = table.Rows[2]; paragraph = (IWParagraph)row2.Cells[0].AddParagraph(); textRange = paragraph.AppendText("7"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Right; textRange.CharacterFormat.FontSize = 13f; row2.Cells[0].CellFormat.Borders.LineWidth = 1.5f; row2.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DashLargeGap; paragraph = (IWParagraph)row2.Cells[1].AddParagraph(); textRange = paragraph.AppendText("8"); textRange.CharacterFormat.TextColor = Color.Blue; textRange.CharacterFormat.FontSize = 16f; row2.Cells[1].CellFormat.Borders.LineWidth = 3f; row2.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Wave; paragraph = (IWParagraph)row2.Cells[2].AddParagraph(); textRange = paragraph.AppendText("9"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Right; row2.Cells[2].CellFormat.Borders.LineWidth = 2f; row2.Cells[2].CellFormat.Borders.Color = Color.Cyan; row2.Cells[2].CellFormat.Borders.Shadow = true; row2.Cells[2].CellFormat.Borders.Space = 20; // -------------------------------------------- // Table Cell Merging. // -------------------------------------------- section.AddParagraph(); paragraph = section.AddParagraph(); paragraph.AppendText("Table Cell Merging...").CharacterFormat.FontSize = 14; section.AddParagraph(); paragraph = section.AddParagraph(); textBody = section.Body; // Adding a new Table to the textbody. table = textBody.AddTable(); RowFormat format = new RowFormat(); format.Paddings.All = 5; format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Dot; format.Borders.LineWidth = 2; // Inserting rows to the table. table.ResetCells(6, 6, format, 80); // Table formatting with cell merging. table.Rows[0].Cells[0].CellFormat.HorizontalMerge = CellMerge.Start; table.Rows[0].Cells[1].CellFormat.HorizontalMerge = CellMerge.Continue; table.Rows[0].Cells[0].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; table.Rows[0].Cells[0].CellFormat.BackColor = Color.FromArgb(218, 230, 246); IWParagraph par = table.Rows[0].Cells[0].AddParagraph(); par.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; par.AppendText("Horizontal Merge").CharacterFormat.Bold = true; table.Rows[2].Cells[3].CellFormat.VerticalMerge = CellMerge.Start; table.Rows[3].Cells[3].CellFormat.VerticalMerge = CellMerge.Continue; table.Rows[2].Cells[3].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; par = table.Rows[2].Cells[3].AddParagraph(); table.Rows[2].Cells[3].CellFormat.BackColor = Color.FromArgb(252, 172, 85); par.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; par.AppendText("Vertical Merge").CharacterFormat.Bold = true; #region Table Cell Spacing. // -------------------------------------------- // Table Cell Spacing. // -------------------------------------------- section.AddParagraph(); paragraph = section.AddParagraph(); paragraph.AppendText("Table Cell spacing...").CharacterFormat.FontSize = 14; section.AddParagraph(); paragraph = section.AddParagraph(); textBody = section.Body; // Adding a new Table to the textbody. table = textBody.AddTable(); format = new RowFormat(); format.CellSpacing = 5; format.Paddings.All = 5; format.CellSpacing = 2.5f; format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DotDash; format.IsBreakAcrossPages = true; table.ResetCells(25, 5, format, 100); IWTextRange text; table.Rows[0].IsHeader = true; for (int i = 0; i < table.Rows[0].Cells.Count; i++) { paragraph = table[0, i].AddParagraph() as WParagraph; paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText(string.Format("Header {0}", i + 1)); text.CharacterFormat.Font = new Font("Bitstream Vera Serif", 10); text.CharacterFormat.Bold = true; text.CharacterFormat.TextColor = Color.FromArgb(0, 21, 84); table[0, i].CellFormat.BackColor = Color.FromArgb(203, 211, 226); } for (int i = 1; i < table.Rows.Count; i++) { for (int j = 0; j < 5; j++) { paragraph = table[i, j].AddParagraph() as WParagraph; paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText(string.Format("Cell {0} , {1}", i, j + 1)); text.CharacterFormat.TextColor = Color.FromArgb(242, 151, 50); text.CharacterFormat.Bold = true; if (i % 2 != 1) { table[i, j].CellFormat.BackColor = Color.FromArgb(231, 235, 245); } else { table[i, j].CellFormat.BackColor = Color.FromArgb(246, 249, 255); } } } #endregion Table Cell Spacing. #region Nested Table // -------------------------------------------- // Nested Table. // -------------------------------------------- section.AddParagraph(); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.PageBreakBefore = true; paragraph.AppendText("Nested Table...").CharacterFormat.FontSize = 14; section.AddParagraph(); paragraph = section.AddParagraph(); textBody = section.Body; // Adding a new Table to the textbody. table = textBody.AddTable(); format = new RowFormat(); format.Paddings.All = 5; format.CellSpacing = 2.5f; format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DotDash; table.ResetCells(5, 3, format, 100); for (int i = 0; i < table.Rows[0].Cells.Count; i++) { paragraph = table[0, i].AddParagraph() as WParagraph; paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText(string.Format("Header {0}", i + 1)); text.CharacterFormat.Font = new Font("Bitstream Vera Serif", 10); text.CharacterFormat.Bold = true; text.CharacterFormat.TextColor = Color.FromArgb(0, 21, 84); table[0, i].CellFormat.BackColor = Color.FromArgb(242, 151, 50); } table[0, 2].Width = 200; for (int i = 1; i < table.Rows.Count; i++) { for (int j = 0; j < 3; j++) { paragraph = table[i, j].AddParagraph() as WParagraph; paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; if ((i == 2) && (j == 2)) { text = paragraph.AppendText("Nested Table"); } else { text = paragraph.AppendText(string.Format("Cell {0} , {1}", i, j + 1)); } if ((j == 2)) { table[i, j].Width = 200; } text.CharacterFormat.TextColor = Color.FromArgb(242, 151, 50); text.CharacterFormat.Bold = true; } } // Adding a nested Table. IWTable nestTable = table[2, 2].AddTable(); format = new RowFormat(); format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DotDash; format.HorizontalAlignment = RowAlignment.Center; nestTable.ResetCells(3, 3, format, 50); for (int i = 0; i < nestTable.Rows.Count; i++) { for (int j = 0; j < 3; j++) { paragraph = nestTable[i, j].AddParagraph() as WParagraph; paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; nestTable[i, j].CellFormat.BackColor = Color.FromArgb(231, 235, 245); text = paragraph.AppendText(string.Format("Cell {0} , {1}", i, j + 1)); text.CharacterFormat.TextColor = Color.Black; text.CharacterFormat.Bold = true; } } #endregion Nested Table #region Table with Images //Add a new section to the document. section = document.AddSection(); //Add paragraph to the section. paragraph = section.AddParagraph(); //Writing text. textRange = paragraph.AppendText("Table with Images"); textRange.CharacterFormat.FontSize = 13f; textRange.CharacterFormat.TextColor = Color.DarkBlue; textRange.CharacterFormat.Bold = true; //Add paragraph to the section. section.AddParagraph(); paragraph = section.AddParagraph(); text = null; //Adding a new Table to the paragraph. table = section.Body.AddTable(); table.ResetCells(1, 3); //Adding rows to the table. WTableRow row = table.Rows[0]; //Set heading row height row.Height = 25f; //set heading values to the Table. for (int i = 0; i < 3; i++) { //Add paragraph for writing Text to the cells. paragraph = (IWParagraph)row.Cells[i].AddParagraph(); //Set Horizontal Alignment as Center. paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; //Writing Row Heading switch (i) { case 0: text = paragraph.AppendText("SNO"); row.Cells[i].Width = 50f; break; case 1: text = paragraph.AppendText("Drinks"); break; case 2: text = paragraph.AppendText("Showcase Image"); row.Cells[i].Width = 200f; break; } //Set row Heading formatting text.CharacterFormat.Bold = true; text.CharacterFormat.FontName = "Cambria"; text.CharacterFormat.FontSize = 11f; text.CharacterFormat.TextColor = Color.White; //Set row cells formatting row.Cells[i].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; row.Cells[i].CellFormat.BackColor = Color.FromArgb(157, 161, 190); row.Cells[i].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; } int sno = 1; //Writing Sno, Product name and Product Images to the Table. row1 = table.AddRow(false); //Writing SNO to the table with formatting text. paragraph = (IWParagraph)row1.Cells[0].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText(sno.ToString()); text.CharacterFormat.Bold = true; text.CharacterFormat.FontSize = 10f; row1.Cells[0].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; row1.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[0].CellFormat.BackColor = Color.FromArgb(217, 223, 239); //Writing Product Name to the table with Formatting. paragraph = (IWParagraph)row1.Cells[1].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText("Apple Juice"); text.CharacterFormat.Bold = true; text.CharacterFormat.FontSize = 10f; text.CharacterFormat.TextColor = Color.FromArgb(50, 65, 124); row1.Cells[1].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; row1.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[1].CellFormat.BackColor = Color.FromArgb(217, 223, 239); Assembly execAssm = typeof(TableFormattingDemo).GetTypeInfo().Assembly; //Writing Product Images to the Table. paragraph = (IWParagraph)row1.Cells[2].AddParagraph(); Stream imageStream = execAssm.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.DocIO.DocIO.Assets.Apple.png"); paragraph.AppendPicture(imageStream); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; row1.Cells[2].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; row1.Cells[2].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[2].CellFormat.BackColor = Color.FromArgb(217, 223, 239); sno++; row1 = table.AddRow(false); //Writing SNO to the table with formatting text. paragraph = (IWParagraph)row1.Cells[0].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText(sno.ToString()); text.CharacterFormat.Bold = true; text.CharacterFormat.FontSize = 10f; row1.Cells[0].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; row1.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[0].CellFormat.BackColor = Color.FromArgb(217, 223, 239); //Writing Product Name to the table with Formatting. paragraph = (IWParagraph)row1.Cells[1].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText("Grape Juice"); text.CharacterFormat.Bold = true; text.CharacterFormat.FontSize = 10f; text.CharacterFormat.TextColor = Color.FromArgb(50, 65, 124); row1.Cells[1].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; row1.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[1].CellFormat.BackColor = Color.FromArgb(217, 223, 239); //Writing Product Images to the Table. paragraph = (IWParagraph)row1.Cells[2].AddParagraph(); imageStream = execAssm.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.DocIO.DocIO.Assets.Grape.png"); paragraph.AppendPicture(imageStream); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; row1.Cells[2].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; row1.Cells[2].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[2].CellFormat.BackColor = Color.FromArgb(217, 223, 239); sno++; row1 = table.AddRow(false); //Writing SNO to the table with formatting text. paragraph = (IWParagraph)row1.Cells[0].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText(sno.ToString()); text.CharacterFormat.Bold = true; text.CharacterFormat.FontSize = 10f; row1.Cells[0].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; row1.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[0].CellFormat.BackColor = Color.FromArgb(217, 223, 239); //Writing Product Name to the table with Formatting. paragraph = (IWParagraph)row1.Cells[1].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText("Hot Soup"); text.CharacterFormat.Bold = true; text.CharacterFormat.FontSize = 10f; text.CharacterFormat.TextColor = Color.FromArgb(50, 65, 124); row1.Cells[1].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; row1.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[1].CellFormat.BackColor = Color.FromArgb(217, 223, 239); //Writing Product Images to the Table. paragraph = (IWParagraph)row1.Cells[2].AddParagraph(); imageStream = execAssm.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.DocIO.DocIO.Assets.Soup.png"); paragraph.AppendPicture(imageStream); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; row1.Cells[2].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; row1.Cells[2].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[2].CellFormat.BackColor = Color.FromArgb(217, 223, 239); sno++; #endregion Table with Images Save(rdDoc.IsChecked == true, document); }
public async Task <IActionResult> GenerateDocument(int Id, string tokenId) { var LabTest = _context.TblLabTests .Include(x => x.MethodNavigation) .Include(x => x.BiodataNavigation) .Include(x => x.BiodataNavigation.GenderNavigation) .Include(x => x.TblLabTestsIndicatorsValues) .Include(x => x.TblLabTestsSpecimen) .FirstOrDefault(x => x.Id == Id); if (LabTest == null) { return(NotFound()); } //Loads or opens an existing word document through Open method of WordDocument class Stream fs = new FileStream("Templates/result.docx", FileMode.Open, FileAccess.Read, FileShare.Read); WordDocument document = new WordDocument(fs, FormatType.Docx); if (document.Sections.Count < 1) { throw new Exception("Result template empty. Please contact your Application support."); } IWSection section = document.Sections[0]; IWTable table = section.Tables[0]; WParagraph p = (WParagraph)table.Rows[0].Cells[1].ChildEntities[0]; p.AppendText(LabTest.BiodataNavigation.Fullname); p = (WParagraph)table.Rows[1].Cells[1].ChildEntities[0]; string gardian = LabTest.BiodataNavigation.LegalGardianName; gardian = string.IsNullOrEmpty(gardian) ? "-" : gardian; p.AppendText(gardian); p = (WParagraph)table.Rows[2].Cells[1].ChildEntities[0]; p.AppendText(LabTest.BiodataNavigation.Dateofbirth.ToString("dd/MMM/yyyy")); //skip 3 //Repos.GenderRepos genders = new Repos.GenderRepos(); int g_id = 1; foreach (var g in _context.TlkpGenders) { string tmp = g.Gender.Substring(0, 2).Trim().Trim('='); try { p = (WParagraph)table.Rows[3].Cells[g_id].ChildEntities[0]; WCheckBox checkbox = p.AppendCheckBox(); if (LabTest.BiodataNavigation.Gender == g_id) { checkbox.Checked = true; } p.AppendText(" " + tmp); g_id++; } catch { } } p = (WParagraph)table.Rows[4].Cells[1].ChildEntities[0]; p.AppendText(LabTest.BiodataNavigation.EpidNo); //skip 5 for local phone number p = (WParagraph)table.Rows[5].Cells[1].ChildEntities[0]; p.AppendText(LabTest.BiodataNavigation.LocalPhone ?? "-"); p = (WParagraph)table.Rows[6].Cells[1].ChildEntities[0]; p.AppendText(LabTest.BiodataNavigation.HomePhone ?? "-"); p = (WParagraph)table.Rows[7].Cells[1].ChildEntities[0]; p.AppendText(LabTest.BiodataNavigation.ResidentialAddress); //next table table = section.Tables[1]; p = (WParagraph)table.Rows[0].Cells[1].ChildEntities[0]; p.AppendText(LabTest.MethodNavigation.Methodname); int k = 1; foreach (var i in LabTest.TblLabTestsIndicatorsValues) { var iname = _context.TlkpTestIndicators.FirstOrDefault(x => x.Id == i.Indicator).IndicatorName; p = (WParagraph)table.Rows[k].Cells[0].ChildEntities[0]; p.AppendText(iname); p = (WParagraph)table.Rows[k].Cells[1].ChildEntities[0]; p.AppendText(i.IndicatorValue.Value.ToString()); k++; } /*Dictionary<int, string> _dict = new Dictionary<int, string> { * { 1, "POSITIVE"}, * { 2, "NEGATIVE"}, * { 97, "NO RESULT"} * };*/ var p1 = (WParagraph)table.Rows[k].Cells[0].ChildEntities[0]; p = (WParagraph)table.Rows[k].Cells[1].ChildEntities[0]; WCheckBox checkbox1 = p.AppendCheckBox(); if (LabTest.Interpretation == 2) { checkbox1.Checked = true; p1.AppendText("INTERPRETATION: NEGATIVE RESULT"); } else if (LabTest.Interpretation > 2) { p1.AppendText("INTERPRETATION: UNKNOWN"); } p.AppendText(" NEGATIVE"); p = (WParagraph)table.Rows[k + 1].Cells[1].ChildEntities[0]; checkbox1 = p.AppendCheckBox(); if (LabTest.Interpretation == 1) { checkbox1.Checked = true; p1.AppendText("INTERPRETATION: POSITIVE RESULT"); } p.AppendText(" POSITIVE"); //next table table = section.Tables[2]; DateTime d1 = DateTime.Today; // any date will do p = (WParagraph)table.Rows[0].Cells[1].ChildEntities[0]; p.AppendText(LabTest.TestingDate.Value.ToString("dd/MMM/yyyy")); p = (WParagraph)table.Rows[1].Cells[1].ChildEntities[0]; TimeSpan t = LabTest.TestingTime.Value; string chg = (d1 + t).ToString("hh:mm tt"); p.AppendText(chg); p = (WParagraph)table.Rows[2].Cells[1].ChildEntities[0]; p.AppendText(LabTest.ReportingDate.Value.ToString("dd/MMM/yyyy")); p = (WParagraph)table.Rows[3].Cells[1].ChildEntities[0]; t = LabTest.ReportingTime.Value; chg = (d1 + t).ToString("hh:mm tt"); p.AppendText(chg); //next table table = section.Tables[3]; //Repos.SpecimenRepos _specimen = new Repos.SpecimenRepos(); k = 1; foreach (var s in LabTest.TblLabTestsSpecimen) { bool other = s.Specimen == 99; var sname = _context.TlkpSpecimen.FirstOrDefault(x => x.Id == s.Specimen).Type; p = (WParagraph)table.Rows[k].Cells[0].ChildEntities[0]; IWTextRange textRange = p.AppendText(sname + (other ? " (Specify)" : "")); textRange.CharacterFormat.FontSize = 8; p.ApplyStyle(BuiltinStyle.BlockText); p = (WParagraph)table.Rows[k].Cells[1].ChildEntities[0]; if (other && !string.IsNullOrEmpty(s.SpecimenOther)) { textRange = p.AppendText(s.SpecimenOther); textRange.CharacterFormat.FontSize = 10; } p = (WParagraph)table.Rows[k].Cells[2].ChildEntities[0]; checkbox1 = p.AppendCheckBox(); if (s.Checked) { checkbox1.Checked = true; } k++; } // //table = section.Tables[1]; // p = (WParagraph)table.Rows[6].Cells[1].ChildEntities[0]; //p.AppendText(LabTest.BioData.ResidentialAddress); DocIORenderer render = new DocIORenderer(); //Converts Word document to PDF. PdfDocument pdfDocument = render.ConvertToPDF(document); //Release the resources used by the Word document and DocIO Renderer objects. render.Dispose(); render.Dispose(); document.Dispose(); //add barcode PdfQRBarcode barcode = new PdfQRBarcode(); barcode.ErrorCorrectionLevel = PdfErrorCorrectionLevel.High; //Set XDimension barcode.XDimension = 2.5f; //https://localhost:44353/LabTests/Details/ string endpoint = configuration.GetConnectionString("ServerEndpoint"); barcode.Text = string.Format("{0}LabTests/Details/{1}", endpoint, Id); //Creating new PDF Document //PdfDocument doc = new PdfDocument(); //Adding new page to PDF document PdfPage page = pdfDocument.Pages[0]; //Printing barcode on to the Pdf. //barcode.Draw(page, new PointF(25, 70)); barcode.Draw(page, new PointF(250, 650)); if (!string.IsNullOrEmpty(tokenId)) { Response.Cookies.Append("fileDownloadToken", tokenId); } MemoryStream stream = new MemoryStream(); //document.Save(stream, FormatType.Docx); pdfDocument.Save(stream); //return File(stream, "application/msword", "Sample.docx"); return(File(stream.ToArray(), "application/octet-stream", "Draft.pdf")); //return RedirectToAction(nameof(Index)); }
private void button1_Click(object sender, EventArgs e) { try { WordDocument doc = new WordDocument(); doc.EnsureMinimal(); WParagraph para = doc.LastParagraph; para.AppendText("Essential DocIO - Table of Contents"); para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; para.ApplyStyle(BuiltinStyle.Heading4); para = doc.LastSection.AddParagraph() as WParagraph; para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; para.ApplyStyle(BuiltinStyle.Heading4); if (!this.checkBox6.Checked) { para.AppendText("Select TOC and press F9 to update the Table of Contents").CharacterFormat.HighlightColor = Color.Yellow; } para = doc.LastSection.AddParagraph() as WParagraph; string title = this.textBox1.Text + "\n"; para.AppendText(title); para.ApplyStyle(BuiltinStyle.Heading4); //Insert TOC TableOfContent toc = para.AppendTOC(1, 3); para.ApplyStyle(BuiltinStyle.Heading4); //Apply built-in paragraph formatting WSection section = doc.LastSection; // Set Margin of the document section.PageSetup.Margins.All = 72; if (radioButton1.Checked) { #region Default Styles WParagraph newPara = section.AddParagraph() as WParagraph; newPara = section.AddParagraph() as WParagraph; newPara.AppendBreak(BreakType.PageBreak); WTextRange text = newPara.AppendText("Document with Default styles") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading1); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading1 of built in style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can only insert TOC field in a word document. It can not refresh or create TOC field. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Section1") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading2); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph1") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph2") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph."); section.AddParagraph(); section = doc.AddSection() as WSection; section.BreakCode = SectionBreakCode.NewPage; newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Section2") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading2); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph1") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph2") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph."); #endregion } else { #region Custom styles //Custom styles. WParagraphStyle pStyle1 = (WParagraphStyle)doc.AddParagraphStyle("MyStyle1"); WParagraphStyle pStyle2 = (WParagraphStyle)doc.AddParagraphStyle("MyStyle2"); WParagraphStyle pStyle3 = (WParagraphStyle)doc.AddParagraphStyle("MyStyle3"); //Set the Heading Styles to false in order to define custom levels to TOC. toc.UseHeadingStyles = false; //Set the TOC level style which determines; based on which the TOC should be created. toc.SetTOCLevelStyle(1, "MyStyle1"); toc.SetTOCLevelStyle(2, "MyStyle2"); toc.SetTOCLevelStyle(3, "MyStyle3"); section = doc.AddSection() as WSection; pStyle1.CharacterFormat.FontName = "Cambria"; pStyle1.CharacterFormat.FontSize = 30f; para = section.AddParagraph() as WParagraph; WTextRange text = para.AppendText("Document with Custom Styles") as WTextRange; para.ApplyStyle("MyStyle1"); para = doc.LastSection.AddParagraph() as WParagraph; para.AppendText("This is the heading1 of built in style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can only insert TOC field in a word document. It can not refresh or create TOC field. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC."); pStyle2.CharacterFormat.FontName = "Cambria"; pStyle2.CharacterFormat.FontSize = 20f; doc.LastSection.AddParagraph(); para = doc.LastSection.AddParagraph() as WParagraph; text = para.AppendText("Section1") as WTextRange; para.ApplyStyle("MyStyle2"); para = doc.LastSection.AddParagraph() as WParagraph; para.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); pStyle3.CharacterFormat.FontName = "Cambria"; pStyle3.CharacterFormat.FontSize = 14f; doc.LastSection.AddParagraph(); para = doc.LastSection.AddParagraph() as WParagraph; text = para.AppendText("Section2") as WTextRange; para.ApplyStyle("MyStyle3"); para = doc.LastSection.AddParagraph() as WParagraph; para.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); #endregion } if (this.numericUpDown2.Value < this.numericUpDown1.Value) { MessageBoxAdv.Show("Not a valid heading level range. UpperHeadingLevel must be greater than LowerHeadingLevel"); } else { toc.IncludePageNumbers = checkBox1.Checked; toc.RightAlignPageNumbers = checkBox2.Checked; toc.UseHyperlinks = checkBox3.Checked; toc.LowerHeadingLevel = Convert.ToInt32(this.numericUpDown1.Value); toc.UpperHeadingLevel = Convert.ToInt32(this.numericUpDown2.Value); //Right click text. Select Paragraph option. Set OutlineLevel. Update TOC toc see the text added in TOC. toc.UseOutlineLevels = this.checkBox4.Checked; //Select the text that should be marked as Table of contents. //Press ALT+SHIFT+O. A dialog box will appear with options to enter the text, select the table identifier and level. //Choose the table identifier and level for the test and click �Mark�. Update TOC toc see the text added in TOC. //Sets the Table Identifier if necessary. //toc.TableID = "B"; toc.UseTableEntryFields = this.checkBox5.Checked; //Updates the table of contents. if (this.checkBox6.Checked) { doc.UpdateTableOfContents(); } //Save as doc format if (wordDocRadioBtn.Checked) { //Saving the document to disk. doc.Save("Sample.doc"); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer] #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.doc") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start("Sample.doc"); #endif //Exit this.Close(); } } //Save as docx format else if (wordDocxRadioBtn.Checked) { //Saving the document as .docx doc.Save("Sample.docx", FormatType.Docx); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { try { //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer] #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.docx") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start("Sample.docx"); #endif //Exit this.Close(); } catch (Win32Exception ex) { MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system"); Console.WriteLine(ex.ToString()); } } } //Save as pdf format else if (pdfRadioBtn.Checked) { DocToPDFConverter converter = new DocToPDFConverter(); //Convert word document into PDF document PdfDocument pdfDoc = converter.ConvertToPDF(doc); //Save the pdf file pdfDoc.Save("Sample.pdf"); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { try { #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.pdf") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start("Sample.pdf"); #endif //Exit this.Close(); } catch (Exception ex) { MessageBoxAdv.Show("PDF Viewer is not installed in this system"); Console.WriteLine(ex.ToString()); } } } else { // Exit this.Close(); } } } catch (Exception Ex) { MessageBox.Show(Ex.Message); } }
private void button1_Click(object sender, System.EventArgs e) { try { // Create a new document. WordDocument document = new WordDocument(); // Adding a new section to the document. IWSection section = document.AddSection(); section.PageSetup.DifferentFirstPage = true; IWTextRange textRange; IWParagraph paragraph = section.AddParagraph(); // -------------------------------------------- // Table in page header // -------------------------------------------- IWParagraph hParagraph = new WParagraph(document); hParagraph.AppendText("Header text\r\n").CharacterFormat.FontSize = 14; section.HeadersFooters.FirstPageHeader.Paragraphs.Add(hParagraph); IWTable hTable = document.LastSection.HeadersFooters.FirstPageHeader.AddTable(); hTable.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; hTable.TableFormat.Paddings.All = 5.4f; hTable.ResetCells(2, 2); hTable[0, 0].AddParagraph().AppendText("1"); hTable[0, 1].AddParagraph().AppendText("2"); hTable[1, 0].AddParagraph().AppendText("3"); hTable[1, 1].AddParagraph().AppendText("4"); // -------------------------------------------- // Tiny table // -------------------------------------------- paragraph = section.AddParagraph(); paragraph.AppendText("Tiny table\r\n").CharacterFormat.FontSize = 14; paragraph = section.AddParagraph(); WTextBody textBody = section.Body; IWTable table = textBody.AddTable(); table.ResetCells(2, 2); table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; table.TableFormat.Paddings.All = 5.4f; WTableRow row_0 = table.Rows[0]; row_0.Cells[0].AddParagraph().AppendText("A"); row_0.Cells[0].AddParagraph().AppendText("AA"); row_0.Cells[0].AddParagraph().AppendText("AAA"); WTableRow row_1 = table.Rows[1]; row_1.Cells[1].AddParagraph().AppendText("B"); row_1.Cells[1].AddParagraph().AppendText("BB\r\nBBB"); row_1.Cells[1].AddParagraph().AppendText("BBB"); textBody.AddParagraph().AppendText("Text after table...").CharacterFormat.FontSize = 14; // -------------------------------------------- // Table with different formatting // -------------------------------------------- section.AddParagraph(); paragraph = section.AddParagraph(); paragraph.AppendText("Table with different formatting\r\n").CharacterFormat.FontSize = 14; paragraph = section.AddParagraph(); textBody = section.Body; table = textBody.AddTable(); table.ResetCells(3, 3); /* ------- First Row -------- */ WTableRow row0 = table.Rows[0]; paragraph = (IWParagraph)row0.Cells[0].AddParagraph(); textRange = paragraph.AppendText("1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; textRange.CharacterFormat.FontName = "Arial"; textRange.CharacterFormat.Bold = true; textRange.CharacterFormat.FontSize = 14f; row0.Cells[0].CellFormat.Borders.LineWidth = 2f; row0.Cells[0].CellFormat.Borders.Color = Color.Magenta; paragraph = (IWParagraph)row0.Cells[1].AddParagraph(); textRange = paragraph.AppendText("2"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Right; textRange.CharacterFormat.Emboss = true; textRange.CharacterFormat.FontSize = 15f; row0.Cells[1].CellFormat.Borders.LineWidth = 1.3f; row0.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DoubleWave; paragraph = (IWParagraph)row0.Cells[2].AddParagraph(); textRange = paragraph.AppendText("3"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; textRange.CharacterFormat.Engrave = true; textRange.CharacterFormat.FontSize = 15f; row0.Cells[2].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Emboss3D; /* ------- Second Row -------- */ WTableRow row1 = table.Rows[1]; paragraph = (IWParagraph)row1.Cells[0].AddParagraph(); textRange = paragraph.AppendText("4"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; textRange.CharacterFormat.SmallCaps = true; textRange.CharacterFormat.FontName = "Comic Sans MS"; textRange.CharacterFormat.FontSize = 16; row1.Cells[0].CellFormat.Borders.LineWidth = 2f; row1.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DashDotStroker; paragraph = (IWParagraph)row1.Cells[1].AddParagraph(); textRange = paragraph.AppendText("5"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; textRange.CharacterFormat.FontName = "Times New Roman"; textRange.CharacterFormat.Shadow = true; textRange.CharacterFormat.TextBackgroundColor = Color.Orange; textRange.CharacterFormat.FontSize = 15f; row1.Cells[1].CellFormat.Borders.LineWidth = 2f; row1.Cells[1].CellFormat.Borders.Color = Color.Brown; paragraph = (IWParagraph)row1.Cells[2].AddParagraph(); textRange = paragraph.AppendText("6"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; textRange.CharacterFormat.Bold = true; textRange.CharacterFormat.FontSize = 14f; row1.Cells[2].CellFormat.BackColor = Color.FromArgb(51, 51, 101); row1.Cells[2].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; /* ------- Third Row -------- */ WTableRow row2 = table.Rows[2]; paragraph = (IWParagraph)row2.Cells[0].AddParagraph(); textRange = paragraph.AppendText("7"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Right; textRange.CharacterFormat.FontSize = 13f; row2.Cells[0].CellFormat.Borders.LineWidth = 1.5f; row2.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DashLargeGap; paragraph = (IWParagraph)row2.Cells[1].AddParagraph(); textRange = paragraph.AppendText("8"); textRange.CharacterFormat.TextColor = Color.Blue; textRange.CharacterFormat.FontSize = 16f; row2.Cells[1].CellFormat.Borders.LineWidth = 3f; row2.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Wave; paragraph = (IWParagraph)row2.Cells[2].AddParagraph(); textRange = paragraph.AppendText("9"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Right; row2.Cells[2].CellFormat.Borders.LineWidth = 2f; row2.Cells[2].CellFormat.Borders.Color = Color.Cyan; row2.Cells[2].CellFormat.Borders.Shadow = true; row2.Cells[2].CellFormat.Borders.Space = 20; // -------------------------------------------- // Table Cell Merging. // -------------------------------------------- section.AddParagraph(); paragraph = section.AddParagraph(); paragraph.AppendText("Table Cell Merging...").CharacterFormat.FontSize = 14; section.AddParagraph(); paragraph = section.AddParagraph(); textBody = section.Body; // Adding a new Table to the textbody. table = textBody.AddTable(); table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; table.TableFormat.Paddings.All = 5.4f; RowFormat format = new RowFormat(); format.Paddings.All = 5; format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Dot; format.Borders.LineWidth = 2; // Inserting rows to the table. table.ResetCells(6, 6, format, 80); // Table formatting with cell merging. table.Rows[0].Cells[0].CellFormat.HorizontalMerge = CellMerge.Start; table.Rows[0].Cells[1].CellFormat.HorizontalMerge = CellMerge.Continue; table.Rows[0].Cells[0].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; table.Rows[0].Cells[0].CellFormat.BackColor = Color.FromArgb(218, 230, 246); IWParagraph par = table.Rows[0].Cells[0].AddParagraph(); par.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; par.AppendText("Horizontal Merge").CharacterFormat.Bold = true; table.Rows[2].Cells[3].CellFormat.VerticalMerge = CellMerge.Start; table.Rows[3].Cells[3].CellFormat.VerticalMerge = CellMerge.Continue; table.Rows[2].Cells[3].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; par = table.Rows[2].Cells[3].AddParagraph(); table.Rows[2].Cells[3].CellFormat.BackColor = Color.FromArgb(252, 172, 85); par.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; par.AppendText("Vertical Merge").CharacterFormat.Bold = true; #region Table Cell Spacing. // -------------------------------------------- // Table Cell Spacing. // -------------------------------------------- section.AddParagraph(); paragraph = section.AddParagraph(); paragraph.AppendText("Table Cell spacing...").CharacterFormat.FontSize = 14; section.AddParagraph(); paragraph = section.AddParagraph(); textBody = section.Body; // Adding a new Table to the textbody. table = textBody.AddTable(); format = new RowFormat(); format.Paddings.All = 5; format.CellSpacing = 2; format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DotDash; format.IsBreakAcrossPages = true; table.ResetCells(25, 5, format, 90); IWTextRange text; table.Rows[0].IsHeader = true; for (int i = 0; i < table.Rows[0].Cells.Count; i++) { paragraph = table[0, i].AddParagraph() as WParagraph; paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText(string.Format("Header {0}", i + 1)); text.CharacterFormat.Font = new Font("Bitstream Vera Serif", 10); text.CharacterFormat.Bold = true; text.CharacterFormat.TextColor = Color.FromArgb(0, 21, 84); table[0, i].CellFormat.BackColor = Color.FromArgb(203, 211, 226); } for (int i = 1; i < table.Rows.Count; i++) { for (int j = 0; j < 5; j++) { paragraph = table[i, j].AddParagraph() as WParagraph; paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText(string.Format("Cell {0} , {1}", i, j + 1)); text.CharacterFormat.TextColor = Color.FromArgb(242, 151, 50); text.CharacterFormat.Bold = true; if (i % 2 != 1) { table[i, j].CellFormat.BackColor = Color.FromArgb(231, 235, 245); } else { table[i, j].CellFormat.BackColor = Color.FromArgb(246, 249, 255); } } } #endregion Table Cell Spacing. #region Nested Table // -------------------------------------------- // Nested Table. // -------------------------------------------- section.AddParagraph(); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.PageBreakBefore = true; paragraph.AppendText("Nested Table...").CharacterFormat.FontSize = 14; section.AddParagraph(); paragraph = section.AddParagraph(); textBody = section.Body; // Adding a new Table to the textbody. table = textBody.AddTable(); format = new RowFormat(); format.Paddings.All = 5; format.CellSpacing = 2.5f; format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DotDash; table.ResetCells(5, 3, format, 100); for (int i = 0; i < table.Rows[0].Cells.Count; i++) { paragraph = table[0, i].AddParagraph() as WParagraph; paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText(string.Format("Header {0}", i + 1)); text.CharacterFormat.Font = new Font("Bitstream Vera Serif", 10); text.CharacterFormat.Bold = true; text.CharacterFormat.TextColor = Color.FromArgb(0, 21, 84); table[0, i].CellFormat.BackColor = Color.FromArgb(242, 151, 50); } table[0, 2].Width = 200; for (int i = 1; i < table.Rows.Count; i++) { for (int j = 0; j < 3; j++) { paragraph = table[i, j].AddParagraph() as WParagraph; paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; if ((i == 2) && (j == 2)) { text = paragraph.AppendText("Nested Table"); } else { text = paragraph.AppendText(string.Format("Cell {0} , {1}", i, j + 1)); } if ((j == 2)) { table[i, j].Width = 200; } text.CharacterFormat.TextColor = Color.FromArgb(242, 151, 50); text.CharacterFormat.Bold = true; } } // Adding a nested Table. IWTable nestTable = table[2, 2].AddTable(); format = new RowFormat(); format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DotDash; format.HorizontalAlignment = RowAlignment.Center; nestTable.ResetCells(3, 3, format, 45); for (int i = 0; i < nestTable.Rows.Count; i++) { for (int j = 0; j < 3; j++) { paragraph = nestTable[i, j].AddParagraph() as WParagraph; paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; nestTable[i, j].CellFormat.BackColor = Color.FromArgb(231, 235, 245); text = paragraph.AppendText(string.Format("Cell {0} , {1}", i, j + 1)); text.CharacterFormat.TextColor = Color.Black; text.CharacterFormat.Bold = true; } } #endregion Nested Table #region Table with Images string dataPath = Application.StartupPath + @"..\..\..\..\..\..\..\..\Common\images\DocIO\"; //Add a new section to the document. section = document.AddSection(); //Add paragraph to the section. paragraph = section.AddParagraph(); //Writing text. textRange = paragraph.AppendText("Table with Images"); textRange.CharacterFormat.FontSize = 13f; textRange.CharacterFormat.TextColor = Color.DarkBlue; textRange.CharacterFormat.Bold = true; //Add paragraph to the section. section.AddParagraph(); paragraph = section.AddParagraph(); text = null; //Adding a new Table to the paragraph. table = section.Body.AddTable(); table.ResetCells(1, 3); //Adding rows to the table. WTableRow row = table.Rows[0]; //Set heading row height row.Height = 25f; //set heading values to the Table. for (int i = 0; i < 3; i++) { //Add paragraph for writing Text to the cells. paragraph = (IWParagraph)row.Cells[i].AddParagraph(); //Set Horizontal Alignment as Center. paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; //Writing Row Heading switch (i) { case 0: text = paragraph.AppendText("SNO"); row.Cells[i].Width = 50f; break; case 1: text = paragraph.AppendText("Drinks"); break; case 2: text = paragraph.AppendText("Showcase Image"); row.Cells[i].Width = 200f; break; } //Set row Heading formatting text.CharacterFormat.Bold = true; text.CharacterFormat.FontName = "Cambria"; text.CharacterFormat.FontSize = 11f; text.CharacterFormat.TextColor = Color.White; //Set row cells formatting row.Cells[i].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; row.Cells[i].CellFormat.BackColor = Color.FromArgb(157, 161, 190); row.Cells[i].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; } int sno = 1; //Writing Sno, Product name and Product Images to the Table. row1 = table.AddRow(false); //Writing SNO to the table with formatting text. paragraph = (IWParagraph)row1.Cells[0].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText(sno.ToString()); text.CharacterFormat.Bold = true; text.CharacterFormat.FontSize = 10f; row1.Cells[0].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; row1.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[0].CellFormat.BackColor = Color.FromArgb(217, 223, 239); //Writing Product Name to the table with Formatting. paragraph = (IWParagraph)row1.Cells[1].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText("Apple Juice"); text.CharacterFormat.Bold = true; text.CharacterFormat.FontSize = 10f; text.CharacterFormat.TextColor = Color.FromArgb(50, 65, 124); row1.Cells[1].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; row1.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[1].CellFormat.BackColor = Color.FromArgb(217, 223, 239); //Writing Product Images to the Table. paragraph = (IWParagraph)row1.Cells[2].AddParagraph(); paragraph.AppendPicture(Image.FromFile(dataPath + "Apple Juice.png")); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; row1.Cells[2].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; row1.Cells[2].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[2].CellFormat.BackColor = Color.FromArgb(217, 223, 239); sno++; row1 = table.AddRow(false); //Writing SNO to the table with formatting text. paragraph = (IWParagraph)row1.Cells[0].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText(sno.ToString()); text.CharacterFormat.Bold = true; text.CharacterFormat.FontSize = 10f; row1.Cells[0].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; row1.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[0].CellFormat.BackColor = Color.FromArgb(217, 223, 239); //Writing Product Name to the table with Formatting. paragraph = (IWParagraph)row1.Cells[1].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText("Grape Juice"); text.CharacterFormat.Bold = true; text.CharacterFormat.FontSize = 10f; text.CharacterFormat.TextColor = Color.FromArgb(50, 65, 124); row1.Cells[1].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; row1.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[1].CellFormat.BackColor = Color.FromArgb(217, 223, 239); //Writing Product Images to the Table. paragraph = (IWParagraph)row1.Cells[2].AddParagraph(); paragraph.AppendPicture(Image.FromFile(dataPath + "Grape Juice.png")); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; row1.Cells[2].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; row1.Cells[2].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[2].CellFormat.BackColor = Color.FromArgb(217, 223, 239); sno++; row1 = table.AddRow(false); //Writing SNO to the table with formatting text. paragraph = (IWParagraph)row1.Cells[0].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText(sno.ToString()); text.CharacterFormat.Bold = true; text.CharacterFormat.FontSize = 10f; row1.Cells[0].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; row1.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[0].CellFormat.BackColor = Color.FromArgb(217, 223, 239); //Writing Product Name to the table with Formatting. paragraph = (IWParagraph)row1.Cells[1].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText("Hot Soup"); text.CharacterFormat.Bold = true; text.CharacterFormat.FontSize = 10f; text.CharacterFormat.TextColor = Color.FromArgb(50, 65, 124); row1.Cells[1].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; row1.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[1].CellFormat.BackColor = Color.FromArgb(217, 223, 239); //Writing Product Images to the Table. paragraph = (IWParagraph)row1.Cells[2].AddParagraph(); paragraph.AppendPicture(Image.FromFile(dataPath + "Hot Soup.png")); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; row1.Cells[2].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; row1.Cells[2].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[2].CellFormat.BackColor = Color.FromArgb(217, 223, 239); sno++; #endregion Table with Images //Save as doc format if (wordDocRadioBtn.Checked) { //Saving the document to disk. document.Save("Sample.doc"); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer] #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.doc") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start("Sample.doc"); #endif //Exit this.Close(); } } //Save as docx format else if (wordDocxRadioBtn.Checked) { //Saving the document as .docx document.Save("Sample.docx", FormatType.Docx); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { try { //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer] #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.docx") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start("Sample.docx"); #endif //Exit this.Close(); } catch (Win32Exception ex) { MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system"); Console.WriteLine(ex.ToString()); } } } //Save as pdf format else if (pdfRadioBtn.Checked) { DocToPDFConverter converter = new DocToPDFConverter(); //Convert word document into PDF document PdfDocument pdfDoc = converter.ConvertToPDF(document); //Save the pdf file pdfDoc.Save("Sample.pdf"); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { try { #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.pdf") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start("Sample.pdf"); #endif //Exit this.Close(); } catch (Exception ex) { MessageBoxAdv.Show("PDF Viewer is not installed in this system"); Console.WriteLine(ex.ToString()); } } } else { // Exit this.Close(); } } catch (Exception Ex) { MessageBox.Show(Ex.Message); } }
public ActionResult TableofContents(string Group1, string UpdateTOC) { if (Group1 == null) { return(View()); } WordDocument doc = new WordDocument(); doc.EnsureMinimal(); WParagraph para = doc.LastParagraph; para.AppendText("Essential DocIO - Table of Contents"); para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; para.ApplyStyle(BuiltinStyle.Heading4); para = doc.LastSection.AddParagraph() as WParagraph; para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; para.ApplyStyle(BuiltinStyle.Heading4); if (UpdateTOC != "Update") { para.AppendText("Select TOC and press F9 to update the Table of Contents").CharacterFormat.HighlightColor = Syncfusion.Drawing.Color.Yellow; } para = doc.LastSection.AddParagraph() as WParagraph; //Insert TOC TableOfContent toc = para.AppendTOC(1, 3); para.ApplyStyle(BuiltinStyle.Heading4); //Apply built-in paragraph formatting WSection section = doc.LastSection; #region Default Styles WParagraph newPara = section.AddParagraph() as WParagraph; newPara = section.AddParagraph() as WParagraph; newPara.AppendBreak(BreakType.PageBreak); WTextRange text = newPara.AppendText("Document with Default styles") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading1); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading1 of built in style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can only insert TOC field in a word document. It can not refresh or create TOC field. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Section1") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading2); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph1") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph2") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph."); section.AddParagraph(); section = doc.AddSection() as WSection; section.BreakCode = SectionBreakCode.NewPage; newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Section2") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading2); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph1") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph2") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph."); #endregion toc.IncludePageNumbers = true; toc.RightAlignPageNumbers = true; toc.UseHyperlinks = true; toc.LowerHeadingLevel = 1; toc.UpperHeadingLevel = 3; toc.UseOutlineLevels = true; //Updates the table of contents. if (UpdateTOC == "Update") { doc.UpdateTableOfContents(); } #region Document SaveOption string filename = ""; string contenttype = ""; MemoryStream ms = new MemoryStream(); //Save as .docx format if (Group1 == "WordDocx") { filename = "Table of Contents.docx"; contenttype = "application/vnd.ms-word.document.12"; doc.Save(ms, FormatType.Docx); } // Save as .doc format else if (Group1 == "WordDoc") { filename = "Table of Contents.doc"; contenttype = "application/msword"; doc.Save(ms, FormatType.Doc); } //Save as .xml format else if (Group1 == "WordML") { filename = "Table of Contents.xml"; contenttype = "application/msword"; doc.Save(ms, FormatType.WordML); } //Save as .pdf format else if (Group1 == "Pdf") { filename = "Table of Contents.pdf"; contenttype = "application/pdf"; Syncfusion.DocIORenderer.DocIORenderer renderer = new Syncfusion.DocIORenderer.DocIORenderer(); Syncfusion.Pdf.PdfDocument pdfDoc = renderer.ConvertToPDF(doc); pdfDoc.Save(ms); pdfDoc.Close(); } #endregion Document SaveOption doc.Close(); ms.Position = 0; return(File(ms, contenttype, filename)); }
protected void Button1_Click(object sender, EventArgs e) { WordDocument doc = new WordDocument(); doc.EnsureMinimal(); WParagraph para = doc.LastParagraph; para.AppendText("Essential DocIO - Table of Contents"); para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; para.ApplyStyle(BuiltinStyle.Heading4); para = doc.LastSection.AddParagraph() as WParagraph; para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; para.ApplyStyle(BuiltinStyle.Heading4); if (!this.CheckBox7.Checked) { para.AppendText("Select TOC and press F9 to update the Table of Contents").CharacterFormat.HighlightColor = Color.Yellow; } para = doc.LastSection.AddParagraph() as WParagraph; string title = this.TextBox1.Text + "\n"; para.AppendText(title); para.ApplyStyle(BuiltinStyle.Heading4); //Insert TOC TableOfContent toc = para.AppendTOC(1, 3); para.ApplyStyle(BuiltinStyle.Heading4); //Apply built-in paragraph formatting WSection section = doc.LastSection; if (this.RadioButton1.Checked) { #region Default Styles WParagraph newPara = section.AddParagraph() as WParagraph; newPara = section.AddParagraph() as WParagraph; newPara.AppendBreak(BreakType.PageBreak); WTextRange text = newPara.AppendText("Document with Default styles") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading1); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading1 of built in style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can only insert TOC field in a word document. It can not refresh or create TOC field. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Section1") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading2); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph1") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph2") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph."); section.AddParagraph(); section = doc.AddSection() as WSection; section.BreakCode = SectionBreakCode.NewPage; newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Section2") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading2); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph1") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph2") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph."); #endregion } else { #region Custom styles //Custom styles. WParagraphStyle pStyle1 = (WParagraphStyle)doc.AddParagraphStyle("MyStyle1"); WParagraphStyle pStyle2 = (WParagraphStyle)doc.AddParagraphStyle("MyStyle2"); WParagraphStyle pStyle3 = (WParagraphStyle)doc.AddParagraphStyle("MyStyle3"); //Set the Heading Styles to false in order to define custom levels to TOC. toc.UseHeadingStyles = false; //Set the TOC level style which determines; based on which the TOC should be created. toc.SetTOCLevelStyle(1, "MyStyle1"); toc.SetTOCLevelStyle(2, "MyStyle2"); toc.SetTOCLevelStyle(3, "MyStyle3"); section = doc.AddSection() as WSection; pStyle1.CharacterFormat.FontName = "Cambria"; pStyle1.CharacterFormat.FontSize = 30f; para = section.AddParagraph() as WParagraph; WTextRange text = para.AppendText("Document with Custom Styles") as WTextRange; para.ApplyStyle("MyStyle1"); para = doc.LastSection.AddParagraph() as WParagraph; para.AppendText("This is the heading1 of built in style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can only insert TOC field in a word document. It can not refresh or create TOC field. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC."); pStyle2.CharacterFormat.FontName = "Cambria"; pStyle2.CharacterFormat.FontSize = 20f; doc.LastSection.AddParagraph(); para = doc.LastSection.AddParagraph() as WParagraph; text = para.AppendText("Section1") as WTextRange; para.ApplyStyle("MyStyle2"); para = doc.LastSection.AddParagraph() as WParagraph; para.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); pStyle3.CharacterFormat.FontName = "Cambria"; pStyle3.CharacterFormat.FontSize = 14f; doc.LastSection.AddParagraph(); para = doc.LastSection.AddParagraph() as WParagraph; text = para.AppendText("Section2") as WTextRange; para.ApplyStyle("MyStyle3"); para = doc.LastSection.AddParagraph() as WParagraph; para.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); #endregion } if (Convert.ToInt32(this.DropDownList2.Text) < Convert.ToInt32(this.DropDownList1.Text)) { Response.Write("Not a valid heading level range. UpperHeadingLevel must be greater than LowerHeadingLevel"); } else { toc.IncludePageNumbers = this.CheckBox2.Checked; toc.RightAlignPageNumbers = this.CheckBox3.Checked; toc.UseHyperlinks = this.CheckBox4.Checked; toc.LowerHeadingLevel = Convert.ToInt32(this.DropDownList1.Text); toc.UpperHeadingLevel = Convert.ToInt32(this.DropDownList2.Text); //Used to set levels for a word or paragraph through OutLine Levels //Right click text. Select Paragraph option. Set OutlineLevel. Update TOC toc see the text added in TOC. toc.UseOutlineLevels = this.CheckBox5.Checked; //Used to set levels for a word or paragraph through Table Entry Fields //Select the text that should be marked as Table of contents. //Press ALT+SHIFT+O. A dialog box will appear with options to enter the text, select the table identifier and level. //Choose the table identifier and level for the test and click �Mark�. Update TOC toc see the text added in TOC. //Sets the Table Identifier if necessary. //toc.TableID = "B"; toc.UseTableEntryFields = this.CheckBox6.Checked; //Updates the table of contents. if (this.CheckBox7.Checked) { doc.UpdateTableOfContents(); } if (rdButtonDoc.Checked) { //Save as .doc format doc.Save("Sample.doc", FormatType.Doc, Response, HttpContentDisposition.Attachment); } //Save as .docx format else if (rdButtonDocx.Checked) { try { doc.Save("Sample.docx", FormatType.Docx, Response, HttpContentDisposition.Attachment); } catch (Win32Exception ex) { Response.Write("Microsoft Word Viewer or Microsoft Word is not installed in this system"); Console.WriteLine(ex.ToString()); } } //Save as WordML(.xml) format if (rdButtonWordML.Checked) { try { doc.Save("Sample.xml", FormatType.WordML, Response, HttpContentDisposition.Attachment); } catch (Win32Exception ex) { Response.Write("Microsoft Word Viewer or Microsoft Word is not installed in this system"); Console.WriteLine(ex.ToString()); } } //Save as .pdf format else if (rdButtonPdf.Checked) { try { DocToPDFConverter converter = new DocToPDFConverter(); PdfDocument pdfDoc = converter.ConvertToPDF(doc); pdfDoc.Save("Sample.pdf", Response, HttpReadType.Save); } catch (Win32Exception ex) { Response.Write("PDF Viewer is not installed in this system"); Console.WriteLine(ex.ToString()); } } } }
void OnButtonClicked(object sender, EventArgs e) { WordDocument doc = new WordDocument(); doc.EnsureMinimal(); WParagraph para = doc.LastParagraph; para.AppendText("Essential DocIO - Table of Contents"); para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; para.ApplyStyle(BuiltinStyle.Heading4); para = doc.LastSection.AddParagraph() as WParagraph; para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; para.ApplyStyle(BuiltinStyle.Heading4); para = doc.LastSection.AddParagraph() as WParagraph; //Insert TOC TableOfContent toc = para.AppendTOC(1, 3); para.ApplyStyle(BuiltinStyle.Heading4); //Apply built-in paragraph formatting WSection section = doc.LastSection; #region Default Styles WParagraph newPara = section.AddParagraph() as WParagraph; newPara = section.AddParagraph() as WParagraph; newPara.AppendBreak(BreakType.PageBreak); WTextRange text = newPara.AppendText("Document with Default styles") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading1); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading1 of built in style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can only insert TOC field in a word document. It can not refresh or create TOC field. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Section1") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading2); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph1") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph2") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph."); section.AddParagraph(); section = doc.AddSection() as WSection; section.BreakCode = SectionBreakCode.NewPage; newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Section2") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading2); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph1") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph2") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph."); #endregion toc.IncludePageNumbers = true; toc.RightAlignPageNumbers = true; toc.UseHyperlinks = true; toc.LowerHeadingLevel = 1; toc.UpperHeadingLevel = 3; toc.UseOutlineLevels = true; //Updates the table of contents. doc.UpdateTableOfContents(); string filename = ""; string contenttype = ""; MemoryStream outputStream = new MemoryStream(); if (pdfButton != null && (bool)pdfButton.IsChecked) { filename = "Table Of Contents.pdf"; contenttype = "application/pdf"; DocIORenderer renderer = new DocIORenderer(); PdfDocument pdfDoc = renderer.ConvertToPDF(doc); pdfDoc.Save(outputStream); pdfDoc.Close(); } else { filename = "Table Of Contents.docx"; contenttype = "application/msword"; doc.Save(outputStream, FormatType.Docx); } doc.Close(); if (Device.RuntimePlatform == Device.UWP) { DependencyService.Get <ISaveWindowsPhone>() .Save(filename, contenttype, outputStream); } else { DependencyService.Get <ISave>().Save(filename, contenttype, outputStream); } }
private void button1_Click_1(object sender, System.EventArgs e) { // Get Template document and database path. string dataPath = Application.StartupPath + @"..\..\..\..\..\..\..\..\Common\Data\"; try { //SDF the database and get the NorthWind AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true); DataTable table = new DataTable(); SqlCeConnection conn = new SqlCeConnection(); if (conn.ServerVersion.StartsWith("3.5")) { conn.ConnectionString = "Data Source = " + dataPath + "NorthwindIO_3.5.sdf"; } else { conn.ConnectionString = "Data Source = " + dataPath + "NorthwindIO.sdf"; } conn.Open(); SqlCeDataAdapter adapter = new SqlCeDataAdapter("Select CustomerID,CompanyName,ContactName,Address,Country,Phone from Customers", conn); adapter.Fill(table); adapter.Dispose(); conn.Close(); // Creating a new document. WordDocument document = new WordDocument(); // Adding a new section to the document. IWSection section = document.AddSection(); IWParagraph paragraph = section.AddParagraph(); paragraph.ParagraphFormat.BeforeSpacing = 20f; //Format the heading. IWTextRange text = paragraph.AppendText("Northwind Report"); text.CharacterFormat.Bold = true; text.CharacterFormat.FontName = "Cambria"; text.CharacterFormat.FontSize = 14.0f; text.CharacterFormat.TextColor = Color.DarkBlue; paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; paragraph = section.AddParagraph(); paragraph.ParagraphFormat.BeforeSpacing = 18f; //Create a new table WTextBody textBody = section.Body; IWTable docTable = textBody.AddTable(); //Set the format for rows RowFormat format = new RowFormat(); format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; format.Borders.LineWidth = 1.0F; format.Borders.Color = Color.Black; //Initialize number of rows and cloumns. docTable.ResetCells(table.Rows.Count + 1, table.Columns.Count, format, 84); //Repeat the header. docTable.Rows[0].IsHeader = true; string colName; //Format the header rows for (int c = 0; c <= table.Columns.Count - 1; c++) { string[] Cols = table.Columns[c].ColumnName.Split('|'); colName = Cols[Cols.Length - 1]; IWTextRange theadertext = docTable.Rows[0].Cells[c].AddParagraph().AppendText(colName); theadertext.CharacterFormat.FontSize = 12f; theadertext.CharacterFormat.Bold = true; theadertext.CharacterFormat.TextColor = Color.White; docTable.Rows[0].Cells[c].CellFormat.BackColor = Color.FromArgb(33, 67, 126); docTable.Rows[0].Cells[c].CellFormat.Borders.Color = Color.Black; docTable.Rows[0].Cells[c].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; docTable.Rows[0].Cells[c].CellFormat.Borders.LineWidth = 1.0f; docTable.Rows[0].Cells[c].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; } //Format the table body rows for (int r = 0; r <= table.Rows.Count - 1; r++) { for (int c = 0; c <= table.Columns.Count - 1; c++) { string Value = table.Rows[r][c].ToString(); IWTextRange theadertext = docTable.Rows[r + 1].Cells[c].AddParagraph().AppendText(Value); theadertext.CharacterFormat.FontSize = 10; docTable.Rows[r + 1].Cells[c].CellFormat.BackColor = ((r & 1) == 0) ? Color.FromArgb(237, 240, 246) : Color.FromArgb(192, 201, 219); docTable.Rows[r + 1].Cells[c].CellFormat.Borders.Color = Color.Black; docTable.Rows[r + 1].Cells[c].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; docTable.Rows[r + 1].Cells[c].CellFormat.Borders.LineWidth = 0.5f; docTable.Rows[r + 1].Cells[c].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle; } } // Add a footer paragraph text to the document. WParagraph footerPar = new WParagraph(document); // Add text. footerPar.AppendText("Copyright Syncfusion Inc. 2001 - 2017"); // Add page and Number of pages field to the document. footerPar.AppendText(" Page "); footerPar.AppendField("Page", Syncfusion.DocIO.FieldType.FieldPage); section.HeadersFooters.Footer.Paragraphs.Add(footerPar); //Save as doc format if (wordDocRadioBtn.Checked) { //Saving the document to disk. document.Save("Sample.doc"); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer] System.Diagnostics.Process.Start("Sample.doc"); //Exit this.Close(); } } //Save as docx format else if (wordDocxRadioBtn.Checked) { //Saving the document as .docx document.Save("Sample.docx", FormatType.Docx); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { try { //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer] System.Diagnostics.Process.Start("Sample.docx"); //Exit this.Close(); } catch (Win32Exception ex) { MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system"); Console.WriteLine(ex.ToString()); } } } //Save as pdf format else if (pdfRadioBtn.Checked) { DocToPDFConverter converter = new DocToPDFConverter(); //Convert word document into PDF document PdfDocument pdfDoc = converter.ConvertToPDF(document); //Save the pdf file pdfDoc.Save("Sample.pdf"); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { try { System.Diagnostics.Process.Start("Sample.pdf"); //Exit this.Close(); } catch (Exception ex) { MessageBoxAdv.Show("PDF Viewer is not installed in this system"); Console.WriteLine(ex.ToString()); } } } else { // Exit this.Close(); } } catch (Exception Ex) { // Shows the Message box with Exception message, if an exception throws. MessageBoxAdv.Show(Ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { } }
public ActionResult Styles(string Group1, string Group2) { if (Group1 == null) { return(View()); } WordDocument document = null; #region Built-in Style if (Group1 == "Built-in") { document = new WordDocument(); WSection section = document.AddSection() as WSection; WParagraph para = section.AddParagraph() as WParagraph; section.AddColumn(100, 100); section.AddColumn(100, 100); section.MakeColumnsEqual(); #region List Style //List //para = section.AddParagraph() as WParagraph; para.AppendText("This para is written with style List").CharacterFormat.UnderlineStyle = UnderlineStyle.Double; para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.List); para.AppendText("Google Chrome\n"); para.AppendText("Mozilla Firefox\n"); para.AppendText("Internet Explorer"); //List5 style para = section.AddParagraph() as WParagraph; para.AppendText("\nThis para is written with style List5").CharacterFormat.UnderlineStyle = UnderlineStyle.Double; para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.List5); para.AppendText("Google Chrome\n"); para.AppendText("Mozilla Firefox\n"); para.AppendText("Internet Explorer"); #endregion #region ListNumber Style //List Number style para = section.AddParagraph() as WParagraph; para.AppendText("\nThis para is written with style ListNumber").CharacterFormat.UnderlineStyle = UnderlineStyle.Double; para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.ListNumber); para.AppendText("Google Chrome\n"); para.AppendText("Mozilla Firefox\n"); para.AppendText("Internet Explorer"); //List Number5 style para = section.AddParagraph() as WParagraph; para.AppendText("\nThis para is written with style ListNumber5").CharacterFormat.UnderlineStyle = UnderlineStyle.Double; para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.ListNumber5); para.AppendText("Google Chrome\n"); para.AppendText("Mozilla Firefox\n"); para.AppendText("Internet Explorer"); #endregion #region TOA Heading Style //TOA Heading para = section.AddParagraph() as WParagraph; para.ParagraphFormat.AfterSpacing = 10; para.AppendText("\nThis para is written with style TOA Heading").CharacterFormat.UnderlineStyle = UnderlineStyle.Double; para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.ToaHeading); para.AppendText("Google Chrome\n"); para.AppendText("Mozilla Firefox\n"); para.AppendText("Internet Explorer"); #endregion section.BreakCode = SectionBreakCode.NewColumn; #region ListBullet Style //ListBullet para = section.AddParagraph() as WParagraph; para.AppendText("\nThis para is written with style ListBullet").CharacterFormat.UnderlineStyle = UnderlineStyle.Double; para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.ListBullet); para.AppendText("Google Chrome\n"); para.AppendText("Mozilla Firefox\n"); para.AppendText("Internet Explorer"); //ListBullet5 para = section.AddParagraph() as WParagraph; para.AppendText("\nThis para is written with style ListBullet5").CharacterFormat.UnderlineStyle = UnderlineStyle.Double; para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.ListBullet5); para.AppendText("Google Chrome\n"); para.AppendText("Mozilla Firefox\n"); para.AppendText("Internet Explorer"); #endregion #region List Continue Style //ListContinue para = section.AddParagraph() as WParagraph; para.AppendText("\nThis para is written with style ListContinue").CharacterFormat.UnderlineStyle = UnderlineStyle.Double; para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.ListContinue); para.AppendText("Google Chrome\n"); para.AppendText("Mozilla Firefox\n"); para.AppendText("Internet Explorer"); //ListContinue5 para = section.AddParagraph() as WParagraph; para.AppendText("\nThis para is written with style ListContinue5").CharacterFormat.UnderlineStyle = UnderlineStyle.Double; para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.ListContinue5); para.AppendText("Google Chrome\n"); para.AppendText("Mozilla Firefox\n"); para.AppendText("Internet Explorer"); #endregion #region HTMLSample Style //HtmlSample para = section.AddParagraph() as WParagraph; para.AppendText("\nThis para is written with style HtmlSample").CharacterFormat.UnderlineStyle = UnderlineStyle.Double; para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.HtmlSample); para.AppendText("Google Chrome\n"); para.AppendText("Mozilla Firefox\n"); para.AppendText("Internet Explorer"); #endregion section = document.AddSection() as WSection; section.BreakCode = SectionBreakCode.NoBreak; #region Document Map Style //Docuemnt Map para = section.AddParagraph() as WParagraph; para.AppendText("This para is written with style DocumentMap\n").CharacterFormat.UnderlineStyle = UnderlineStyle.Double; para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.DocumentMap); para.AppendText("Google Chrome\n").CharacterFormat.TextColor = Syncfusion.Drawing.Color.White; para.AppendText("Mozilla Firefox\n").CharacterFormat.TextColor = Syncfusion.Drawing.Color.White; para.AppendText("Internet Explorer").CharacterFormat.TextColor = Syncfusion.Drawing.Color.White; #endregion #region Heading Styles //Heading Styles para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.Heading1); para.AppendText("Hello World. This para is written with style " + para.StyleName.ToString()); para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.Heading2); para.AppendText("Hello World. This para is written with style " + para.StyleName.ToString()); para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.Heading3); para.AppendText("Hello World. This para is written with style " + para.StyleName.ToString()); para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.Heading4); para.AppendText("Hello World. This para is written with style " + para.StyleName.ToString()); para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.Heading5); para.AppendText("Hello World. This para is written with style " + para.StyleName.ToString()); para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.Heading6); para.AppendText("Hello World. This para is written with style " + para.StyleName.ToString()); para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.Heading7); para.AppendText("Hello World. This para is written with style " + para.StyleName.ToString()); para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.Heading8); para.AppendText("Hello World. This para is written with style " + para.StyleName.ToString()); para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.Heading9); para.AppendText("Hello World. This para is written with style " + para.StyleName.ToString()); #endregion #region MessageHeaderStyle //MessageHeader para = section.AddParagraph() as WParagraph; para = section.AddParagraph() as WParagraph; para.AppendText("This para is written with style MessageHeader\n").CharacterFormat.UnderlineStyle = UnderlineStyle.Double; para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.MessageHeader); para.AppendText("Google Chrome\n"); para.AppendText("Mozilla Firefox\n"); para.AppendText("Internet Explorer"); #endregion } #endregion Built-in Style #region Custom Style else { document = new WordDocument(); IWParagraphStyle style = null; // Adding a new section to the document. WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; IWParagraph par = document.LastSection.AddParagraph(); WTextRange range = par.AppendText("Using CustomStyles") as WTextRange; range.CharacterFormat.TextBackgroundColor = Syncfusion.Drawing.Color.Red; range.CharacterFormat.TextColor = Syncfusion.Drawing.Color.White; range.CharacterFormat.FontSize = 18f; document.LastParagraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; // Create Paragraph styles style = document.AddParagraphStyle("MyStyle_Normal"); style.CharacterFormat.FontName = "Bitstream Vera Serif"; style.CharacterFormat.FontSize = 10f; style.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify; style.CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(0, 21, 84); style = document.AddParagraphStyle("MyStyle_Low"); style.CharacterFormat.FontName = "Times New Roman"; style.CharacterFormat.FontSize = 16f; style.CharacterFormat.Bold = true; style = document.AddParagraphStyle("MyStyle_Medium"); style.CharacterFormat.FontName = "Monotype Corsiva"; style.CharacterFormat.FontSize = 18f; style.CharacterFormat.Bold = true; style.CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(51, 66, 125); style = document.AddParagraphStyle("Mystyle_High"); style.CharacterFormat.FontName = "Bitstream Vera Serif"; style.CharacterFormat.FontSize = 20f; style.CharacterFormat.Bold = true; style.CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(242, 151, 50); IWParagraph paragraph = null; for (int i = 0; i < document.Styles.Count; i++) { //Skip to apply the document default styles and also paragraph style. if (document.Styles[i].Name == "Normal" || document.Styles[i].Name == "Default Paragraph Font" || document.Styles[i].StyleType != StyleType.ParagraphStyle) { continue; } // Getting styles from Document. style = (IWParagraphStyle)document.Styles[i]; // Adding a new paragraph section.AddParagraph(); paragraph = section.AddParagraph(); // Applying styles to the current paragraph. paragraph.ApplyStyle(style.Name); // Writing Text with the current style and formatting. paragraph.AppendText("Northwind Database with [" + style.Name + "] Style"); // Adding a new paragraph section.AddParagraph(); paragraph = section.AddParagraph(); // Applying another style to the current paragraph. paragraph.ApplyStyle("MyStyle_Normal"); // Writing text with current style. paragraph.AppendText("The Northwind sample database (Northwind.mdb) is included with all versions of Access. It provides data you can experiment with and database objects that demonstrate features you might want to implement in your own databases. Using Northwind, you can become familiar with how a relational database is structured and how the database objects work together to help you enter, store, manipulate, and print your data."); } } #endregion Custom Style FormatType type = FormatType.Docx; string filename = "Sample.docx"; string contenttype = "application/vnd.ms-word.document.12"; #region Document SaveOption //Save as .doc format if (Group2 == "WordDoc") { type = FormatType.Doc; filename = "Sample.doc"; contenttype = "application/msword"; } //Save as .xml format else if (Group2 == "WordML") { type = FormatType.WordML; filename = "Sample.xml"; contenttype = "application/msword"; } #endregion Document SaveOption MemoryStream ms = new MemoryStream(); document.Save(ms, type); document.Close(); ms.Position = 0; return(File(ms, contenttype, filename)); }
public ActionResult Word(int id, int type, byte[] image, bool pdf = false) { var dba = new ApplicationDbContext(); int idCustomer; string idConsultant; global::Interview.Interview interview = null; Campaign campaign = null; byte[] byteArrayImg; if (type == 1 || type == 2) { idCustomer = db.Interviews.Where(i => i.IdCampaign == id).Include(i => i.Campaign.Customer).Select(i => i.Campaign.Customer.IdCustomer).FirstOrDefault(); idConsultant = db.Interviews.Where(i => i.IdCampaign == id).Select(u => u.Id).FirstOrDefault(); var idFirm = db.Users.Where(u => u.Id == idConsultant).Select(u => u.IdFirm).FirstOrDefault(); byteArrayImg = ImageController.GetImage("Firms", idFirm.ToString(), true); } else { idCustomer = db.Interviews.Where(i => i.IdInterview == id).Include(i => i.Campaign.Customer).Select(i => i.Campaign.Customer.IdCustomer).FirstOrDefault(); idConsultant = db.Interviews.Where(i => i.IdInterview == id).Select(u => u.Id).FirstOrDefault(); byteArrayImg = ImageController.GetImage("Users", idConsultant, true); } var byteArrayCust = ImageController.GetImage("Customers", idCustomer.ToString(), true); Stream streamCust = new MemoryStream(byteArrayCust); Stream streamImg = new MemoryStream(byteArrayImg); WordDocument document = new WordDocument(); IWSection section = document.AddSection(); section.PageSetup.DifferentFirstPage = true; section.PageSetup.InsertPageNumbers(false, PageNumberAlignment.Center); section.PageSetup.Margins.Left = 50; section.PageSetup.Margins.Right = 50; // Add a new paragraph for header to the document. IWParagraph headerPar = new WParagraph(document); // Add a new table to the header. IWTable table = section.HeadersFooters.FirstPageHeader.AddTable(); // Styles const string font = "Segoe UI"; Style styleTitle = (WParagraphStyle)document.AddParagraphStyle("Title"); styleTitle.CharacterFormat.FontName = font; styleTitle.CharacterFormat.FontSize = 25; styleTitle.CharacterFormat.TextColor = Color.FromArgb(31, 73, 125); Style stylePNode = (WParagraphStyle)document.AddParagraphStyle("PNode"); stylePNode.CharacterFormat.FontName = font; stylePNode.CharacterFormat.TextColor = Color.FromArgb(238, 131, 0); stylePNode.CharacterFormat.FontSize = 20; Style styleNode = (WParagraphStyle)document.AddParagraphStyle("Node"); styleNode.CharacterFormat.FontName = font; styleNode.CharacterFormat.TextColor = Color.FromArgb(195, 23, 0); styleNode.CharacterFormat.FontSize = 17; Style styleQuestion = (WParagraphStyle)document.AddParagraphStyle("Question"); styleQuestion.CharacterFormat.FontName = font; styleQuestion.CharacterFormat.Bold = true; styleQuestion.CharacterFormat.FontSize = 11; Style styleAnswer = (WParagraphStyle)document.AddParagraphStyle("Answer"); styleAnswer.CharacterFormat.FontName = font; styleAnswer.CharacterFormat.FontSize = 11; styleAnswer.CharacterFormat.TextColor = Color.FromArgb(31, 73, 125); Style styleList = (WParagraphStyle)document.AddParagraphStyle("List"); styleList.CharacterFormat.FontName = font; styleList.CharacterFormat.TextColor = Color.FromArgb(51, 132, 204); styleList.CharacterFormat.FontSize = 11; styleList.CharacterFormat.UnderlineStyle = UnderlineStyle.Single; Style styleComment = (WParagraphStyle)document.AddParagraphStyle("Comment"); styleComment.CharacterFormat.FontName = font; styleComment.CharacterFormat.Italic = true; styleComment.CharacterFormat.FontSize = 11; var format = new RowFormat(); // Setting cleared table border style. format.Borders.BorderType = BorderStyle.Cleared; // Inserting table with a row and two columns. table.ResetCells(1, 2, format, 265); IWTextRange textRange; // Inserting logo image to the table cells. headerPar = table[0, 0].AddParagraph() as WParagraph; headerPar.AppendPicture(Image.FromStream(streamImg)); (headerPar.Items[0] as WPicture).Width = 50; (headerPar.Items[0] as WPicture).Height = 50; headerPar.AppendText(Environment.NewLine); var userName = db.Users.Find(idConsultant).FullName; switch (type) { case 1: case 2: textRange = headerPar.AppendText("Manager: " + userName); textRange.CharacterFormat.FontName = font; headerPar.AppendText(Environment.NewLine); textRange = headerPar.AppendText("Type : Campaign"); textRange.CharacterFormat.FontName = font; break; case 3: case 4: textRange = headerPar.AppendText("Consultant: " + userName); textRange.CharacterFormat.FontName = font; headerPar.AppendText(Environment.NewLine); textRange = headerPar.AppendText("Type: Interview"); textRange.CharacterFormat.FontName = font; break; } headerPar.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left; var customerName = db.Customers.Find(idCustomer).Name; var industryName = db.Customers.Where(c => c.IdCustomer == idCustomer) .Include(c => c.Industry) .Select(c => c.Industry.Name).FirstOrDefault(); // Inserting text to the table second cell. headerPar = table[0, 1].AddParagraph() as WParagraph; headerPar.AppendPicture(Image.FromStream(streamCust)); ((WPicture)headerPar.Items[0]).Width = 50; ((WPicture)headerPar.Items[0]).Height = 50; headerPar.AppendText(Environment.NewLine); headerPar.AppendText("Customer: " + customerName); headerPar.AppendText(Environment.NewLine); headerPar.AppendText("Industry: " + industryName); headerPar.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Right; section = document.AddSection(); section.BreakCode = SectionBreakCode.NoBreak; IWParagraph paragraph = section.AddParagraph(); //TableOfContent toc = paragraph.AppendTOC(1, 3); //toc.UseHeadingStyles = false; //toc.SetTOCLevelStyle(1, "Title"); //toc.SetTOCLevelStyle(2, "PNode"); //toc.SetTOCLevelStyle(3, "Node"); if (type == 1 || type == 2) { campaign = db.Campaigns.Find(id); var idQuestionnaire = db.Interviews.Where(i => i.Campaign.IdCampaign == id).Include(i => i.Campaign).Select(i => i.Campaign.IdQuestionnaire).FirstOrDefault(); var questions = db.Questions.Where(q => q.IdQuestionnaire == idQuestionnaire); var questionnairename = db.Questionnaires.Find(idQuestionnaire).Name; var interviewees = db.CandidateCampaigns.Include(cc => cc.Candidate).Include(x => x.Group) .Where(cc => cc.IdCampaign == campaign.IdCampaign) .Select(x => x.Candidate); var consultants = db.Campaigns.Where(c => c.IdCampaign == campaign.IdCampaign) .Include(c => c.ApplicationUsers) .Select(c => c.ApplicationUsers); string start = ""; if (campaign.StartDate != null) { start = campaign.StartDate.Value.ToShortDateString(); } var end = ""; if (campaign.EndDate != null) { end = campaign.EndDate.Value.ToShortDateString(); } paragraph.AppendText(Environment.NewLine + Environment.NewLine + Environment.NewLine); textRange = paragraph.AppendText("Campaign: " + campaign.Name); paragraph.ApplyStyle("Title"); paragraph.AppendText(Environment.NewLine + Environment.NewLine); paragraph = section.AddParagraph(); textRange = paragraph.AppendText("Start: " + start + " -> Expected End: " + end); textRange.CharacterFormat.FontName = font; paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left; paragraph.AppendText(Environment.NewLine + Environment.NewLine); textRange = paragraph.AppendText("Questionnaire: " + questionnairename); textRange.CharacterFormat.FontName = font; paragraph.AppendText(Environment.NewLine + Environment.NewLine); textRange = paragraph.AppendText("Description: " + campaign.Description); textRange.CharacterFormat.FontName = font; paragraph.AppendText(Environment.NewLine + Environment.NewLine); if (type == 2 && !string.IsNullOrEmpty(campaign.Comment)) { textRange = paragraph.AppendText("Comment: " + campaign.Comment); textRange.CharacterFormat.FontName = font; } paragraph.AppendText(Environment.NewLine + Environment.NewLine); paragraph = section.AddParagraph(); paragraph.AppendText("Consultants: "); paragraph.ApplyStyle("List"); foreach (var consultant in consultants) { paragraph = section.AddParagraph(); textRange = paragraph.AppendText(consultant.FullName); textRange.CharacterFormat.FontName = font; paragraph.ListFormat.ApplyDefBulletStyle(); } var dbg = new ApplicationDbContext(); if (type == 2) { paragraph = section.AddParagraph(); paragraph.AppendText("Interviewees: "); paragraph.ApplyStyle("List"); foreach (var interviewee in interviewees) { paragraph = section.AddParagraph(); var group = dbg.CandidateCampaigns.Where(cc => cc.IdCandidate == interviewee.IdCandidate).Select(cc => cc.Group).FirstOrDefault(); var groupname = ""; if (group != null) { groupname = group.Name; } textRange = paragraph.AppendText(interviewee.FullNameAndFunction + " - " + groupname); textRange.CharacterFormat.FontName = font; paragraph.ListFormat.ApplyDefBulletStyle(); } } // Nodes var fullnodes = db.Nodes.Where(x => x.IdQuestionnaire == idQuestionnaire).ToList(); if (fullnodes.Any()) { var root = fullnodes.FirstOrDefault(r => r.IsRoot); if (root != null) { var nodes = fullnodes.Where(n => !n.IsRoot && n.IdParentNode != root.IdNode).ToList(); var pnodes = fullnodes.FindAll(p => p.IdParentNode == root.IdNode).ToList(); foreach (var pnode in pnodes) { section = document.AddSection(); paragraph = section.AddParagraph(); paragraph.AppendText(Environment.NewLine); paragraph.AppendText(pnode.Name); paragraph.ApplyStyle("PNode"); if (db.Questions.Any(x => x.IdNode == pnode.IdNode)) { foreach (var question in questions.Where(q => q.IdNode == pnode.IdNode)) { paragraph = section.AddParagraph(); paragraph.AppendText(question.Description); paragraph.ApplyStyle("Question"); paragraph.AppendText(Environment.NewLine); if (!question.IsRelevant) { textRange.CharacterFormat.TextColor = Color.DimGray; } section.AddParagraph().AppendText(Environment.NewLine); var dbi = new ApplicationDbContext(); foreach (var answer in dba.Answers.Where(a => a.IdQuestion == question.IdQuestion && a.Interview.IdCampaign == campaign.IdCampaign && !a.Interview.Deleted)) { var intervname = dbi.Interviews.Find(answer.IdInterview).Name; paragraph = section.AddParagraph(); paragraph.AppendText("Answer from Interview " + intervname + ":"); paragraph.ApplyStyle("Answer"); if (answer != null && answer.IntervieweeAnswer != null) { if (question.AnswerType == AnswerType.Integer) { textRange = paragraph.AppendText(answer.IntervieweeAnswer + " / 5"); } else { textRange = paragraph.AppendText(answer.IntervieweeAnswer); } textRange.CharacterFormat.FontName = font; textRange.CharacterFormat.Bold = true; paragraph.AppendText(Environment.NewLine); } else { paragraph = section.AddParagraph(); textRange = paragraph.AppendText("No answer yet"); textRange.CharacterFormat.FontName = font; textRange.CharacterFormat.TextColor = Color.DarkGray; paragraph.AppendText(Environment.NewLine); } if (type == 2 && !string.IsNullOrEmpty(answer.ConsultantComment)) { if (answer.Comment != null) { paragraph = section.AddParagraph(); paragraph.AppendText("Comment: " + answer.Comment); paragraph.ApplyStyle("Comment"); paragraph.AppendText(Environment.NewLine); } paragraph = section.AddParagraph(); paragraph.AppendText("Consultant's comment: " + answer.ConsultantComment); paragraph.ApplyStyle("Comment"); paragraph.AppendText(Environment.NewLine); } } } } else { foreach (var node in nodes.Where(n => n.IdParentNode == pnode.IdNode)) { paragraph = section.AddParagraph(); paragraph.AppendText(Environment.NewLine); paragraph.AppendText(" > " + node.Name); paragraph.ApplyStyle("Node"); paragraph.AppendText(Environment.NewLine); foreach (var question in questions.Where(q => q.IdNode == node.IdNode)) { paragraph = section.AddParagraph(); paragraph.AppendText(question.Description); paragraph.ApplyStyle("Question"); paragraph.AppendText(Environment.NewLine); if (!question.IsRelevant) { textRange.CharacterFormat.TextColor = Color.DimGray; } var dbi = new ApplicationDbContext(); foreach (var answer in dba.Answers.Where(a => a.IdQuestion == question.IdQuestion && a.Interview.IdCampaign == campaign.IdCampaign && !a.Interview.Deleted)) { var intervname = dbi.Interviews.Find(answer.IdInterview).Name; paragraph = section.AddParagraph(); paragraph.AppendText("Answer from Interview " + intervname + ":"); paragraph.ApplyStyle("Answer"); if (answer.IntervieweeAnswer != null) { paragraph = section.AddParagraph(); if (question.AnswerType == AnswerType.Integer) { textRange = paragraph.AppendText(answer.IntervieweeAnswer + " / 5"); } else { textRange = paragraph.AppendText(answer.IntervieweeAnswer); } textRange.CharacterFormat.FontName = font; textRange.CharacterFormat.Bold = true; paragraph.AppendText(Environment.NewLine); } else { paragraph = section.AddParagraph(); textRange = paragraph.AppendText("No answer yet"); textRange.CharacterFormat.FontName = font; textRange.CharacterFormat.TextColor = Color.DarkGray; paragraph.AppendText(Environment.NewLine); } if (type == 2 && !string.IsNullOrEmpty(answer.ConsultantComment)) { if (answer.Comment != null) { paragraph = section.AddParagraph(); paragraph.AppendText("Comment: " + answer.Comment); paragraph.ApplyStyle("Comment"); paragraph.AppendText(Environment.NewLine); } paragraph = section.AddParagraph(); paragraph.AppendText("Consultant's comment: " + answer.ConsultantComment); paragraph.ApplyStyle("Comment"); paragraph.AppendText(Environment.NewLine); } } } } } } } } } else if (type == 3 || type == 4) { interview = db.Interviews.Find(id); var idInterviewee = db.Interviewees.Where(i => i.IdInterview == id).Select(i => i.IdCandidate).FirstOrDefault(); var idQuestionnaire = db.Interviews.Where(i => i.IdInterview == id).Include(i => i.Campaign).Select(i => i.Campaign.IdQuestionnaire).FirstOrDefault(); var questions = db.Questions.Where(q => q.IdQuestionnaire == idQuestionnaire); var interviewees = db.Interviewees.Include(cc => cc.Candidate) .Where(cc => cc.IdInterview == interview.IdInterview) .Select(x => x.Candidate); var consultant = interview.ApplicationUsers; paragraph.AppendText(Environment.NewLine + Environment.NewLine + Environment.NewLine); paragraph.AppendText("Interview: " + interview.Name); paragraph.ApplyStyle("Title"); paragraph.AppendText(Environment.NewLine + Environment.NewLine); paragraph = section.AddParagraph(); textRange = paragraph.AppendText("Date: " + interview.Date.ToShortDateString() + Environment.NewLine); textRange.CharacterFormat.FontName = font; paragraph.AppendText(Environment.NewLine + Environment.NewLine); textRange = paragraph.AppendText("Description: " + interview.Description); textRange.CharacterFormat.FontName = font; paragraph.AppendText(Environment.NewLine + Environment.NewLine); if (type == 4 && interview.Comment != null) { textRange = paragraph.AppendText("Comment: " + interview.Comment + Environment.NewLine); textRange.CharacterFormat.FontName = font; } paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left; paragraph.AppendText(Environment.NewLine + Environment.NewLine); paragraph = section.AddParagraph(); paragraph.AppendText("Consultants: "); paragraph.ApplyStyle("List"); paragraph = section.AddParagraph(); textRange = paragraph.AppendText(consultant.FullName); textRange.CharacterFormat.FontName = font; paragraph.ListFormat.ApplyDefBulletStyle(); paragraph = section.AddParagraph(); paragraph.AppendText("Interviewee(s): "); paragraph.ApplyStyle("List"); var dbc = new ApplicationDbContext(); foreach (var i in interviewees) { paragraph = section.AddParagraph(); var group = dbc.CandidateCampaigns.Where( cc => cc.IdCandidate == i.IdCandidate && cc.IdCampaign == interview.IdCampaign).Select(cc => cc.Group).FirstOrDefault(); var groupname = ""; if (group != null) { groupname = group.Name; } textRange = paragraph.AppendText(i.FullNameAndFunction + " - " + groupname); textRange.CharacterFormat.FontName = font; textRange.CharacterFormat.Bold = false; paragraph.ListFormat.ApplyDefBulletStyle(); } var fullnodes = db.Nodes.Where(x => x.IdQuestionnaire == idQuestionnaire).ToList(); if (fullnodes.Any()) { var root = fullnodes.FirstOrDefault(r => r.IsRoot); if (root != null) { var nodes = fullnodes.Where(n => !n.IsRoot && n.IdParentNode != root.IdNode).ToList(); var pnodes = fullnodes.FindAll(p => p.IdParentNode == root.IdNode).ToList(); foreach (var pnode in pnodes) { var score = db.CustomScores.FirstOrDefault(c => c.IdNode == pnode.IdNode && c.IdInterview == interview.IdInterview); var val = 0; if (score != null) { val = score.Value != null ? score.Value : 0; } section = document.AddSection(); paragraph = section.AddParagraph(); paragraph.AppendText(Environment.NewLine); paragraph.AppendText(pnode.Name + " " + val + " / 5"); paragraph.ApplyStyle("PNode"); if (db.Questions.Any(x => x.IdNode == pnode.IdNode)) { foreach (var question in questions.Where(q => q.IdNode == pnode.IdNode)) { var answer = dba.Answers.FirstOrDefault(a => a.IdQuestion == question.IdQuestion && a.IdInterview == id); paragraph = section.AddParagraph(); paragraph.AppendText(question.Description); paragraph.ApplyStyle("Question"); paragraph.AppendText(Environment.NewLine); if (answer != null && answer.IntervieweeAnswer != null) { paragraph = section.AddParagraph(); paragraph.AppendText("Answer:"); paragraph.ApplyStyle("Answer"); paragraph = section.AddParagraph(); if (question.AnswerType == AnswerType.Integer) { paragraph.AppendText(answer.IntervieweeAnswer + " / 5"); } else { paragraph.AppendText(answer.IntervieweeAnswer); } textRange.CharacterFormat.FontName = font; textRange.CharacterFormat.Bold = true; paragraph.AppendText(Environment.NewLine); if (type == 4 && !string.IsNullOrEmpty(answer.ConsultantComment)) { if (answer.Comment != null) { paragraph = section.AddParagraph(); paragraph.AppendText("Comment: " + answer.Comment); paragraph.ApplyStyle("Comment"); paragraph.AppendText(Environment.NewLine); } paragraph = section.AddParagraph(); paragraph.AppendText("Consultant's comment: " + answer.ConsultantComment); paragraph.ApplyStyle("Comment"); paragraph.AppendText(Environment.NewLine); } } else { paragraph = section.AddParagraph(); textRange = paragraph.AppendText("No answer yet"); textRange.CharacterFormat.FontName = font; textRange.CharacterFormat.TextColor = Color.DarkGray; paragraph.AppendText(Environment.NewLine); } } } else { foreach (var node in nodes.Where(n => n.IdParentNode == pnode.IdNode)) { paragraph = section.AddParagraph(); paragraph.AppendText(Environment.NewLine); paragraph.AppendText(" > " + node.Name + " " + val + " / 5"); paragraph.ApplyStyle("Node"); paragraph.AppendText(Environment.NewLine); foreach (var question in questions.Where(q => q.IdNode == node.IdNode)) { var answer = dba.Answers.FirstOrDefault(a => a.IdQuestion == question.IdQuestion && a.IdInterview == id); paragraph = section.AddParagraph(); paragraph.AppendText(question.Description); paragraph.ApplyStyle("Question"); paragraph.AppendText(Environment.NewLine); if (answer != null && answer.IntervieweeAnswer != null) { paragraph = section.AddParagraph(); paragraph.AppendText("Answer:"); paragraph.ApplyStyle("Answer"); paragraph = section.AddParagraph(); if (question.AnswerType == AnswerType.Integer) { paragraph.AppendText(answer.IntervieweeAnswer + " / 5"); } else { paragraph.AppendText(answer.IntervieweeAnswer); } textRange.CharacterFormat.FontName = font; textRange.CharacterFormat.Bold = true; paragraph.AppendText(Environment.NewLine); if (type == 4 && !string.IsNullOrEmpty(answer.ConsultantComment)) { if (answer.Comment != null) { paragraph = section.AddParagraph(); paragraph.AppendText("Comment: " + answer.Comment); paragraph.ApplyStyle("Comment"); paragraph.AppendText(Environment.NewLine); } paragraph = section.AddParagraph(); paragraph.AppendText("Consultant's comment: " + answer.ConsultantComment); paragraph.ApplyStyle("Comment"); paragraph.AppendText(Environment.NewLine); } } else { paragraph = section.AddParagraph(); textRange = paragraph.AppendText("No answer yet"); textRange.CharacterFormat.FontName = font; textRange.CharacterFormat.TextColor = Color.DarkGray; paragraph.AppendText(Environment.NewLine); } } } } } } } } switch (type) { case 1: if (!pdf) { return(document.ExportAsActionResult(DateTime.Now.ToShortDateString() + "_" + campaign.Name + "_Customer.docx", FormatType.Word2013, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } else { var converted = ConvertToPDF(document); return(converted.ExportAsActionResult(DateTime.Now.ToShortDateString() + "_" + campaign.Name + "_Customer.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } case 2: if (!pdf) { return(document.ExportAsActionResult(DateTime.Now.ToShortDateString() + "_" + campaign.Name + "_Firm.docx", FormatType.Word2013, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } else { var converted = ConvertToPDF(document); return(converted.ExportAsActionResult(DateTime.Now.ToShortDateString() + "_" + campaign.Name + "_Firm.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } case 3: if (!pdf) { return(document.ExportAsActionResult(DateTime.Now.ToShortDateString() + "_" + interview.Name + "_Customer.docx", FormatType.Word2013, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } else { var converted = ConvertToPDF(document); return(converted.ExportAsActionResult(DateTime.Now.ToShortDateString() + "_" + interview.Name + "_Customer.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } case 4: if (!pdf) { return(document.ExportAsActionResult(DateTime.Now.ToShortDateString() + "_" + interview.Name + "_Firm.docx", FormatType.Word2013, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } else { var converted = ConvertToPDF(document); return(converted.ExportAsActionResult(DateTime.Now.ToShortDateString() + "_" + interview.Name + "_Firm.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } } return(document.ExportAsActionResult("Report.docx", FormatType.Word2013, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); }
/// <summary> /// Inserts and updates the Table of Contents (TOC) in a Word document. /// </summary> private void Button_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) { //Creates a new Word document. using WordDocument document = new(); //Adds one section and paragraph. document.EnsureMinimal(); document.LastSection.PageSetup.Margins.All = 72; WParagraph para = document.LastParagraph; IWTextRange textRange = para.AppendText("Essential DocIO - Table of Contents"); textRange.CharacterFormat.Bold = true; textRange.CharacterFormat.FontSize = 14; para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; para.ParagraphFormat.BeforeSpacing = 12f; para.ParagraphFormat.AfterSpacing = 3f; para = document.LastSection.AddParagraph() as WParagraph; para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; para.ParagraphFormat.BeforeSpacing = 12f; para.ParagraphFormat.AfterSpacing = 3f; if (!checkBox.IsChecked.Value) { textRange = para.AppendText("Select TOC and press F9 to update the Table of Contents"); textRange.CharacterFormat.HighlightColor = Syncfusion.Drawing.Color.Yellow; textRange.CharacterFormat.Bold = true; textRange.CharacterFormat.FontSize = 14; } para = document.LastSection.AddParagraph() as WParagraph; //Inserts TOC. Syncfusion.DocIO.DLS.TableOfContent toc = para.AppendTOC(1, 3); para.ParagraphFormat.BeforeSpacing = 12f; para.ParagraphFormat.AfterSpacing = 3f; //Applies built-in paragraph formatting. WSection section = document.LastSection; #region Default Styles WParagraph newPara = section.AddParagraph() as WParagraph; newPara = section.AddParagraph() as WParagraph; newPara.AppendBreak(BreakType.PageBreak); WTextRange text = newPara.AppendText("Document with Default styles") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading1); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading1 of built in style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can only insert TOC field in a word document. It can not refresh or create TOC field. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Section1") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading2); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph1") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph2") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph."); section.AddParagraph(); section = document.AddSection() as WSection; section.PageSetup.Margins.All = 72; section.BreakCode = SectionBreakCode.NewPage; newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Section2") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading2); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph1") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph2") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph."); #endregion //Enables a flag to show page numbers in table of contents. toc.IncludePageNumbers = true; //Enables a flag to show page numbers as right aligned. toc.RightAlignPageNumbers = true; //Enables a flag to use hyperlinks for the levels. toc.UseHyperlinks = true; //Sets the starting heading level of the table of contents. toc.LowerHeadingLevel = 1; //Sets the ending heading level of the table of contents. toc.UpperHeadingLevel = 3; //Enables a flag to use outline levels. toc.UseOutlineLevels = true; //Updates the table of contents. if (checkBox.IsChecked.Value) { document.UpdateTableOfContents(); } #region Document SaveOption using MemoryStream ms = new(); string filename = string.Empty; //Saves as .docx format. if (worddocx.IsChecked == true) { filename = "Table of Contents.docx"; //Saves the Word document to the memory stream. document.Save(ms, FormatType.Docx); } //Saves as .doc format. else if (worddoc.IsChecked == true) { filename = "Table of Contents.doc"; //Saves the Word document to the memory stream. document.Save(ms, FormatType.Doc); } //Saves as .pdf format. else if (pdf.IsChecked == true) { filename = "Table of Contents.pdf"; //Creates a new DocIORenderer instance. using DocIORenderer renderer = new(); //Converts Word document into PDF. using PdfDocument pdfDoc = renderer.ConvertToPDF(document); //Saves the PDF document to the memory stream. pdfDoc.Save(ms); } ms.Position = 0; //Saves the memory stream as file. SaveHelper.SaveAndLaunch(filename, ms); #endregion Document SaveOption }
/// <summary> /// Generate update table of contents functionality of Essential DocIO /// </summary> /// <returns>Return the created Word document as stream</returns> public MemoryStream TableofContent(string documentType, string button, bool UpdateTOC) { WordDocument doc = new WordDocument(); doc.EnsureMinimal(); WParagraph para = doc.LastParagraph; para.AppendText("Essential DocIO - Table of Contents"); para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; para.ApplyStyle(BuiltinStyle.Heading4); para = doc.LastSection.AddParagraph() as WParagraph; para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; para.ApplyStyle(BuiltinStyle.Heading4); if (!UpdateTOC) { para.AppendText("Select TOC and press F9 to update the Table of Contents").CharacterFormat.HighlightColor = Syncfusion.Drawing.Color.Yellow; } para = doc.LastSection.AddParagraph() as WParagraph; //Insert TOC TableOfContent toc = para.AppendTOC(1, 3); para.ApplyStyle(BuiltinStyle.Heading4); //Apply built-in paragraph formatting WSection section = doc.LastSection; #region Default Styles WParagraph newPara = section.AddParagraph() as WParagraph; newPara = section.AddParagraph() as WParagraph; newPara.AppendBreak(BreakType.PageBreak); WTextRange text = newPara.AppendText("Document with Default styles") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading1); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading1 of built in style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can only insert TOC field in a word document. It can not refresh or create TOC field. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Section1") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading2); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph1") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph2") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph."); section.AddParagraph(); section = doc.AddSection() as WSection; section.BreakCode = SectionBreakCode.NewPage; newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Section2") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading2); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph1") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph2") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph."); #endregion toc.IncludePageNumbers = true; toc.RightAlignPageNumbers = true; toc.UseHyperlinks = true; toc.LowerHeadingLevel = 1; toc.UpperHeadingLevel = 3; toc.UseOutlineLevels = true; //Updates the table of contents. if (UpdateTOC) { doc.UpdateTableOfContents(); } FormatType formatType = FormatType.Docx; //Save as .doc format if (documentType == "WordDoc") { formatType = FormatType.Doc; } //Save as .xml format else if (documentType == "WordML") { formatType = FormatType.WordML; } //Save the document as a stream and retrun the stream using (MemoryStream stream = new MemoryStream()) { //Save the created Word document to MemoryStream doc.Save(stream, formatType); doc.Close(); stream.Position = 0; return(stream); } }
public ActionResult TableofContent(string Group1, string UpdateTOC) { if (Group1 == null) { return(View()); } WordDocument doc = new WordDocument(); doc.EnsureMinimal(); WParagraph para = doc.LastParagraph; para.AppendText("Essential DocIO - Table of Contents"); para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; para.ApplyStyle(BuiltinStyle.Heading4); para = doc.LastSection.AddParagraph() as WParagraph; para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; para.ApplyStyle(BuiltinStyle.Heading4); if (UpdateTOC != "Update") { para.AppendText("Select TOC and press F9 to update the Table of Contents").CharacterFormat.HighlightColor = Color.Yellow; } para = doc.LastSection.AddParagraph() as WParagraph; //Insert TOC TableOfContent toc = para.AppendTOC(1, 3); para.ApplyStyle(BuiltinStyle.Heading4); //Apply built-in paragraph formatting WSection section = doc.LastSection; #region Default Styles WParagraph newPara = section.AddParagraph() as WParagraph; newPara = section.AddParagraph() as WParagraph; newPara.AppendBreak(BreakType.PageBreak); WTextRange text = newPara.AppendText("Document with Default styles") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading1); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading1 of built in style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can only insert TOC field in a word document. It can not refresh or create TOC field. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Section1") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading2); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph1") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph2") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph."); section.AddParagraph(); section = doc.AddSection() as WSection; section.BreakCode = SectionBreakCode.NewPage; newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Section2") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading2); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph1") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text."); section.AddParagraph(); newPara = section.AddParagraph() as WParagraph; text = newPara.AppendText("Paragraph2") as WTextRange; newPara.ApplyStyle(BuiltinStyle.Heading3); newPara = section.AddParagraph() as WParagraph; newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph."); #endregion toc.IncludePageNumbers = true; toc.RightAlignPageNumbers = true; toc.UseHyperlinks = true; toc.LowerHeadingLevel = 1; toc.UpperHeadingLevel = 3; toc.UseOutlineLevels = true; //Updates the table of contents. if (UpdateTOC == "Update") { doc.UpdateTableOfContents(); } //Save as .doc format if (Group1 == "WordDoc") { return(doc.ExportAsActionResult("Sample.doc", FormatType.Doc, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .docx format else if (Group1 == "WordDocx") { return(doc.ExportAsActionResult("Sample.docx", FormatType.Docx, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } // Save as WordML(.xml) format else if (Group1 == "WordML") { return(doc.ExportAsActionResult("Sample.xml", FormatType.WordML, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .pdf format else if (Group1 == "Pdf") { DocToPDFConverter converter = new DocToPDFConverter(); PdfDocument pdfDoc = converter.ConvertToPDF(doc); return(pdfDoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } return(View()); }
public ActionResult FormatTable(string Group1) { if (Group1 == null) { return(View()); } // Create a new document. WordDocument document = new WordDocument(); // Adding a new section to the document. IWSection section = document.AddSection(); section.PageSetup.DifferentFirstPage = true; IWTextRange textRange; IWParagraph paragraph = section.AddParagraph(); // -------------------------------------------- // Table in page header // -------------------------------------------- IWParagraph hParagraph = new WParagraph(document); hParagraph.AppendText("Header text\r\n").CharacterFormat.FontSize = 14; section.HeadersFooters.FirstPageHeader.Paragraphs.Add(hParagraph); IWTable hTable = document.LastSection.HeadersFooters.FirstPageHeader.AddTable(); hTable.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; hTable.TableFormat.Paddings.All = 5.4f; hTable.ResetCells(2, 2); hTable[0, 0].AddParagraph().AppendText("1"); hTable[0, 1].AddParagraph().AppendText("2"); hTable[1, 0].AddParagraph().AppendText("3"); hTable[1, 1].AddParagraph().AppendText("4"); // -------------------------------------------- // Tiny table // -------------------------------------------- paragraph = section.AddParagraph(); paragraph.AppendText("Tiny table\r\n").CharacterFormat.FontSize = 14; paragraph = section.AddParagraph(); WTextBody textBody = section.Body; IWTable table = textBody.AddTable(); table.ResetCells(2, 2); table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; table.TableFormat.Paddings.All = 5.4f; WTableRow row_0 = table.Rows[0]; row_0.Cells[0].AddParagraph().AppendText("A"); row_0.Cells[0].AddParagraph().AppendText("AA"); row_0.Cells[0].AddParagraph().AppendText("AAA"); WTableRow row_1 = table.Rows[1]; row_1.Cells[1].AddParagraph().AppendText("B"); row_1.Cells[1].AddParagraph().AppendText("BB\r\nBBB"); row_1.Cells[1].AddParagraph().AppendText("BBB"); textBody.AddParagraph().AppendText("Text after table...").CharacterFormat.FontSize = 14; // -------------------------------------------- // Table with different formatting // -------------------------------------------- section.AddParagraph(); paragraph = section.AddParagraph(); paragraph.AppendText("Table with different formatting\r\n").CharacterFormat.FontSize = 14; paragraph = section.AddParagraph(); textBody = section.Body; table = textBody.AddTable(); table.ResetCells(3, 3); /* ------- First Row -------- */ WTableRow row0 = table.Rows[0]; paragraph = (IWParagraph)row0.Cells[0].AddParagraph(); textRange = paragraph.AppendText("1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; textRange.CharacterFormat.FontName = "Arial"; textRange.CharacterFormat.Bold = true; textRange.CharacterFormat.FontSize = 14f; row0.Cells[0].CellFormat.Borders.LineWidth = 2f; row0.Cells[0].CellFormat.Borders.Color = Color.Magenta; paragraph = (IWParagraph)row0.Cells[1].AddParagraph(); textRange = paragraph.AppendText("2"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Right; textRange.CharacterFormat.Emboss = true; textRange.CharacterFormat.FontSize = 15f; row0.Cells[1].CellFormat.Borders.LineWidth = 1.3f; row0.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DoubleWave; paragraph = (IWParagraph)row0.Cells[2].AddParagraph(); textRange = paragraph.AppendText("3"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; textRange.CharacterFormat.Engrave = true; textRange.CharacterFormat.FontSize = 15f; row0.Cells[2].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Emboss3D; /* ------- Second Row -------- */ WTableRow row1 = table.Rows[1]; paragraph = (IWParagraph)row1.Cells[0].AddParagraph(); textRange = paragraph.AppendText("4"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; textRange.CharacterFormat.SmallCaps = true; textRange.CharacterFormat.FontName = "Comic Sans MS"; textRange.CharacterFormat.FontSize = 16; row1.Cells[0].CellFormat.Borders.LineWidth = 2f; row1.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DashDotStroker; paragraph = (IWParagraph)row1.Cells[1].AddParagraph(); textRange = paragraph.AppendText("5"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; textRange.CharacterFormat.FontName = "Times New Roman"; textRange.CharacterFormat.Shadow = true; textRange.CharacterFormat.TextBackgroundColor = Color.Orange; textRange.CharacterFormat.FontSize = 15f; row1.Cells[1].CellFormat.Borders.LineWidth = 2f; row1.Cells[1].CellFormat.Borders.Color = Color.Brown; paragraph = (IWParagraph)row1.Cells[2].AddParagraph(); textRange = paragraph.AppendText("6"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; textRange.CharacterFormat.Bold = true; textRange.CharacterFormat.FontSize = 14f; row1.Cells[2].CellFormat.BackColor = Color.FromArgb(51, 51, 101); row1.Cells[2].CellFormat.VerticalAlignment = VerticalAlignment.Middle; /* ------- Third Row -------- */ WTableRow row2 = table.Rows[2]; paragraph = (IWParagraph)row2.Cells[0].AddParagraph(); textRange = paragraph.AppendText("7"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Right; textRange.CharacterFormat.FontSize = 13f; row2.Cells[0].CellFormat.Borders.LineWidth = 1.5f; row2.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DashLargeGap; paragraph = (IWParagraph)row2.Cells[1].AddParagraph(); textRange = paragraph.AppendText("8"); textRange.CharacterFormat.TextColor = Color.Blue; textRange.CharacterFormat.FontSize = 16f; row2.Cells[1].CellFormat.Borders.LineWidth = 3f; row2.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Wave; paragraph = (IWParagraph)row2.Cells[2].AddParagraph(); textRange = paragraph.AppendText("9"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Right; row2.Cells[2].CellFormat.Borders.LineWidth = 2f; row2.Cells[2].CellFormat.Borders.Color = Color.Cyan; row2.Cells[2].CellFormat.Borders.Shadow = true; row2.Cells[2].CellFormat.Borders.Space = 20; // -------------------------------------------- // Table Cell Merging. // -------------------------------------------- section.AddParagraph(); paragraph = section.AddParagraph(); paragraph.AppendText("Table Cell Merging...").CharacterFormat.FontSize = 14; section.AddParagraph(); paragraph = section.AddParagraph(); textBody = section.Body; // Adding a new Table to the textbody. table = textBody.AddTable(); RowFormat format = new RowFormat(); format.Paddings.All = 5; format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Dot; format.Borders.LineWidth = 2; // Inserting rows to the table. table.ResetCells(6, 6, format, 80); // Table formatting with cell merging. table.Rows[0].Cells[0].CellFormat.HorizontalMerge = CellMerge.Start; table.Rows[0].Cells[1].CellFormat.HorizontalMerge = CellMerge.Continue; table.Rows[0].Cells[0].CellFormat.VerticalAlignment = VerticalAlignment.Middle; table.Rows[0].Cells[0].CellFormat.BackColor = Color.FromArgb(218, 230, 246); IWParagraph par = table.Rows[0].Cells[0].AddParagraph(); par.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; par.AppendText("Horizontal Merge").CharacterFormat.Bold = true; table.Rows[2].Cells[3].CellFormat.VerticalMerge = CellMerge.Start; table.Rows[3].Cells[3].CellFormat.VerticalMerge = CellMerge.Continue; table.Rows[2].Cells[3].CellFormat.VerticalAlignment = VerticalAlignment.Middle; par = table.Rows[2].Cells[3].AddParagraph(); table.Rows[2].Cells[3].CellFormat.BackColor = Color.FromArgb(252, 172, 85); par.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; par.AppendText("Vertical Merge").CharacterFormat.Bold = true; #region Table Cell Spacing. // -------------------------------------------- // Table Cell Spacing. // -------------------------------------------- section.AddParagraph(); paragraph = section.AddParagraph(); paragraph.AppendText("Table Cell spacing...").CharacterFormat.FontSize = 14; section.AddParagraph(); paragraph = section.AddParagraph(); textBody = section.Body; // Adding a new Table to the textbody. table = textBody.AddTable(); table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; table.TableFormat.Paddings.All = 5.4f; format = new RowFormat(); format.Paddings.All = 5; format.CellSpacing = 2; format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DotDash; format.IsBreakAcrossPages = true; table.ResetCells(25, 5, format, 90); IWTextRange text; table.Rows[0].IsHeader = true; for (int i = 0; i < table.Rows[0].Cells.Count; i++) { paragraph = table[0, i].AddParagraph() as WParagraph; paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText(string.Format("Header {0}", i + 1)); text.CharacterFormat.Font = new Font("Bitstream Vera Serif", 10); text.CharacterFormat.Bold = true; text.CharacterFormat.TextColor = Color.FromArgb(0, 21, 84); table[0, i].CellFormat.BackColor = Color.FromArgb(203, 211, 226); } for (int i = 1; i < table.Rows.Count; i++) { for (int j = 0; j < 5; j++) { paragraph = table[i, j].AddParagraph() as WParagraph; paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText(string.Format("Cell {0} , {1}", i, j + 1)); text.CharacterFormat.TextColor = Color.FromArgb(242, 151, 50); text.CharacterFormat.Bold = true; if (i % 2 != 1) { table[i, j].CellFormat.BackColor = Color.FromArgb(231, 235, 245); } else { table[i, j].CellFormat.BackColor = Color.FromArgb(246, 249, 255); } } } #endregion Table Cell Spacing. #region Nested Table // -------------------------------------------- // Nested Table. // -------------------------------------------- section.AddParagraph(); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.PageBreakBefore = true; paragraph.AppendText("Nested Table...").CharacterFormat.FontSize = 14; section.AddParagraph(); paragraph = section.AddParagraph(); textBody = section.Body; // Adding a new Table to the textbody. table = textBody.AddTable(); format = new RowFormat(); format.Paddings.All = 5; format.CellSpacing = 2.5f; format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DotDash; table.ResetCells(5, 3, format, 100); for (int i = 0; i < table.Rows[0].Cells.Count; i++) { paragraph = table[0, i].AddParagraph() as WParagraph; paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText(string.Format("Header {0}", i + 1)); text.CharacterFormat.Font = new Font("Bitstream Vera Serif", 10); text.CharacterFormat.Bold = true; text.CharacterFormat.TextColor = Color.FromArgb(0, 21, 84); table[0, i].CellFormat.BackColor = Color.FromArgb(242, 151, 50); } table[0, 2].Width = 200; for (int i = 1; i < table.Rows.Count; i++) { for (int j = 0; j < 3; j++) { paragraph = table[i, j].AddParagraph() as WParagraph; paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; if ((i == 2) && (j == 2)) { text = paragraph.AppendText("Nested Table"); } else { text = paragraph.AppendText(string.Format("Cell {0} , {1}", i, j + 1)); } if ((j == 2)) { table[i, j].Width = 200; } text.CharacterFormat.TextColor = Color.FromArgb(242, 151, 50); text.CharacterFormat.Bold = true; } } // Adding a nested Table. IWTable nestTable = table[2, 2].AddTable(); format = new RowFormat(); format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DotDash; format.HorizontalAlignment = RowAlignment.Center; nestTable.ResetCells(3, 3, format, 45); for (int i = 0; i < nestTable.Rows.Count; i++) { for (int j = 0; j < 3; j++) { paragraph = nestTable[i, j].AddParagraph() as WParagraph; paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; nestTable[i, j].CellFormat.BackColor = Color.FromArgb(231, 235, 245); text = paragraph.AppendText(string.Format("Cell {0} , {1}", i, j + 1)); text.CharacterFormat.TextColor = Color.Black; text.CharacterFormat.Bold = true; } } #endregion Nested Table #region Table with Images string dataPath = ResolveApplicationDataPath("", "Content\\DocIO"); //Add a new section to the document. section = document.AddSection(); //Add paragraph to the section. paragraph = section.AddParagraph(); //Writing text. textRange = paragraph.AppendText("Table with Images"); textRange.CharacterFormat.FontSize = 13f; textRange.CharacterFormat.TextColor = Color.DarkBlue; textRange.CharacterFormat.Bold = true; //Add paragraph to the section. section.AddParagraph(); paragraph = section.AddParagraph(); text = null; //Adding a new Table to the paragraph. table = section.Body.AddTable(); table.ResetCells(1, 3); //Adding rows to the table. WTableRow row = table.Rows[0]; //Set heading row height row.Height = 25f; //set heading values to the Table. for (int i = 0; i < 3; i++) { //Add paragraph for writing Text to the cells. paragraph = (IWParagraph)row.Cells[i].AddParagraph(); //Set Horizontal Alignment as Center. paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; //Writing Row Heading switch (i) { case 0: text = paragraph.AppendText("SNO"); row.Cells[i].Width = 50f; break; case 1: text = paragraph.AppendText("Drinks"); break; case 2: text = paragraph.AppendText("Showcase Image"); row.Cells[i].Width = 200f; break; } //Set row Heading formatting text.CharacterFormat.Bold = true; text.CharacterFormat.FontName = "Cambria"; text.CharacterFormat.FontSize = 11f; text.CharacterFormat.TextColor = Color.White; //Set row cells formatting row.Cells[i].CellFormat.VerticalAlignment = VerticalAlignment.Middle; row.Cells[i].CellFormat.BackColor = Color.FromArgb(157, 161, 190); row.Cells[i].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; } int sno = 1; //Writing Sno, Product name and Product Images to the Table. row1 = table.AddRow(false); //Writing SNO to the table with formatting text. paragraph = (IWParagraph)row1.Cells[0].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText(sno.ToString()); text.CharacterFormat.Bold = true; text.CharacterFormat.FontSize = 10f; row1.Cells[0].CellFormat.VerticalAlignment = VerticalAlignment.Middle; row1.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[0].CellFormat.BackColor = Color.FromArgb(217, 223, 239); //Writing Product Name to the table with Formatting. paragraph = (IWParagraph)row1.Cells[1].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText("Apple Juice"); text.CharacterFormat.Bold = true; text.CharacterFormat.FontSize = 10f; text.CharacterFormat.TextColor = Color.FromArgb(50, 65, 124); row1.Cells[1].CellFormat.VerticalAlignment = VerticalAlignment.Middle; row1.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[1].CellFormat.BackColor = Color.FromArgb(217, 223, 239); //Writing Product Images to the Table. paragraph = (IWParagraph)row1.Cells[2].AddParagraph(); paragraph.AppendPicture(Image.FromFile(dataPath + "Apple Juice.png")); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; row1.Cells[2].CellFormat.VerticalAlignment = VerticalAlignment.Middle; row1.Cells[2].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[2].CellFormat.BackColor = Color.FromArgb(217, 223, 239); sno++; row1 = table.AddRow(false); //Writing SNO to the table with formatting text. paragraph = (IWParagraph)row1.Cells[0].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText(sno.ToString()); text.CharacterFormat.Bold = true; text.CharacterFormat.FontSize = 10f; row1.Cells[0].CellFormat.VerticalAlignment = VerticalAlignment.Middle; row1.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[0].CellFormat.BackColor = Color.FromArgb(217, 223, 239); //Writing Product Name to the table with Formatting. paragraph = (IWParagraph)row1.Cells[1].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText("Grape Juice"); text.CharacterFormat.Bold = true; text.CharacterFormat.FontSize = 10f; text.CharacterFormat.TextColor = Color.FromArgb(50, 65, 124); row1.Cells[1].CellFormat.VerticalAlignment = VerticalAlignment.Middle; row1.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[1].CellFormat.BackColor = Color.FromArgb(217, 223, 239); //Writing Product Images to the Table. paragraph = (IWParagraph)row1.Cells[2].AddParagraph(); paragraph.AppendPicture(Image.FromFile(dataPath + "Grape Juice.png")); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; row1.Cells[2].CellFormat.VerticalAlignment = VerticalAlignment.Middle; row1.Cells[2].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[2].CellFormat.BackColor = Color.FromArgb(217, 223, 239); sno++; row1 = table.AddRow(false); //Writing SNO to the table with formatting text. paragraph = (IWParagraph)row1.Cells[0].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText(sno.ToString()); text.CharacterFormat.Bold = true; text.CharacterFormat.FontSize = 10f; row1.Cells[0].CellFormat.VerticalAlignment = VerticalAlignment.Middle; row1.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[0].CellFormat.BackColor = Color.FromArgb(217, 223, 239); //Writing Product Name to the table with Formatting. paragraph = (IWParagraph)row1.Cells[1].AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; text = paragraph.AppendText("Hot Soup"); text.CharacterFormat.Bold = true; text.CharacterFormat.FontSize = 10f; text.CharacterFormat.TextColor = Color.FromArgb(50, 65, 124); row1.Cells[1].CellFormat.VerticalAlignment = VerticalAlignment.Middle; row1.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[1].CellFormat.BackColor = Color.FromArgb(217, 223, 239); //Writing Product Images to the Table. paragraph = (IWParagraph)row1.Cells[2].AddParagraph(); paragraph.AppendPicture(Image.FromFile(dataPath + "Hot Soup.png")); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; row1.Cells[2].CellFormat.VerticalAlignment = VerticalAlignment.Middle; row1.Cells[2].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single; row1.Cells[2].CellFormat.BackColor = Color.FromArgb(217, 223, 239); sno++; #endregion Table with Images //Save as .doc format if (Group1 == "WordDoc") { return(document.ExportAsActionResult("Sample.doc", FormatType.Doc, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .docx format else if (Group1 == "WordDocx") { return(document.ExportAsActionResult("Sample.docx", FormatType.Docx, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } // Save as WordML(.xml) format else if (Group1 == "WordML") { return(document.ExportAsActionResult("Sample.xml", FormatType.WordML, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .pdf format else if (Group1 == "Pdf") { DocToPDFConverter converter = new DocToPDFConverter(); PdfDocument pdfDoc = converter.ConvertToPDF(document); return(pdfDoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } return(View()); }
private void ApplyBuiltInStyle() { // Creating a new document. using (WordDocument document = new WordDocument()) { #region Create a Word document //Add new section to the Word document WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; //Add new paragraph WParagraph para = section.AddParagraph() as WParagraph; //Add multi-column to the section section.AddColumn(100, 100); section.AddColumn(100, 100); //Make the section columns are qual section.MakeColumnsEqual(); #region Built-in styles #region List Style //Apply List Style para.AppendText("This para is written with style List").CharacterFormat.UnderlineStyle = Syncfusion.Drawing.UnderlineStyle.Double; para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.List); para.AppendText("Google Chrome\n"); para.AppendText("Mozilla Firefox\n"); para.AppendText("Internet Explorer"); //Apply List5 style para = section.AddParagraph() as WParagraph; para.AppendText("\nThis para is written with style List5").CharacterFormat.UnderlineStyle = Syncfusion.Drawing.UnderlineStyle.Double; para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.List5); para.AppendText("Google Chrome\n"); para.AppendText("Mozilla Firefox\n"); para.AppendText("Internet Explorer"); #endregion #region ListNumber Style //List Number style para = section.AddParagraph() as WParagraph; para.AppendText("\nThis para is written with style ListNumber").CharacterFormat.UnderlineStyle = Syncfusion.Drawing.UnderlineStyle.Double; para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.ListNumber); para.AppendText("Google Chrome\n"); para.AppendText("Mozilla Firefox\n"); para.AppendText("Internet Explorer"); //List Number5 style para = section.AddParagraph() as WParagraph; para.AppendText("\nThis para is written with style ListNumber5").CharacterFormat.UnderlineStyle = Syncfusion.Drawing.UnderlineStyle.Double; para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.ListNumber5); para.AppendText("Google Chrome\n"); para.AppendText("Mozilla Firefox\n"); para.AppendText("Internet Explorer"); #endregion #region TOA Heading Style //Apply TOA Heading style para = section.AddParagraph() as WParagraph; para.AppendText("\nThis para is written with style TOA Heading").CharacterFormat.UnderlineStyle = Syncfusion.Drawing.UnderlineStyle.Double; para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.ToaHeading); para.AppendText("Google Chrome\n"); para.AppendText("Mozilla Firefox\n"); para.AppendText("Internet Explorer"); #endregion //Add new paragraph para = section.AddParagraph() as WParagraph; //Set Section break section.BreakCode = SectionBreakCode.NewColumn; #region ListBullet Style //ListBullet para = section.AddParagraph() as WParagraph; para.AppendText("\nThis para is written with style ListBullet").CharacterFormat.UnderlineStyle = Syncfusion.Drawing.UnderlineStyle.Double; para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.ListBullet); para.AppendText("Google Chrome\n"); para.AppendText("Mozilla Firefox\n"); para.AppendText("Internet Explorer"); //ListBullet5 para = section.AddParagraph() as WParagraph; para.AppendText("\nThis para is written with style ListBullet5").CharacterFormat.UnderlineStyle = Syncfusion.Drawing.UnderlineStyle.Double; para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.ListBullet5); para.AppendText("Google Chrome\n"); para.AppendText("Mozilla Firefox\n"); para.AppendText("Internet Explorer"); #endregion #region List Continue Style //Apply ListContinue Style para = section.AddParagraph() as WParagraph; para.AppendText("\nThis para is written with style ListContinue").CharacterFormat.UnderlineStyle = Syncfusion.Drawing.UnderlineStyle.Double; para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.ListContinue); para.AppendText("Google Chrome\n"); para.AppendText("Mozilla Firefox\n"); para.AppendText("Internet Explorer"); //Apply ListContinue5 style para = section.AddParagraph() as WParagraph; para.AppendText("\nThis para is written with style ListContinue5").CharacterFormat.UnderlineStyle = Syncfusion.Drawing.UnderlineStyle.Double; para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.ListContinue5); para.AppendText("Google Chrome\n"); para.AppendText("Mozilla Firefox\n"); para.AppendText("Internet Explorer"); #endregion #region HTMLSample Style //Apply HtmlSample style para = section.AddParagraph() as WParagraph; para.AppendText("\nThis para is written with style HtmlSample").CharacterFormat.UnderlineStyle = Syncfusion.Drawing.UnderlineStyle.Double; para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.HtmlSample); para.AppendText("Google Chrome\n"); para.AppendText("Mozilla Firefox\n"); para.AppendText("Internet Explorer"); #endregion //Add new section to the document section = document.AddSection() as WSection; //Set Section break section.BreakCode = SectionBreakCode.NoBreak; #region Document Map Style //Apply Docuemnt Map Style para = section.AddParagraph() as WParagraph; para.AppendText("This para is written with style DocumentMap\n").CharacterFormat.UnderlineStyle = Syncfusion.Drawing.UnderlineStyle.Double; para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.DocumentMap); IWTextRange textrange = para.AppendText("Google Chrome\n"); textrange.CharacterFormat.TextBackgroundColor = Syncfusion.Drawing.Color.Red; textrange = para.AppendText("Mozilla Firefox\n"); textrange.CharacterFormat.TextBackgroundColor = Syncfusion.Drawing.Color.Red; textrange = para.AppendText("Internet Explorer"); textrange.CharacterFormat.TextBackgroundColor = Syncfusion.Drawing.Color.Red; #endregion #region Heading Styles //Apply Heading Styles para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.Heading1); para.AppendText("Hello World. This para is written with style " + para.StyleName.ToString()); para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.Heading2); para.AppendText("Hello World. This para is written with style " + para.StyleName.ToString()); para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.Heading3); para.AppendText("Hello World. This para is written with style " + para.StyleName.ToString()); para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.Heading4); para.AppendText("Hello World. This para is written with style " + para.StyleName.ToString()); para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.Heading5); para.AppendText("Hello World. This para is written with style " + para.StyleName.ToString()); para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.Heading6); para.AppendText("Hello World. This para is written with style " + para.StyleName.ToString()); para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.Heading7); para.AppendText("Hello World. This para is written with style " + para.StyleName.ToString()); para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.Heading8); para.AppendText("Hello World. This para is written with style " + para.StyleName.ToString()); para = section.AddParagraph() as WParagraph; para.ApplyStyle(BuiltinStyle.Heading9); para.AppendText("Hello World. This para is written with style " + para.StyleName.ToString()); #endregion #endregion Built-in styles #endregion #region Saving Document //Save the word document to the stream. MemoryStream stream = new MemoryStream(); document.Save(stream, FormatType.Docx); //Save file in the disk based on specfic OS if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows) { Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("WordDocument_BuiltInStyles.docx", "application/msword", stream); } else { Xamarin.Forms.DependencyService.Get <ISave>().Save("WordDocument_BuiltInStyles.docx", "application/msword", stream); } #endregion } }