void CheckParagraph() { if (m_paragraph == null) { m_paragraph = m_section.AddParagraph(); } }
/// <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
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(); }
/// <summary> /// Creates paragraph in the Word document. /// </summary> /// <param name="section">The section to add paragraphs.</param> private void CreateParagraph(WSection section) { #region Inserting Header IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph(); //Gets the image. string resourcePath = "syncfusion.dociodemos.winui.Assets.DocIO.HeaderImage.png"; Stream imageStream = assembly.GetManifestResourceStream(resourcePath); //Appends image to the paragraph. WPicture picture = paragraph.AppendPicture(imageStream) as WPicture; picture.WidthScale = 173f; picture.HeightScale = 149f; #endregion #region Inserting Footer paragraph = section.HeadersFooters.Footer.AddParagraph(); paragraph.ParagraphFormat.Tabs.AddTab(523f, TabJustification.Right, TabLeader.NoLeader); //Adds page and Number of pages field to the document. paragraph.AppendText("\tPage "); paragraph.AppendField("Page", FieldType.FieldPage); paragraph.AppendText(" of "); paragraph.AppendField("NumPages", FieldType.FieldNumPages); #endregion //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; WTextRange textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 18f; textRange.CharacterFormat.FontName = "Calibri"; //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("Adventure Works Cycles, the fictitious company on which the Adventure Works sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Bothell, Washington with 290 employees, several regional sales teams are located throughout their market base.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("In 2000, Adventure Works Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the Adventure Works Cycles product line. These subcomponents are shipped to the Bothell location for final product assembly. In 2001, Importadores Neptuno, became the sole manufacturer and distributor of the touring bicycle product group.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; textRange = paragraph.AppendText("Product Overview") as WTextRange; textRange.CharacterFormat.FontSize = 16f; textRange.CharacterFormat.FontName = "Calibri"; }
public async Task GenerateReports() { Assembly assembly = typeof(CreateInvoicePageViewModel).GetTypeInfo().Assembly; WordDocument document = new WordDocument(); WSection section = document.AddSection() as WSection; IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph(); paragraph.AppendText("Testing paragraph header"); paragraph = section.AddParagraph(); paragraph.AppendText("Hi again."); MemoryStream stream = new MemoryStream(); document.Save(stream, FormatType.Word2010); document.Close(); if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows) { await DependencyService.Get <ISaveWindowsPhone>().Save("SQReportTest.docx", "application/msword", stream); } else { DependencyService.Get <ISave>().Save("SQReportTest.docx", "application/msword", stream); } }
private void exportarWord() { using (MemoryStream ms = new MemoryStream()) { WordDocument document = new WordDocument(); WSection section = document.AddSection() as WSection; section.PageSetup.Margins.All = 72; IWParagraph paragraph = section.AddParagraph(); paragraph.ApplyStyle("Normal"); paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center; WTextRange textRange = paragraph.AppendText(tituloReporte) as WTextRange; textRange.CharacterFormat.FontSize = 20f; textRange.CharacterFormat.FontName = "Calibri"; textRange.CharacterFormat.TextColor = Syncfusion.Drawing.Color.Blue; IWTable table = section.AddTable(); int numeroCabeceras = cabecalho.Length; int numeroFilas = lista.Length; table.ResetCells(numeroFilas + 1, numeroCabeceras); for (int i = 0; i < numeroCabeceras; i++) { table[0, i].AddParagraph().AppendText(cabecalho[i]); } int fila = 1; int col = 0; foreach (object item in lista) { col = 0; foreach (string prop in nomesPropriedadesCabecalho) { table[fila, col].AddParagraph().AppendText( item.GetType().GetProperty(prop).GetValue(item).ToString() ); col++; } fila++; } document.Save(ms, FormatType.Docx); byte[] buffer = ms.ToArray(); string base64 = Convert.ToBase64String(buffer); word = "data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64," + base64; } }
public byte[] ExportarWordDatos <T>(string[] nombreProp, List <T> lista) { using (MemoryStream ms = new MemoryStream()) { WordDocument word = new WordDocument(); WSection wSection = word.AddSection() as WSection; wSection.PageSetup.Margins.All = 72; wSection.PageSetup.PageSize = new Syncfusion.Drawing.SizeF(612, 792); IWParagraph paragraph = wSection.AddParagraph(); paragraph.ApplyStyle("Normal"); paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center; WTextRange textRange = paragraph.AppendText("Reporte en Word") as WTextRange; textRange.CharacterFormat.FontSize = 20f; textRange.CharacterFormat.FontName = "Calibri"; textRange.CharacterFormat.TextColor = Syncfusion.Drawing.Color.Blue; if (nombreProp != null && nombreProp.Length > 0)//Validar checks nulos { //Se crea el documento IWTable table = wSection.AddTable(); int numeroColumnas = nombreProp.Length; int nFilas = lista.Count; table.ResetCells(nFilas + 1, numeroColumnas); //Obtener cabeceras de las propiedades de la clase Dictionary <string, string> diccionario = cm.TypeDescriptor .GetProperties(typeof(T)) .Cast <cm.PropertyDescriptor>() .ToDictionary(p => p.Name, p => p.DisplayName); for (int i = 0; i < nombreProp.Length; i++) { table[0, i].AddParagraph().AppendText(diccionario[nombreProp[i]]); } int fila = 1; int col = 0; foreach (object item in lista) { col = 0; foreach (string propiedad in nombreProp) { table[fila, col].AddParagraph().AppendText( item.GetType().GetProperty(propiedad).GetValue(item).ToString() ); col++; } fila++; } } word.Save(ms, FormatType.Docx); return(ms.ToArray()); } }
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(); } }
private void Button_Click_1(object sender, RoutedEventArgs e) { WordDocument document = new WordDocument(); WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; WParagraph para = section.AddParagraph() as WParagraph; section.AddColumn(100, 100); section.AddColumn(100, 100); section.MakeColumnsEqual(); #region Built-in styles # region List Style
void OnButtonClicked(object sender, EventArgs e) { // Creating a new document. WordDocument document = new WordDocument(); WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; WParagraph para = section.AddParagraph() as WParagraph; section.AddColumn(100, 100); section.AddColumn(100, 100); section.MakeColumnsEqual(); #region Built-in styles # region List Style
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(); } }
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
/// <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); } }
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); } }
void OnButtonClicked(object sender, EventArgs e) { string resourcePath = "SampleBrowser.Samples.DocIO.Templates.CreateEquation.docx"; Assembly assembly = Assembly.GetExecutingAssembly(); Stream fileStream = assembly.GetManifestResourceStream(resourcePath); // Loads the stream into Word Document. WordDocument document = new WordDocument(fileStream, Syncfusion.DocIO.FormatType.Automatic); //Gets the last section in the document WSection section = document.LastSection; //Sets page margins document.LastSection.PageSetup.Margins.All = 72; //Adds new paragraph to the section IWParagraph paragraph = section.AddParagraph(); //Appends text to paragraph IWTextRange textRange = paragraph.AppendText("Mathematical equations"); textRange.CharacterFormat.FontSize = 28; paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center; paragraph.ParagraphFormat.AfterSpacing = 12; #region Sum to the power of n //Adds new paragraph to the section paragraph = AddParagraph(section, "This is an expansion of the sum (1+X) to the power of n."); //Creates an equation with sum to the power of N CreateSumToThePowerOfN(paragraph); #endregion #region Fourier series //Adds new paragraph to the section paragraph = AddParagraph(section, "This is a Fourier series for the function of period 2L"); //Creates a Fourier series equation CreateFourierseries(paragraph); #endregion #region Triple scalar product //Adds new paragraph to the section paragraph = AddParagraph(section, "This is an expansion of triple scalar product"); //Creates a triple scalar product equation CreateTripleScalarProduct(paragraph); #endregion #region Gamma function //Adds new paragraph to the section paragraph = AddParagraph(section, "This is an expansion of gamma function"); //Creates a gamma function equation CreateGammaFunction(paragraph); #endregion #region Vector relation //Adds new paragraph to the section paragraph = AddParagraph(section, "This is an expansion of vector relation "); //Creates a vector relation equation CreateVectorRelation(paragraph); #endregion MemoryStream stream = new MemoryStream(); //Set file content type string contentType = null; string fileName = null; if (docxButton.Checked) { fileName = "CreateEquation.docx"; contentType = "application/msword"; document.Save(stream, FormatType.Docx); } else { fileName = "CreateEquation.pdf"; contentType = "application/pdf"; DocIORenderer renderer = new DocIORenderer(); PdfDocument pdfDoc = renderer.ConvertToPDF(document); pdfDoc.Save(stream); pdfDoc.Close(); } document.Dispose(); if (stream != null) { SaveAndroid androidSave = new SaveAndroid(); androidSave.Save(fileName, contentType, stream, m_context); } }
public MemoryStream CreateWord() { //Creating a new document WordDocument document = new WordDocument(); //Adding a new section to the document WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; //Set page size of the section section.PageSetup.PageSize = new Syncfusion.Drawing.SizeF(612, 792); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 11f; style.ParagraphFormat.BeforeSpacing = 0; style.ParagraphFormat.AfterSpacing = 8; style.ParagraphFormat.LineSpacing = 13.8f; style = document.AddParagraphStyle("Heading 1") as WParagraphStyle; style.ApplyBaseStyle("Normal"); style.CharacterFormat.FontName = "Calibri Light"; style.CharacterFormat.FontSize = 16f; style.CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(46, 116, 181); style.ParagraphFormat.BeforeSpacing = 12; style.ParagraphFormat.AfterSpacing = 0; style.ParagraphFormat.Keep = true; style.ParagraphFormat.KeepFollow = true; style.ParagraphFormat.OutlineLevel = OutlineLevel.Level1; IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph(); paragraph.ApplyStyle("Normal"); paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left; WTextRange textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Calibri"; textRange.CharacterFormat.TextColor = Syncfusion.Drawing.Color.Red; //Appends paragraph paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center; textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 18f; textRange.CharacterFormat.FontName = "Calibri"; //Appends paragraph paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is in Bothell, Washington with 290 employees, several regional sales teams are located throughout their market base.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; //Appends paragraph paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("In 2000, AdventureWorks Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the AdventureWorks Cycles product line. These subcomponents are shipped to the Bothell location for final product assembly. In 2001, Importadores Neptuno, became the sole manufacturer and distributor of the touring bicycle product group.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; //Saves the Word document to MemoryStream MemoryStream stream = new MemoryStream(); document.Save(stream, FormatType.Docx); //Closes the Word document document.Close(); stream.Position = 0; return(stream); }
/// <summary> /// Create a simple Word document /// </summary> /// <returns>Return the created Word document as stream</returns> public MemoryStream CreateWordDocument(string documentType) { //Creating a new document WordDocument document = new WordDocument(); //Adding a new section to the document WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; //Set page size of the section section.PageSetup.PageSize = new SizeF(612, 792); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 11f; style.ParagraphFormat.BeforeSpacing = 0; style.ParagraphFormat.AfterSpacing = 8; style.ParagraphFormat.LineSpacing = 13.8f; style = document.AddParagraphStyle("Heading 1") as WParagraphStyle; style.ApplyBaseStyle("Normal"); style.CharacterFormat.FontName = "Calibri Light"; style.CharacterFormat.FontSize = 16f; style.CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(46, 116, 181); style.ParagraphFormat.BeforeSpacing = 12; style.ParagraphFormat.AfterSpacing = 0; style.ParagraphFormat.Keep = true; style.ParagraphFormat.KeepFollow = true; style.ParagraphFormat.OutlineLevel = OutlineLevel.Level1; IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph(); string basePath = _hostingEnvironment.WebRootPath + @"/images/DocIO/"; FileStream imageStream = new FileStream(basePath + @"AdventureCycle.jpg", FileMode.Open, FileAccess.Read); WPicture picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.InFrontOfText; picture.VerticalOrigin = VerticalOrigin.Margin; picture.VerticalPosition = -45; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = 263.5f; picture.WidthScale = 20; picture.HeightScale = 15; paragraph.ApplyStyle("Normal"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; WTextRange textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Calibri"; textRange.CharacterFormat.TextColor = Syncfusion.Drawing.Color.Red; //Appends paragraph paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 18f; textRange.CharacterFormat.FontName = "Calibri"; //Appends paragraph paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Bothell, Washington with 290 employees, several regional sales teams are located throughout their market base.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("In 2000, Adventure Works Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the Adventure Works Cycles product line. These subcomponents are shipped to the Bothell location for final product assembly. In 2001, Importadores Neptuno, became the sole manufacturer and distributor of the touring bicycle product group.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; textRange = paragraph.AppendText("Product Overview") as WTextRange; textRange.CharacterFormat.FontSize = 16f; textRange.CharacterFormat.FontName = "Calibri"; //Appends table IWTable table = section.AddTable(); table.ResetCells(3, 2); table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.None; table.TableFormat.IsAutoResized = true; //Appends paragraph paragraph = table[0, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends picture to the paragraph imageStream = new FileStream(basePath + @"Mountain-200.jpg", FileMode.Open, FileAccess.Read); picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 4.5f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -2.15f; picture.WidthScale = 79; picture.HeightScale = 79; //Appends paragraph paragraph = table[0, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-200"); //Appends paragraph paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-M68B-38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 25\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $2,294.99\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph paragraph = table[1, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-300 "); //Appends paragraph paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-M47B-38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 35\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 22\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $1,079.99\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph paragraph = table[1, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends picture to the paragraph imageStream = new FileStream(basePath + @"Mountain-300.jpg", FileMode.Open, FileAccess.Read); picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 8.2f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -14.95f; picture.WidthScale = 75; picture.HeightScale = 75; //Appends paragraph paragraph = table[2, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends picture to the paragraph imageStream = new FileStream(basePath + @"Road-550-W.jpg", FileMode.Open, FileAccess.Read); picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 3.75f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -5f; picture.WidthScale = 92; picture.HeightScale = 92; //Appends paragraph paragraph = table[2, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Road-150 "); //Appends paragraph paragraph = table[2, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-R93R-44\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 44\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 14\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $3,578.27\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph paragraph = table[2, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends paragraph section.AddParagraph(); 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 document.Save(stream, formatType); document.Close(); stream.Position = 0; return(stream); } }
void OnButtonClicked(object sender, EventArgs e) { Assembly assembly = typeof(CreateEquation).GetTypeInfo().Assembly; #if COMMONSB string rootPath = "SampleBrowser.Samples.DocIO.Samples.Templates."; #else string rootPath = "SampleBrowser.DocIO.Samples.Templates."; #endif Stream inputStream = assembly.GetManifestResourceStream(rootPath + "CreateEquation.docx"); // Loads the stream into Word Document. WordDocument document = new WordDocument(inputStream, Syncfusion.DocIO.FormatType.Automatic); //Gets the last section in the document WSection section = document.LastSection; //Sets page margins document.LastSection.PageSetup.Margins.All = 72; //Adds new paragraph to the section IWParagraph paragraph = section.AddParagraph(); //Appends text to paragraph IWTextRange textRange = paragraph.AppendText("Mathematical equations"); textRange.CharacterFormat.FontSize = 28; paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center; paragraph.ParagraphFormat.AfterSpacing = 12; #region Sum to the power of n //Adds new paragraph to the section paragraph = AddParagraph(section, "This is an expansion of the sum (1+X) to the power of n."); //Creates an equation with sum to the power of N CreateSumToThePowerOfN(paragraph); #endregion #region Fourier series //Adds new paragraph to the section paragraph = AddParagraph(section, "This is a Fourier series for the function of period 2L"); //Creates a Fourier series equation CreateFourierseries(paragraph); #endregion #region Triple scalar product //Adds new paragraph to the section paragraph = AddParagraph(section, "This is an expansion of triple scalar product"); //Creates a triple scalar product equation CreateTripleScalarProduct(paragraph); #endregion #region Gamma function //Adds new paragraph to the section paragraph = AddParagraph(section, "This is an expansion of gamma function"); //Creates a gamma function equation CreateGammaFunction(paragraph); #endregion #region Vector relation //Adds new paragraph to the section paragraph = AddParagraph(section, "This is an expansion of vector relation "); //Creates a vector relation equation CreateVectorRelation(paragraph); #endregion string filename = ""; string contenttype = ""; MemoryStream outputStream = new MemoryStream(); if (this.pdfButton.IsChecked != null && (bool)this.pdfButton.IsChecked) { filename = "CreateEquation.pdf"; contenttype = "application/pdf"; DocIORenderer renderer = new DocIORenderer(); PdfDocument pdfDoc = renderer.ConvertToPDF(document); pdfDoc.Save(outputStream); pdfDoc.Close(); } else { filename = "CreateEquation.docx"; contenttype = "application/msword"; document.Save(outputStream, FormatType.Docx); } document.Close(); if (Device.RuntimePlatform == Device.UWP) { Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save(filename, contenttype, outputStream); } else { Xamarin.Forms.DependencyService.Get <ISave>().Save(filename, contenttype, outputStream); } }
private void button1_Click(object sender, System.EventArgs e) { try { //Getting Image files path. string dataPath = Application.StartupPath + @"..\..\..\..\..\..\..\..\Common\images\DocIO\"; //A new document is created. WordDocument document = new WordDocument(); //Adding a new section to the document. WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; //Set page size of the section section.PageSetup.PageSize = new SizeF(612, 792); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 11f; style.ParagraphFormat.BeforeSpacing = 0; style.ParagraphFormat.AfterSpacing = 8; style.ParagraphFormat.LineSpacing = 13.8f; style = document.AddParagraphStyle("Heading 1") as WParagraphStyle; style.ApplyBaseStyle("Normal"); style.CharacterFormat.FontName = "Calibri Light"; style.CharacterFormat.FontSize = 16f; style.CharacterFormat.TextColor = Color.FromArgb(46, 116, 181); style.ParagraphFormat.BeforeSpacing = 12; style.ParagraphFormat.AfterSpacing = 0; style.ParagraphFormat.Keep = true; style.ParagraphFormat.KeepFollow = true; style.ParagraphFormat.OutlineLevel = OutlineLevel.Level1; IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph(); WPicture picture = paragraph.AppendPicture(Image.FromFile(dataPath + "AdventureCycle.jpg")) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.InFrontOfText; picture.VerticalOrigin = VerticalOrigin.Margin; picture.VerticalPosition = -45; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = 263.5f; picture.WidthScale = 20; picture.HeightScale = 15; paragraph.ApplyStyle("Normal"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; WTextRange textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Calibri"; textRange.CharacterFormat.TextColor = Color.Red; //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 18f; textRange.CharacterFormat.FontName = "Calibri"; //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Bothell, Washington with 290 employees, several regional sales teams are located throughout their market base.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("In 2000, Adventure Works Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the Adventure Works Cycles product line. These subcomponents are shipped to the Bothell location for final product assembly. In 2001, Importadores Neptuno, became the sole manufacturer and distributor of the touring bicycle product group.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; textRange = paragraph.AppendText("Product Overview") as WTextRange; textRange.CharacterFormat.FontSize = 16f; textRange.CharacterFormat.FontName = "Calibri"; //Appends table. IWTable table = section.AddTable(); table.ResetCells(3, 2); table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.None; table.TableFormat.IsAutoResized = true; //Appends paragraph. paragraph = table[0, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends picture to the paragraph. picture = paragraph.AppendPicture(Image.FromFile(dataPath + "Mountain-200.jpg")) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 4.5f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -2.15f; picture.WidthScale = 79; picture.HeightScale = 79; //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-200"); //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-M68B-38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 25\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $2,294.99\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-300 "); //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-M47B-38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 35\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 22\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $1,079.99\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[1, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends picture to the paragraph. picture = paragraph.AppendPicture(Image.FromFile(dataPath + "Mountain-300.jpg")) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 8.2f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -14.95f; picture.WidthScale = 75; picture.HeightScale = 75; //Appends paragraph. paragraph = table[2, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends picture to the paragraph. picture = paragraph.AppendPicture(Image.FromFile(dataPath + "Road-550-W.jpg")) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 3.75f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -5f; picture.WidthScale = 92; picture.HeightScale = 92; //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Road-150 "); //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-R93R-44\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 44\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 14\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $3,578.27\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. section.AddParagraph(); //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); } }
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); } }
public MemoryStream CreateWord(List <Lokaal> lokalen) { //Creating a new document WordDocument document = new WordDocument(); //Adding a new section to the document WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; //Set page size of the section section.PageSetup.PageSize = new Syncfusion.Drawing.SizeF(612, 792); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 16f; style.ParagraphFormat.BeforeSpacing = 0; style.ParagraphFormat.AfterSpacing = 0; style.ParagraphFormat.LineSpacing = 13.8f; style = document.AddParagraphStyle("Heading 1") as WParagraphStyle; style.ApplyBaseStyle("Normal"); style.CharacterFormat.FontName = "Calibri Light"; style.CharacterFormat.FontSize = 18f; style.CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(46, 116, 181); style.ParagraphFormat.BeforeSpacing = 12; style.ParagraphFormat.AfterSpacing = 0; style.ParagraphFormat.Keep = true; style.ParagraphFormat.KeepFollow = true; style.ParagraphFormat.OutlineLevel = OutlineLevel.Level1; IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph(); paragraph.ApplyStyle("Normal"); paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center; WTextRange textRange = paragraph.AppendText("Overzicht") as WTextRange; textRange.CharacterFormat.FontName = "Calibri"; textRange.CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(46, 116, 181); //Appends paragraph paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center; textRange = paragraph.AppendText("Inventaris Lokalen") as WTextRange; textRange.CharacterFormat.FontSize = 20f; textRange.CharacterFormat.FontName = "Calibri"; //Eerste cel van tabel IWTable table = section.AddTable(); table.ResetCells(lokalen.Count(), 3); WTableCell firstCell = table.Rows[0].Cells[0]; firstCell.Width = 100; paragraph = firstCell.AddParagraph(); paragraph.ApplyStyle("Normal"); textRange = paragraph.AppendText("Lokaal") as WTextRange; textRange.CharacterFormat.Bold = true; //Tweede cel van tabel WTableCell secondCell = table.Rows[0].Cells[1]; secondCell.Width = 180; paragraph = secondCell.AddParagraph(); paragraph.ApplyStyle("Normal"); textRange = paragraph.AppendText("Details") as WTextRange; textRange.CharacterFormat.Bold = true; //Derde cel van tabel WTableCell thirdCell = table.Rows[0].Cells[2]; thirdCell.Width = 170; paragraph = thirdCell.AddParagraph(); paragraph.ApplyStyle("Normal"); textRange = paragraph.AppendText("Voorwerpen") as WTextRange; textRange.CharacterFormat.Bold = true; for (int i = 1; i < lokalen.Count(); i++) { //Lokaal firstCell = table.Rows[i].Cells[0]; firstCell.Width = 100; paragraph = firstCell.AddParagraph(); textRange = paragraph.AppendText("Lokaal " + lokalen[i].lokaalNr) as WTextRange; textRange.CharacterFormat.FontSize = 14f; //Details per lokaal secondCell = table.Rows[i].Cells[1]; secondCell.Width = 180; paragraph = secondCell.AddParagraph(); textRange = paragraph.AppendText("Nummer : " + lokalen[i].lokaalNr + "\n" + "Verantwoordelijke : " + lokalen[i].lokaalVerantwoordelijke + "\n" + "Actief/Inactief : " + (lokalen[i].isActief ? "Actief" : "Inactief")) as WTextRange; textRange.CharacterFormat.FontSize = 13f; //Voorwerpen per lokaal for (int j = 0; j < lokalen[i].Voorwerpen.Count(); j++) { thirdCell = table.Rows[i].Cells[2]; thirdCell.Width = 170; paragraph = thirdCell.AddParagraph(); textRange = paragraph.AppendText("- " + lokalen[i].Voorwerpen[j].aantal + " x " + lokalen[i].Voorwerpen[j].voorwerpNaam + "\n" + (lokalen[i].Voorwerpen[j].defect ? "defect" : "niet defect")) as WTextRange; textRange.CharacterFormat.FontSize = 13f; } } //Saves the Word document to MemoryStream MemoryStream stream = new MemoryStream(); document.Save(stream, FormatType.Docx); //Closes the Word document document.Close(); stream.Position = 0; return(stream); }
public ActionResult DocIOFeatures(string Group1) { if (Group1 == null) { return(View()); } string dataPath3 = ResolveApplicationDataPath("", "Content\\Images\\DocIO"); //A new document is created. WordDocument document = new WordDocument(); //Adding a new section to the document. WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; //Set page size of the section section.PageSetup.PageSize = new SizeF(612, 792); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 11f; style.ParagraphFormat.BeforeSpacing = 0; style.ParagraphFormat.AfterSpacing = 8; style.ParagraphFormat.LineSpacing = 13.8f; style = document.AddParagraphStyle("Heading 1") as WParagraphStyle; style.ApplyBaseStyle("Normal"); style.CharacterFormat.FontName = "Calibri Light"; style.CharacterFormat.FontSize = 16f; style.CharacterFormat.TextColor = Color.FromArgb(46, 116, 181); style.ParagraphFormat.BeforeSpacing = 12; style.ParagraphFormat.AfterSpacing = 0; style.ParagraphFormat.Keep = true; style.ParagraphFormat.KeepFollow = true; style.ParagraphFormat.OutlineLevel = OutlineLevel.Level1; //Appends paragraph. IWParagraph paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; WTextRange textRange = paragraph.AppendText("Syncfusion Metro Studio") as WTextRange; textRange.CharacterFormat.FontSize = 18f; textRange.CharacterFormat.FontName = "Calibri"; //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("Syncfusion Metro Studio is a collection of over 1700 Metro-style icon templates that can be easily customized to create thousands of unique Metro icons. Metro is a design language so it can be applied to any platform or technology. At Syncfusion we have used these icons in everything from PowerPoint presentations to applications written in all .NET platforms including WPF, Silverlight, Windows Phone, Windows Forms, ASP.NET, and ASP.NET MVC.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; #region Insert Table. //Appends table. IWTable table = section.AddTable(); table.ResetCells(3, 2); table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.None; table.TableFormat.IsAutoResized = true; //Appends paragraph. paragraph = table[0, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends picture to the paragraph. WPicture picture = paragraph.AppendPicture(Image.FromFile(System.IO.Path.Combine(dataPath3, "MetroStudio1.png"))) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 0; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -5.15f; picture.WidthScale = 79; picture.HeightScale = 79; //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Developer-friendly icon editor "); //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Metro Studio includes a powerful icon editor that lets you quickly find and customize all the icons that you need in only a few minutes. ") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Convert fonts to icons "); //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Easily customize thousands of font characters as icons and export them to the desired formats. ") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[1, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends picture to the paragraph. picture = paragraph.AppendPicture(Image.FromFile(System.IO.Path.Combine(dataPath3, "MetroStudio2.png"))) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 8.2f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -14.95f; picture.WidthScale = 75; picture.HeightScale = 75; //Appends paragraph. paragraph = table[2, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends picture to the paragraph. picture = paragraph.AppendPicture(Image.FromFile(System.IO.Path.Combine(dataPath3, "MetroStudio3.png"))) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 0; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -4.9f; picture.WidthScale = 92; picture.HeightScale = 92; //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Organize icons as projects "); //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Organize icons into projects that can be serialized for modification at a later time. Multiple icons in a project can be exported with a single click. ") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; #endregion //Appends paragraph. section.AddParagraph(); #region saveOption if (Group1 == "Word97To2003") { //Save as .doc Word 97-2003 format return(document.ExportAsActionResult("Sample.doc", FormatType.Doc, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .docx Word 2007 format else if (Group1 == "Word2007") { return(document.ExportAsActionResult("Sample.docx", FormatType.Word2007, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .docx Word 2010 format else if (Group1 == "Word2010") { return(document.ExportAsActionResult("Sample.docx", FormatType.Word2010, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .docx Word 2013 format else if (Group1 == "Word2013") { return(document.ExportAsActionResult("Sample.docx", FormatType.Word2013, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } #endregion saveOption return(View()); }
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)); }
void OnButtonClicked(object sender, EventArgs e) { WordDocument 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 = 1; 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."); } #region Saving Document MemoryStream stream = new MemoryStream(); document.Save(stream, FormatType.Word2013); document.Close(); if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows) { Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("WordDocument_CustomStyles.docx", "application/msword", stream); } else { Xamarin.Forms.DependencyService.Get <ISave>().Save("WordDocument_CustomStyles.docx", "application/msword", stream); } #endregion }
public ActionResult HelloWorld(string Group1) { if (Group1 == null) { return(View()); } dataPath3 = ResolveApplicationDataPath("", "Images\\DocIO"); // Creating a new document. WordDocument document = new WordDocument(); //Adding a new section to the document. WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; //Set page size of the section section.PageSetup.PageSize = new System.Drawing.SizeF(612, 792); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 11f; style.ParagraphFormat.BeforeSpacing = 0; style.ParagraphFormat.AfterSpacing = 8; style.ParagraphFormat.LineSpacing = 13.8f; style = document.AddParagraphStyle("Heading 1") as WParagraphStyle; style.ApplyBaseStyle("Normal"); style.CharacterFormat.FontName = "Calibri Light"; style.CharacterFormat.FontSize = 16f; style.CharacterFormat.TextColor = System.Drawing.Color.FromArgb(46, 116, 181); style.ParagraphFormat.BeforeSpacing = 12; style.ParagraphFormat.AfterSpacing = 0; style.ParagraphFormat.Keep = true; style.ParagraphFormat.KeepFollow = true; style.ParagraphFormat.OutlineLevel = OutlineLevel.Level1; IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph(); WPicture picture = paragraph.AppendPicture(Image.FromFile(System.IO.Path.Combine(dataPath3, "AdventureCycle.jpg"))) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.InFrontOfText; picture.VerticalOrigin = VerticalOrigin.Margin; picture.VerticalPosition = -45; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = 263.5f; picture.WidthScale = 20; picture.HeightScale = 15; paragraph.ApplyStyle("Normal"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; WTextRange textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Calibri"; textRange.CharacterFormat.TextColor = System.Drawing.Color.Red; //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 18f; textRange.CharacterFormat.FontName = "Calibri"; //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Bothell, Washington with 290 employees, several regional sales teams are located throughout their market base.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("In 2000, Adventure Works Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the Adventure Works Cycles product line. These subcomponents are shipped to the Bothell location for final product assembly. In 2001, Importadores Neptuno, became the sole manufacturer and distributor of the touring bicycle product group.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; textRange = paragraph.AppendText("Product Overview") as WTextRange; textRange.CharacterFormat.FontSize = 16f; textRange.CharacterFormat.FontName = "Calibri"; //Appends table. IWTable table = section.AddTable(); table.ResetCells(3, 2); table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.None; table.TableFormat.IsAutoResized = true; //Appends paragraph. paragraph = table[0, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends picture to the paragraph. picture = paragraph.AppendPicture(Image.FromFile(System.IO.Path.Combine(dataPath3, "Mountain-200.jpg"))) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 4.5f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -2.15f; picture.WidthScale = 79; picture.HeightScale = 79; //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-200"); //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-M68B-38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 25\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $2,294.99\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-300 "); //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-M47B-38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 35\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 22\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $1,079.99\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[1, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends picture to the paragraph. picture = paragraph.AppendPicture(Image.FromFile(System.IO.Path.Combine(dataPath3, "Mountain-300.jpg"))) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 8.2f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -14.95f; picture.WidthScale = 75; picture.HeightScale = 75; //Appends paragraph. paragraph = table[2, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends picture to the paragraph. picture = paragraph.AppendPicture(Image.FromFile(System.IO.Path.Combine(dataPath3, "Road-550-W.jpg"))) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 3.75f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -5f; picture.WidthScale = 92; picture.HeightScale = 92; //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Road-150 "); //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-R93R-44\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 44\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 14\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $3,578.27\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. section.AddParagraph(); #region saveOption //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)); } #endregion saveOption return(View()); }
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) { Assembly assembly = typeof(App).GetTypeInfo().Assembly; // Creating a new document. // Creating a new document. WordDocument document = new WordDocument(); //Adding a new section to the document. WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; //Set page size of the section section.PageSetup.PageSize = new Syncfusion.Drawing.SizeF(612, 792); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 11f; style.ParagraphFormat.BeforeSpacing = 0; style.ParagraphFormat.AfterSpacing = 8; style.ParagraphFormat.LineSpacing = 13.8f; style = document.AddParagraphStyle("Heading 1") as WParagraphStyle; style.ApplyBaseStyle("Normal"); style.CharacterFormat.FontName = "Calibri Light"; style.CharacterFormat.FontSize = 16f; style.CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(46, 116, 181); style.ParagraphFormat.BeforeSpacing = 12; style.ParagraphFormat.AfterSpacing = 0; style.ParagraphFormat.Keep = true; style.ParagraphFormat.KeepFollow = true; style.ParagraphFormat.OutlineLevel = OutlineLevel.Level1; IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph(); Stream imageStream = assembly.GetManifestResourceStream("SampleBrowser.Samples.DocIO.Templates.AdventureCycle.jpg"); WPicture picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.InFrontOfText; picture.VerticalOrigin = VerticalOrigin.Margin; picture.VerticalPosition = -24; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = 263.5f; picture.WidthScale = 20; picture.HeightScale = 15; paragraph.ApplyStyle("Normal"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; WTextRange textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Calibri"; textRange.CharacterFormat.TextColor = Syncfusion.Drawing.Color.Red; //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 18f; textRange.CharacterFormat.FontName = "Calibri"; //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Bothell, Washington with 290 employees, several regional sales teams are located throughout their market base.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("In 2000, Adventure Works Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the Adventure Works Cycles product line. These subcomponents are shipped to the Bothell location for final product assembly. In 2001, Importadores Neptuno, became the sole manufacturer and distributor of the touring bicycle product group.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; textRange = paragraph.AppendText("Product Overview") as WTextRange; textRange.CharacterFormat.FontSize = 16f; textRange.CharacterFormat.FontName = "Calibri"; //Appends table. IWTable table = section.AddTable(); table.ResetCells(3, 2); table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.None; table.TableFormat.IsAutoResized = true; //Appends paragraph. paragraph = table[0, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.BreakCharacterFormat.FontSize = 12f; imageStream = assembly.GetManifestResourceStream("SampleBrowser.Samples.DocIO.Templates.Mountain-200.jpg"); //Appends picture to the paragraph. picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 0; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -5.15f; picture.WidthScale = 79; picture.HeightScale = 79; //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-200"); //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-M68B-38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 25\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $2,294.99\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-300 "); //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-M47B-38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 35\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 22\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $1,079.99\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[1, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; imageStream = assembly.GetManifestResourceStream("SampleBrowser.Samples.DocIO.Templates.Mountain-300.jpg"); //Appends picture to the paragraph. picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 8.2f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -14.95f; picture.WidthScale = 75; picture.HeightScale = 75; //Appends paragraph. paragraph = table[2, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; imageStream = assembly.GetManifestResourceStream("SampleBrowser.Samples.DocIO.Templates.Road-550-W.jpg"); //Appends picture to the paragraph. picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 0; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -4.9f; picture.WidthScale = 92; picture.HeightScale = 92; //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Road-150 "); //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-R93R-44\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 44\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 14\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $3,578.27\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends paragraph. section.AddParagraph(); MemoryStream stream = new MemoryStream(); document.Save(stream, FormatType.Word2013); document.Close(); if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows) { Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("GettingStarted.docx", "application/msword", stream); } else { Xamarin.Forms.DependencyService.Get <ISave>().Save("GettingStarted.docx", "application/msword", stream); } }
public byte[] exportarDatosWord <T>(string[] nombrePropiedades, List <T> lista) { using (MemoryStream ms = new MemoryStream()) { WordDocument document = new WordDocument(); //agregar una secion WSection section = document.AddSection() as WSection; //agregando un margen section.PageSetup.Margins.All = 72; //tamanio section.PageSetup.PageSize = new Syncfusion.Drawing.SizeF(612, 792); //agregando un parrafo IWParagraph paragraph = section.AddParagraph(); //tipo de letra paragraph.ApplyStyle("Normal"); //centrar paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center; //agregando un texto WTextRange textRange = paragraph.AppendText("Reporte en Word") as WTextRange; //el texto va a tener un tamañio de 20f textRange.CharacterFormat.FontSize = 20f; //tipo de letra textRange.CharacterFormat.FontName = "Calibri"; //color textRange.CharacterFormat.TextColor = Syncfusion.Drawing.Color.Blue; //agregando una tabla if (nombrePropiedades != null) { IWTable table = section.AddTable(); //numero de columnas int numeroColumnas = nombrePropiedades.Length; //numero de filas int nfilas = lista.Count; //agregando las columnas y filas de la tabla va a tener table.ResetCells(nfilas + 1, numeroColumnas); //displayName Dictionary <string, string> diccionario = cm.TypeDescriptor.GetProperties(typeof(T)).Cast <cm.PropertyDescriptor>() .ToDictionary(p => p.Name, p => p.DisplayName); if (nombrePropiedades != null) { for (int i = 0; i < numeroColumnas; i++) { //insertando las cabeceras table[0, i].AddParagraph().AppendText(diccionario[nombrePropiedades[i]]); } int fila = 1; int col = 0; foreach (object item in lista) { col = 0; foreach (string propiedad in nombrePropiedades) { table[fila, col].AddParagraph().AppendText( item.GetType().GetProperty(propiedad).GetValue(item).ToString()); col++; } fila++; } } } //guardo en documento document.Save(ms, FormatType.Docx); return(ms.ToArray()); } }
/// <summary> /// Creates product overview table in the Word document. /// </summary> /// <param name="section">The section to add table.</param> private void CreateProductOverviewTable(WSection section) { //Appends table. IWTable table = section.AddTable(); table.ResetCells(4, 2); table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.None; table.TableFormat.IsAutoResized = true; //Appends paragraph. IWParagraph paragraph = table[0, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.BreakCharacterFormat.FontSize = 12f; string resourcePath = "syncfusion.dociodemos.winui.Assets.DocIO.Mountain200.jpg"; //Appends picture to the paragraph. Stream imageStream = assembly.GetManifestResourceStream(resourcePath); WPicture picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 4.5f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -2.15f; picture.WidthScale = 79; picture.HeightScale = 79; //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-200"); //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; //Adds textrange. AddTextRange(paragraph, "Product No: BK-M68B-38\r"); AddTextRange(paragraph, "Size: 38\r"); AddTextRange(paragraph, "Weight: 25\r"); AddTextRange(paragraph, "Price: $2,294.99\r"); //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-300 "); //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; //Adds textrange. AddTextRange(paragraph, "Product No: BK-M47B-38\r"); AddTextRange(paragraph, "Size: 35\r"); AddTextRange(paragraph, "Weight: 22\r"); AddTextRange(paragraph, "Price: $1,079.99\r"); //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[1, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; resourcePath = "syncfusion.dociodemos.winui.Assets.DocIO.Mountain300.jpg"; //Appends picture to the paragraph. imageStream = assembly.GetManifestResourceStream(resourcePath); picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 8.2f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -14.95f; picture.WidthScale = 75; picture.HeightScale = 75; //Appends paragraph. paragraph = table[2, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; resourcePath = "syncfusion.dociodemos.winui.Assets.DocIO.Road550W.jpg"; //Appends picture to the paragraph. imageStream = assembly.GetManifestResourceStream(resourcePath); picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 3.75f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -5f; picture.WidthScale = 92; picture.HeightScale = 92; //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Road-150 "); //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; //Adds textrange. AddTextRange(paragraph, "Product No: BK-R93R-44\r"); AddTextRange(paragraph, "Size: 44\r"); AddTextRange(paragraph, "Weight: 14\r"); AddTextRange(paragraph, "Price: $3,578.27\r"); //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[3, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-100"); //Appends paragraph. paragraph = table[3, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; //Adds textrange. AddTextRange(paragraph, "Product No: BK-M47B-38\r"); AddTextRange(paragraph, "Size: 42\r"); AddTextRange(paragraph, "Weight: 20\r"); AddTextRange(paragraph, "Price: $1,079.99\r"); //Appends paragraph. paragraph = table[3, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[3, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; resourcePath = "syncfusion.dociodemos.winui.Assets.DocIO.Mountain300.jpg"; //Appends picture to the paragraph. imageStream = assembly.GetManifestResourceStream(resourcePath); picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 8.2f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -14.95f; picture.WidthScale = 75; picture.HeightScale = 75; //Appends paragraph. section.AddParagraph(); }
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()); }