/// <summary>
        /// Adds textrange in the paragraph.
        /// </summary>
        private static void AddTextRange(IWParagraph paragraph, string text)
        {
            WTextRange textRange = paragraph.AppendText(text) as WTextRange;

            textRange.CharacterFormat.FontSize = 12f;
            textRange.CharacterFormat.FontName = "Times New Roman";
        }
Beispiel #2
0
        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();
        }
Beispiel #3
0
        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;
            }
        }
Beispiel #4
0
        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());
            }
        }
        /// <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 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());
        }
        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
        }
        async void OnButtonClicked(object sender, EventArgs args)
        {
            //"App" is the class of Portable project
            Assembly assembly = typeof(App).GetTypeInfo().Assembly;

            //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 = 10;
            //Set page size of the section
            section.PageSetup.PageSize = new Syncfusion.Drawing.SizeF(612, 792);

            await Nosi.GetNosiScraped();

            WTextRange textRange = new WTextRange(document);
            //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();

            //Appends paragraph
            foreach (Nosi n in Scraper.NosiList)
            {
                paragraph = section.AddParagraph();
                paragraph.ApplyStyle("Heading 1");
                paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
                textRange = paragraph.AppendText(n.Head) as WTextRange;

                paragraph = section.AddParagraph();
                paragraph.ApplyStyle("Normal");
                paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Justify;
                textRange = paragraph.AppendText(n.Content) as WTextRange;
            }

            //Appends paragraph
            section.AddParagraph();

            //Saves the Word document to MemoryStream
            MemoryStream stream = new MemoryStream();

            document.Save(stream, FormatType.Docx);

            //Save the stream as a file in the device and invoke it for viewing
            await Xamarin.Forms.DependencyService.Get <ISave>().SaveAndView("Nosi.docx", "application/msword", stream);
        }
Beispiel #9
0
        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);
            }
        }
Beispiel #10
0
        /// <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);
            }
        }
Beispiel #11
0
        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);
        }
Beispiel #12
0
        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);
            }
        }
        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 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());
            }
        }
Beispiel #15
0
        /// <summary>
        /// Inserts and updates the Table of Contents (TOC) in a Word document.
        /// </summary>
        private void Button_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
        {
            //Creates a new Word document.
            using WordDocument document = new();
            //Adds one section and paragraph.
            document.EnsureMinimal();
            document.LastSection.PageSetup.Margins.All = 72;
            WParagraph  para      = document.LastParagraph;
            IWTextRange textRange = para.AppendText("Essential DocIO - Table of Contents");

            textRange.CharacterFormat.Bold           = true;
            textRange.CharacterFormat.FontSize       = 14;
            para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            para.ParagraphFormat.BeforeSpacing       = 12f;
            para.ParagraphFormat.AfterSpacing        = 3f;

            para = document.LastSection.AddParagraph() as WParagraph;
            para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            para.ParagraphFormat.BeforeSpacing       = 12f;
            para.ParagraphFormat.AfterSpacing        = 3f;

            if (!checkBox.IsChecked.Value)
            {
                textRange = para.AppendText("Select TOC and press F9 to update the Table of Contents");
                textRange.CharacterFormat.HighlightColor = Syncfusion.Drawing.Color.Yellow;
                textRange.CharacterFormat.Bold           = true;
                textRange.CharacterFormat.FontSize       = 14;
            }

            para = document.LastSection.AddParagraph() as WParagraph;
            //Inserts TOC.
            Syncfusion.DocIO.DLS.TableOfContent toc = para.AppendTOC(1, 3);
            para.ParagraphFormat.BeforeSpacing = 12f;
            para.ParagraphFormat.AfterSpacing  = 3f;

            //Applies built-in paragraph formatting.
            WSection section = document.LastSection;

            #region Default Styles
            WParagraph newPara = section.AddParagraph() as WParagraph;
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendBreak(BreakType.PageBreak);
            WTextRange text = newPara.AppendText("Document with Default styles") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading1);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading1 of built in style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can only insert TOC field in a word document. It can not refresh or create TOC field. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC.");

            section.AddParagraph();
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Section1") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading2);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");

            section.AddParagraph();
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Paragraph1") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading3);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text.");

            section.AddParagraph();
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Paragraph2") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading3);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph.");

            section.AddParagraph();
            section = document.AddSection() as WSection;
            section.PageSetup.Margins.All = 72;
            section.BreakCode             = SectionBreakCode.NewPage;
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Section2") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading2);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");

            section.AddParagraph();
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Paragraph1") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading3);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text.");

            section.AddParagraph();
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Paragraph2") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading3);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph.");
            #endregion

            //Enables a flag to show page numbers in table of contents.
            toc.IncludePageNumbers = true;
            //Enables a flag to show page numbers as right aligned.
            toc.RightAlignPageNumbers = true;
            //Enables a flag to use hyperlinks for the levels.
            toc.UseHyperlinks = true;
            //Sets the starting heading level of the table of contents.
            toc.LowerHeadingLevel = 1;
            //Sets the ending heading level of the table of contents.
            toc.UpperHeadingLevel = 3;
            //Enables a flag to use outline levels.
            toc.UseOutlineLevels = true;

            //Updates the table of contents.
            if (checkBox.IsChecked.Value)
            {
                document.UpdateTableOfContents();
            }

            #region Document SaveOption
            using MemoryStream ms = new();
            string filename = string.Empty;
            //Saves as .docx format.
            if (worddocx.IsChecked == true)
            {
                filename = "Table of Contents.docx";
                //Saves the Word document to the memory stream.
                document.Save(ms, FormatType.Docx);
            }
            //Saves as .doc format.
            else if (worddoc.IsChecked == true)
            {
                filename = "Table of Contents.doc";
                //Saves the Word document to the memory stream.
                document.Save(ms, FormatType.Doc);
            }
            //Saves as .pdf format.
            else if (pdf.IsChecked == true)
            {
                filename = "Table of Contents.pdf";
                //Creates a new DocIORenderer instance.
                using DocIORenderer renderer = new();
                //Converts Word document into PDF.
                using PdfDocument pdfDoc = renderer.ConvertToPDF(document);
                //Saves the PDF document to the memory stream.
                pdfDoc.Save(ms);
            }
            ms.Position = 0;
            //Saves the memory stream as file.
            SaveHelper.SaveAndLaunch(filename, ms);
            #endregion Document SaveOption
        }
Beispiel #16
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            // 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 = Color.FromArgb(46, 116, 181);
            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();

            // Gets the image stream.

            /*
             * IWPicture picture = paragraph.AppendPicture(new Bitmap("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 = 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 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;

            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(new Bitmap("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(new Bitmap("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(new Bitmap("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();

            //Saves the Word document
            //document.Save("Sample.docx");

            // создаем каталог для файла
            string        path    = @"C:\SomeDir2";
            DirectoryInfo dirInfo = new DirectoryInfo(path);

            if (!dirInfo.Exists)
            {
                dirInfo.Create();
            }

            // запись в файл
            using (FileStream fstream = new FileStream($"{path}\\Sample.docx", FileMode.OpenOrCreate))
            {
                document.Save(fstream, 0);
            }
        }
        public ActionResult TableofContents(string Group1, string UpdateTOC)
        {
            if (Group1 == null)
            {
                return(View());
            }
            WordDocument doc = new WordDocument();

            doc.EnsureMinimal();

            WParagraph para = doc.LastParagraph;

            para.AppendText("Essential DocIO - Table of Contents");
            para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            para.ApplyStyle(BuiltinStyle.Heading4);

            para = doc.LastSection.AddParagraph() as WParagraph;
            para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            para.ApplyStyle(BuiltinStyle.Heading4);

            if (UpdateTOC != "Update")
            {
                para.AppendText("Select TOC and press F9 to update the Table of Contents").CharacterFormat.HighlightColor = Syncfusion.Drawing.Color.Yellow;
            }

            para = doc.LastSection.AddParagraph() as WParagraph;

            //Insert TOC
            TableOfContent toc = para.AppendTOC(1, 3);

            para.ApplyStyle(BuiltinStyle.Heading4);

            //Apply built-in paragraph formatting
            WSection section = doc.LastSection;

            #region Default Styles
            WParagraph newPara = section.AddParagraph() as WParagraph;
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendBreak(BreakType.PageBreak);
            WTextRange text = newPara.AppendText("Document with Default styles") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading1);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading1 of built in style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can only insert TOC field in a word document. It can not refresh or create TOC field. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC.");

            section.AddParagraph();
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Section1") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading2);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");

            section.AddParagraph();
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Paragraph1") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading3);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text.");

            section.AddParagraph();
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Paragraph2") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading3);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph.");

            section.AddParagraph();
            section           = doc.AddSection() as WSection;
            section.BreakCode = SectionBreakCode.NewPage;
            newPara           = section.AddParagraph() as WParagraph;
            text = newPara.AppendText("Section2") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading2);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");

            section.AddParagraph();
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Paragraph1") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading3);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading3 of built in style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text.");

            section.AddParagraph();
            newPara = section.AddParagraph() as WParagraph;
            text    = newPara.AppendText("Paragraph2") as WTextRange;
            newPara.ApplyStyle(BuiltinStyle.Heading3);
            newPara = section.AddParagraph() as WParagraph;
            newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph.");
            #endregion
            toc.IncludePageNumbers    = true;
            toc.RightAlignPageNumbers = true;
            toc.UseHyperlinks         = true;
            toc.LowerHeadingLevel     = 1;
            toc.UpperHeadingLevel     = 3;

            toc.UseOutlineLevels = true;

            //Updates the table of contents.
            if (UpdateTOC == "Update")
            {
                doc.UpdateTableOfContents();
            }

            #region Document SaveOption
            string       filename    = "";
            string       contenttype = "";
            MemoryStream ms          = new MemoryStream();
            //Save as .docx format
            if (Group1 == "WordDocx")
            {
                filename    = "Table of Contents.docx";
                contenttype = "application/vnd.ms-word.document.12";
                doc.Save(ms, FormatType.Docx);
            }
            // Save as .doc format
            else if (Group1 == "WordDoc")
            {
                filename    = "Table of Contents.doc";
                contenttype = "application/msword";
                doc.Save(ms, FormatType.Doc);
            }
            //Save as .xml format
            else if (Group1 == "WordML")
            {
                filename    = "Table of Contents.xml";
                contenttype = "application/msword";
                doc.Save(ms, FormatType.WordML);
            }
            //Save as .pdf format
            else if (Group1 == "Pdf")
            {
                filename    = "Table of Contents.pdf";
                contenttype = "application/pdf";
                Syncfusion.DocIORenderer.DocIORenderer renderer = new Syncfusion.DocIORenderer.DocIORenderer();
                Syncfusion.Pdf.PdfDocument             pdfDoc   = renderer.ConvertToPDF(doc);
                pdfDoc.Save(ms);
                pdfDoc.Close();
            }
            #endregion Document SaveOption
            doc.Close();
            ms.Position = 0;
            return(File(ms, contenttype, filename));
        }
Beispiel #18
0
        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);
            }
        }
Beispiel #19
0
        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));
        }
Beispiel #20
0
        /// <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);
            }
        }
Beispiel #21
0
        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());
        }
        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);
            }
        }
Beispiel #23
0
        private void Bwgenmon_DoWork(object sender, DoWorkEventArgs e)
        {
            int index = 0;

            switch (DateTime.Now.Month)
            {
            case 1:
                index = 0;
                break;

            case 2:
                index = 1;
                break;

            case 3:
                index = 2;
                break;

            case 4:
                index = 3;
                break;

            case 5:
                index = 4;
                break;

            case 6:
                index = 5;
                break;

            case 7:
                index = 6;
                break;

            case 8:
                index = 7;
                break;

            case 9:
                index = 8;
                break;

            case 10:
                index = 9;
                break;

            case 11:
                index = 10;
                break;

            case 12:
                index = 11;
                break;
            }

            var dates     = db.Randoms.Where(c => c.ID == 16).FirstOrDefault();
            var datearray = dates.Text.Split(';');
            var marray    = datearray[index].Split(',');

            var amounts     = db.Randoms.Where(c => c.ID == 15).FirstOrDefault();
            var amountarray = amounts.Text.Split(';');
            var amarray     = amountarray[index].Split(',');

            var names     = db.Randoms.Where(c => c.ID == 17).FirstOrDefault();
            var namearray = names.Text.Split(';');
            var narray    = namearray[index].Split(',');

            ArrayList marrayList = new ArrayList();

            marrayList.AddRange(marray);

            ArrayList amarrayList = new ArrayList();

            amarrayList.AddRange(amarray);

            ArrayList narraylist = new ArrayList();

            narraylist.AddRange(narray);

            ArrayList farrayList = new ArrayList();

            for (int i = 0; i <= marrayList.ToArray().Length - 2; i++)
            {
                string a    = narraylist[i].ToString();
                var    data = db.StudentDatas.Where(c => c.StudentName == a).FirstOrDefault();
                farrayList.Add(data.FatherName);
            }


            try
            {
                WordDocument document = new WordDocument(System.Windows.Forms.Application.StartupPath + @"\Samples\submission_sample.docx", FormatType.Docx);

                var schoolname = db.Randoms.Where(c => c.ID == 1).FirstOrDefault();
                var address    = db.Randoms.Where(c => c.ID == 2).FirstOrDefault();
                var contact    = db.Randoms.Where(c => c.ID == 3).FirstOrDefault();
                var email      = db.Randoms.Where(c => c.ID == 4).FirstOrDefault();

                #region SchoolName
                TextSelection textSelection = document.Find("{SchoolName}", false, true);
                IWTextRange   textRange     = textSelection.GetAsOneRange();

                //Modifies the text

                textRange.Text = schoolname.Text.ToString();
                textRange.CharacterFormat.FontName = "Times New Roman";
                #endregion

                #region Address
                textSelection = document.Find("{Address}", false, true);
                WTextRange addr = textSelection.GetAsOneRange();

                addr.Text = address.Text.ToString();

                #endregion

                #region Contact
                textSelection = document.Find("{Contact}", false, true);
                WTextRange con = textSelection.GetAsOneRange();

                con.Text = contact.Text.ToString();
                #endregion

                #region Email
                textSelection = document.Find("{Email}", false, true);
                WTextRange Email = textSelection.GetAsOneRange();

                Email.Text = email.Text.ToString();
                #endregion

                #region DateMonth
                textSelection = document.Find("{DateMonth}", false, true);
                WTextRange DateMonth = textSelection.GetAsOneRange();

                DateMonth.Text = "Month";
                #endregion

                #region MonthDate
                textSelection = document.Find("{MonthDate}", false, true);

                WTextRange MonthDate = textSelection.GetAsOneRange();

                MonthDate.Text = DateTime.Now.ToString("MMMM yyyy");
                #endregion

                #region Time
                textSelection = document.Find("{Time}", false, true);

                WTextRange Time = textSelection.GetAsOneRange();

                Time.Text = DateTime.Now.ToString("hh:mm tt");
                #endregion

                #region Amount

                int amt = 0;
                for (int i = 0; i <= amarrayList.ToArray().Length - 2; i++)
                {
                    amt = amt + Convert.ToInt32(amarrayList[i]);
                }
                textSelection = document.Find("{Amount}", false, true);

                WTextRange Amount = textSelection.GetAsOneRange();

                Amount.Text = "Rs. " + amt.ToString();
                #endregion

                IWSection section = document.Sections[0];


                IWTable table = section.AddTable();

                table.ResetCells(farrayList.ToArray().Length + 1, 4);

                //Header 1
                IWParagraph wParagraph = table[0, 0].AddParagraph();
                wParagraph.ParagraphFormat.AfterSpacing        = 2f;
                wParagraph.ParagraphFormat.BeforeSpacing       = 2f;
                wParagraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left;
                textRange = wParagraph.AppendText("Student’s Name");
                textRange.CharacterFormat.FontName = "Century Gothic";
                textRange.CharacterFormat.FontSize = 9;
                textRange.CharacterFormat.Bold     = true;


                //Header 2
                wParagraph = table[0, 1].AddParagraph();
                wParagraph.ParagraphFormat.AfterSpacing        = 2f;
                wParagraph.ParagraphFormat.BeforeSpacing       = 2f;
                wParagraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left;
                textRange = wParagraph.AppendText("Father's Name");
                textRange.CharacterFormat.FontName = "Century Gothic";
                textRange.CharacterFormat.FontSize = 9;
                textRange.CharacterFormat.Bold     = true;

                //Header 3
                wParagraph = table[0, 2].AddParagraph();
                wParagraph.ParagraphFormat.AfterSpacing        = 2f;
                wParagraph.ParagraphFormat.BeforeSpacing       = 2f;
                wParagraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                textRange = wParagraph.AppendText("Amount");
                textRange.CharacterFormat.FontName = "Century Gothic";
                textRange.CharacterFormat.FontSize = 9;
                textRange.CharacterFormat.Bold     = true;

                //Header 4
                wParagraph = table[0, 3].AddParagraph();
                wParagraph.ParagraphFormat.AfterSpacing        = 2f;
                wParagraph.ParagraphFormat.BeforeSpacing       = 2f;
                wParagraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                textRange = wParagraph.AppendText("Date & Time");
                textRange.CharacterFormat.FontName = "Century Gothic";
                textRange.CharacterFormat.FontSize = 9;
                textRange.CharacterFormat.Bold     = true;


                for (int i = 0; i <= farrayList.ToArray().Length - 1; i++)
                {
                    int inc = i + 1;
                    //Column 1
                    wParagraph = table[inc, 0].AddParagraph();
                    wParagraph.ParagraphFormat.AfterSpacing        = 2f;
                    wParagraph.ParagraphFormat.BeforeSpacing       = 2f;
                    wParagraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left;
                    textRange = wParagraph.AppendText(narraylist[i].ToString());
                    textRange.CharacterFormat.FontName = "Century Gothic";
                    textRange.CharacterFormat.FontSize = 9;
                    textRange.CharacterFormat.Bold     = false;


                    //Column 2
                    wParagraph = table[inc, 1].AddParagraph();
                    wParagraph.ParagraphFormat.AfterSpacing        = 2f;
                    wParagraph.ParagraphFormat.BeforeSpacing       = 2f;
                    wParagraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left;
                    textRange = wParagraph.AppendText(farrayList[i].ToString());
                    textRange.CharacterFormat.FontName = "Century Gothic";
                    textRange.CharacterFormat.FontSize = 9;
                    textRange.CharacterFormat.Bold     = false;

                    //Column 3
                    wParagraph = table[inc, 2].AddParagraph();
                    wParagraph.ParagraphFormat.AfterSpacing        = 2f;
                    wParagraph.ParagraphFormat.BeforeSpacing       = 2f;
                    wParagraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                    textRange = wParagraph.AppendText(amarrayList[i].ToString());
                    textRange.CharacterFormat.FontName = "Century Gothic";
                    textRange.CharacterFormat.FontSize = 9;
                    textRange.CharacterFormat.Bold     = false;

                    //Column 4
                    wParagraph = table[inc, 3].AddParagraph();
                    wParagraph.ParagraphFormat.AfterSpacing        = 2f;
                    wParagraph.ParagraphFormat.BeforeSpacing       = 2f;
                    wParagraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                    textRange = wParagraph.AppendText(marrayList[i].ToString());
                    textRange.CharacterFormat.FontName = "Century Gothic";
                    textRange.CharacterFormat.FontSize = 9;
                    textRange.CharacterFormat.Bold     = false;
                }


                string savepath = "FeeSubmissionList-" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".docx";
                document.Save(savepath, FormatType.Docx);



                PrintWord(System.Windows.Forms.Application.StartupPath + @"\" + savepath, DefaultPrinterName);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
        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());
                    }
                }
            }
        }
Beispiel #25
0
        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());
        }
Beispiel #26
0
        private void Bwprint_DoWork(object sender, DoWorkEventArgs e)
        {
            if (done)
            {
                try
                {
                    WordDocument document = new WordDocument(System.Windows.Forms.Application.StartupPath + @"\Samples\defaulters_sample.docx", FormatType.Docx);

                    var schoolname = db.Randoms.Where(c => c.ID == 1).FirstOrDefault();
                    var address    = db.Randoms.Where(c => c.ID == 2).FirstOrDefault();
                    var contact    = db.Randoms.Where(c => c.ID == 3).FirstOrDefault();
                    var email      = db.Randoms.Where(c => c.ID == 4).FirstOrDefault();

                    #region SchoolName
                    TextSelection textSelection = document.Find("{SchoolName}", false, true);
                    IWTextRange   textRange     = textSelection.GetAsOneRange();

                    //Modifies the text

                    textRange.Text = schoolname.Text.ToString();
                    textRange.CharacterFormat.FontName = "Times New Roman";
                    #endregion

                    #region Address
                    textSelection = document.Find("{Address}", false, true);
                    WTextRange addr = textSelection.GetAsOneRange();

                    addr.Text = address.Text.ToString();

                    #endregion

                    #region Contact
                    textSelection = document.Find("{Contact}", false, true);
                    WTextRange con = textSelection.GetAsOneRange();

                    con.Text = contact.Text.ToString();
                    #endregion

                    #region Email
                    textSelection = document.Find("{Email}", false, true);
                    WTextRange Email = textSelection.GetAsOneRange();

                    Email.Text = email.Text.ToString();
                    #endregion

                    #region Class Section
                    textSelection = document.Find("{ClassSection}", false, true);
                    WTextRange classsection = textSelection.GetAsOneRange();

                    classsection.Text = comboboxclass.Text + " " + comboboxsection.Text;
                    #endregion

                    #region Month Year
                    textSelection = document.Find("{MonthYear}", false, true);

                    WTextRange MonthYear = textSelection.GetAsOneRange();

                    MonthYear.Text = DateTime.Now.ToString("MMMM yyyy");
                    #endregion

                    #region Total Defaulters
                    textSelection = document.Find("{Defaulters}", false, true);

                    WTextRange Defaulters = textSelection.GetAsOneRange();

                    Defaulters.Text = DefaultArray.ToArray().Length.ToString();
                    #endregion



                    IWSection section = document.Sections[0];
                    IWTable   table   = section.AddTable();

                    ArrayList namearray    = new ArrayList();
                    ArrayList Fatherarray  = new ArrayList();
                    ArrayList montharray   = new ArrayList();
                    ArrayList arrearsarray = new ArrayList();

                    for (int i = 0; i <= DefaultArray.ToArray().Length - 1; i++)
                    {
                        int ids  = (Convert.ToInt32(DefaultArray[i]));
                        var data = db.StudentDatas.Where(c => c.ID == ids).FirstOrDefault();
                        namearray.Add(data.StudentName.ToString());
                        Fatherarray.Add(data.FatherName.ToString());

                        var list  = db.StudentFees.Where(c => c.ID == data.ID).FirstOrDefault();
                        int month = TutionFee((Convert.ToInt32(DefaultArray[i]))) + list.TransportFee + list.ExamFee + list.OthersFee;

                        montharray.Add(month.ToString());

                        arrearsarray.Add(list.Arrears.ToString());
                    }

                    table.ResetCells(DefaultArray.ToArray().Length + 1, 4);

                    //Header 1
                    IWParagraph wParagraph = table[0, 0].AddParagraph();
                    wParagraph.ParagraphFormat.AfterSpacing        = 2f;
                    wParagraph.ParagraphFormat.BeforeSpacing       = 2f;
                    wParagraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left;
                    textRange = wParagraph.AppendText("Student’s Name");
                    textRange.CharacterFormat.FontName = "Century Gothic";
                    textRange.CharacterFormat.FontSize = 9;
                    textRange.CharacterFormat.Bold     = true;


                    //Header 2
                    wParagraph = table[0, 1].AddParagraph();
                    wParagraph.ParagraphFormat.AfterSpacing        = 2f;
                    wParagraph.ParagraphFormat.BeforeSpacing       = 2f;
                    wParagraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left;
                    textRange = wParagraph.AppendText("Father's Name");
                    textRange.CharacterFormat.FontName = "Century Gothic";
                    textRange.CharacterFormat.FontSize = 9;
                    textRange.CharacterFormat.Bold     = true;

                    //Header 3
                    wParagraph = table[0, 2].AddParagraph();
                    wParagraph.ParagraphFormat.AfterSpacing        = 2f;
                    wParagraph.ParagraphFormat.BeforeSpacing       = 2f;
                    wParagraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                    textRange = wParagraph.AppendText("This Month");
                    textRange.CharacterFormat.FontName = "Century Gothic";
                    textRange.CharacterFormat.FontSize = 9;
                    textRange.CharacterFormat.Bold     = true;

                    //Header 4
                    wParagraph = table[0, 3].AddParagraph();
                    wParagraph.ParagraphFormat.AfterSpacing        = 2f;
                    wParagraph.ParagraphFormat.BeforeSpacing       = 2f;
                    wParagraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                    textRange = wParagraph.AppendText("Arrears");
                    textRange.CharacterFormat.FontName = "Century Gothic";
                    textRange.CharacterFormat.FontSize = 9;
                    textRange.CharacterFormat.Bold     = true;


                    for (int i = 0; i <= DefaultArray.ToArray().Length - 1; i++)
                    {
                        int         index     = i + 1;
                        IWParagraph Paragraph = table[index, 0].AddParagraph();
                        Paragraph.ParagraphFormat.AfterSpacing        = 2f;
                        Paragraph.ParagraphFormat.BeforeSpacing       = 2f;
                        Paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left;
                        textRange = Paragraph.AppendText(namearray[i].ToString());
                        textRange.CharacterFormat.FontName = "Century Gothic";
                        textRange.CharacterFormat.FontSize = 9;
                        textRange.CharacterFormat.Bold     = false;

                        Paragraph = table[index, 1].AddParagraph();
                        Paragraph.ParagraphFormat.AfterSpacing        = 2f;
                        Paragraph.ParagraphFormat.BeforeSpacing       = 2f;
                        Paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left;
                        textRange = Paragraph.AppendText(Fatherarray[i].ToString());
                        textRange.CharacterFormat.FontName = "Century Gothic";
                        textRange.CharacterFormat.FontSize = 9;
                        textRange.CharacterFormat.Bold     = false;

                        Paragraph = table[index, 2].AddParagraph();
                        Paragraph.ParagraphFormat.AfterSpacing        = 2f;
                        Paragraph.ParagraphFormat.BeforeSpacing       = 2f;
                        Paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                        textRange = Paragraph.AppendText("Rs. " + montharray[i].ToString());
                        textRange.CharacterFormat.FontName = "Century Gothic";
                        textRange.CharacterFormat.FontSize = 9;
                        textRange.CharacterFormat.Bold     = false;

                        Paragraph = table[index, 3].AddParagraph();
                        Paragraph.ParagraphFormat.AfterSpacing        = 2f;
                        Paragraph.ParagraphFormat.BeforeSpacing       = 2f;
                        Paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                        textRange = Paragraph.AppendText("Rs. " + arrearsarray[i].ToString());
                        textRange.CharacterFormat.FontName = "Century Gothic";
                        textRange.CharacterFormat.FontSize = 9;
                        textRange.CharacterFormat.Bold     = false;
                    }


                    //Saves the document in the given name and format

                    string savepath = "DefaulterList-" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".docx";
                    document.Save(savepath, FormatType.Docx);

                    //Releases the resources occupied by WordDocument instance

                    document.Close();

                    PrintWord(System.Windows.Forms.Application.StartupPath + @"\" + savepath, "Microsoft Print to PDF");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString(), "Error - Student Management System", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Beispiel #27
0
        public ActionResult ExportFile(int id)
        {
            try
            {
                //string editor = "";
                //editor = "<table><th>1</th><th>2</th></table>";
                //// Create a unique file name
                //string fileName = Guid.NewGuid() + ".docx";
                //// Convert HTML text to byte array
                //byte[] byteArray = Encoding.UTF8.GetBytes(editor.Contains("<html>") ? editor : "<html>" + editor + "</html>");
                //// Generate Word document from the HTML
                //MemoryStream stream = new MemoryStream(byteArray);
                //Document document = new Document(stream);
                //// Create memory stream for the Word file
                //var outputStream = new MemoryStream();
                //document.Save(outputStream, SaveFormat.Docx);
                //outputStream.Position = 0;
                //// Return generated Word file
                //return File(outputStream, System.Net.Mime.MediaTypeNames.Application.Rtf, fileName);

                Package  package = null;
                DateTime date;
                string   addressFrom = "", addressTo;
                Person   From, To;

                using (ModelDBContainer db = new ModelDBContainer())
                {
                    package = db.Packages.Find(id);
                    From    = package.PersonFrom;
                    To      = package.PersonTo;
                    if (package == null)
                    {
                        throw new Exception("The package was not found");
                    }
                    var maxDate = package.Records.Select(a => a.DateAndTime).Max();
                    date = package.Records.Where(a => a.DateAndTime == maxDate).Single().DateAndTime;
                    if (From.CentreId != null)
                    {
                        DistributionCentre c = db.DistributionCentres.Find(From.CentreId);
                        addressFrom = c.City.Region.Country.NameCountry + ", " + c.City.Region.NameRegion + ", " + c.City.NameCity + ", " + c.Address;
                    }
                    else
                    {
                        addressFrom = From.City.Region.Country.NameCountry + ", " + From.City.Region.NameRegion + ", " + From.City.NameCity + ", " + From.Address;
                    }
                    if (To.CentreId != null)
                    {
                        DistributionCentre c = db.DistributionCentres.Find(To.CentreId);
                        addressTo = c.City.Region.Country.NameCountry + ", " + c.City.Region.NameRegion + ", " + c.City.NameCity + ", " + c.Address;
                    }
                    else
                    {
                        addressTo = To.City.Region.Country.NameCountry + ", " + To.City.Region.NameRegion + ", " + To.City.NameCity + ", " + To.Address;
                    }
                }
                string companyName = Properties.Settings.Default.CompanyName;

                // 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 = 50;
                //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  = Syncfusion.DocIO.OutlineLevel.Level1;
                IWParagraph paragraph = section.AddParagraph();

                paragraph.ApplyStyle("Heading 1");
                paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
                WTextRange textRange = paragraph.AppendText(companyName) as WTextRange;
                textRange.CharacterFormat.FontSize = 14f;
                textRange.CharacterFormat.FontName = "Calibri";

                paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
                textRange = paragraph.AppendText("#" + package.Id) as WTextRange;
                textRange.CharacterFormat.FontSize = 14f;
                textRange.CharacterFormat.FontName = "Calibri";

                paragraph.ApplyStyle("Normal");
                //Appends table.
                IWTable table = section.AddTable();
                table.ResetCells(16, 4);
                table.TableFormat.Borders.BorderType = BorderStyle.Single;
                table.TableFormat.IsAutoResized      = true;

                //Appends paragraph.
                paragraph = table[1, 0].AddParagraph();
                textRange = paragraph.AppendText("ФИО") as WTextRange;
                paragraph = table[2, 0].AddParagraph();
                textRange = paragraph.AppendText("Компания") as WTextRange;
                paragraph = table[3, 0].AddParagraph();
                textRange = paragraph.AppendText("Адрес") as WTextRange;
                paragraph = table[4, 0].AddParagraph();
                textRange = paragraph.AppendText("Телефон") as WTextRange;

                string name1 = (From.Name == null ? "" : From.Name) + " " + (From.MiddleName == null ? "" : From.MiddleName) + " " + (From.Surname == null ? "" : From.Surname);
                paragraph = table[1, 1].AddParagraph();
                textRange = paragraph.AppendText(name1) as WTextRange;
                paragraph = table[2, 1].AddParagraph();
                textRange = paragraph.AppendText(From.Company == null ? "":From.Company) as WTextRange;
                paragraph = table[3, 1].AddParagraph();
                textRange = paragraph.AppendText(addressFrom) as WTextRange;
                paragraph = table[4, 1].AddParagraph();
                textRange = paragraph.AppendText(From.Phone == null ? "" : From.Phone) as WTextRange;

                paragraph = table[6, 0].AddParagraph();
                textRange = paragraph.AppendText("ФИО") as WTextRange;
                paragraph = table[7, 0].AddParagraph();
                textRange = paragraph.AppendText("Компания") as WTextRange;
                paragraph = table[8, 0].AddParagraph();
                textRange = paragraph.AppendText("Адрес") as WTextRange;
                paragraph = table[9, 0].AddParagraph();
                textRange = paragraph.AppendText("Телефон") as WTextRange;

                string name2 = (To.Name == null ? "" : To.Name) + " " + (To.MiddleName == null ? "" : To.MiddleName) + " " + (To.Surname == null ? "" : To.Surname);
                paragraph = table[6, 1].AddParagraph();
                textRange = paragraph.AppendText(name2) as WTextRange;
                paragraph = table[7, 1].AddParagraph();
                textRange = paragraph.AppendText(To.Company == null ? "" : To.Company) as WTextRange;
                paragraph = table[8, 1].AddParagraph();
                textRange = paragraph.AppendText(addressTo) as WTextRange;
                paragraph = table[9, 1].AddParagraph();
                textRange = paragraph.AppendText(To.Phone == null ? "" : To.Phone) as WTextRange;

                paragraph = table[11, 0].AddParagraph();
                textRange = paragraph.AppendText("Дата " + date.ToShortDateString()) as WTextRange;
                paragraph = table[11, 1].AddParagraph();
                textRange = paragraph.AppendText("Время") as WTextRange;
                paragraph = table[12, 1].AddParagraph();
                textRange = paragraph.AppendText("Подпись") as WTextRange;

                paragraph = table[1, 2].AddParagraph();
                textRange = paragraph.AppendText("Объяв.стоимость") as WTextRange;
                paragraph = table[2, 2].AddParagraph();
                textRange = paragraph.AppendText("Описание") as WTextRange;
                paragraph = table[3, 2].AddParagraph();
                textRange = paragraph.AppendText("Вес") as WTextRange;
                paragraph = table[4, 2].AddParagraph();
                textRange = paragraph.AppendText("Размеры") as WTextRange;
                paragraph = table[5, 2].AddParagraph();
                textRange = paragraph.AppendText("Количество") as WTextRange;
                paragraph = table[6, 2].AddParagraph();
                textRange = paragraph.AppendText("Стоимость") as WTextRange;
                paragraph = table[7, 2].AddParagraph();
                textRange = paragraph.AppendText("Курьер") as WTextRange;
                paragraph = table[7, 3].AddParagraph();
                textRange = paragraph.AppendText("Подпись") as WTextRange;

                paragraph = table[1, 3].AddParagraph();
                textRange = paragraph.AppendText(package.DeclaredValue == null ? "" : (package.DeclaredValue.ToString() + " руб")) as WTextRange;
                paragraph = table[2, 3].AddParagraph();
                textRange = paragraph.AppendText(package.Description) as WTextRange;
                paragraph = table[3, 3].AddParagraph();
                textRange = paragraph.AppendText(package.Weight.ToString() + " кг") as WTextRange;
                paragraph = table[4, 3].AddParagraph();
                textRange = paragraph.AppendText(package.Width + "*" + package.Length + "*" + package.Height + " см") as WTextRange;
                paragraph = table[5, 3].AddParagraph();
                textRange = paragraph.AppendText(package.NumberOfPackages.ToString()) as WTextRange;
                paragraph = table[6, 3].AddParagraph();
                textRange = paragraph.AppendText(package.Cost == null ? "" : (package.Cost.ToString() + " руб")) as WTextRange;

                paragraph = table[15, 2].AddParagraph();
                textRange = paragraph.AppendText("Дата        Время") as WTextRange;
                paragraph = table[15, 3].AddParagraph();
                textRange = paragraph.AppendText("Подпись") as WTextRange;
                paragraph = table[14, 2].AddParagraph();
                textRange = paragraph.AppendText("Получатель(ФИО)") as WTextRange;

                paragraph = table[0, 0].AddParagraph();
                textRange = paragraph.AppendText("Отправитель") as WTextRange; textRange.CharacterFormat.Bold = true;
                paragraph = table[5, 0].AddParagraph();
                textRange = paragraph.AppendText("Получатель") as WTextRange; textRange.CharacterFormat.Bold = true;
                paragraph = table[13, 0].AddParagraph();
                textRange = paragraph.AppendText("Примечания") as WTextRange; textRange.CharacterFormat.Bold = true;
                paragraph = table[0, 2].AddParagraph();
                textRange = paragraph.AppendText("Информация об отправлении") as WTextRange; textRange.CharacterFormat.Bold = true;
                paragraph = table[13, 2].AddParagraph();
                textRange = paragraph.AppendText("Подтверждение доставки") as WTextRange; textRange.CharacterFormat.Bold = true;

                //Specifies the horizontal merge
                table.ApplyHorizontalMerge(0, 0, 1);
                table.ApplyHorizontalMerge(5, 0, 1);
                table.ApplyHorizontalMerge(13, 0, 1);
                table.ApplyHorizontalMerge(0, 2, 3);
                table.ApplyHorizontalMerge(13, 2, 3);

                //Appends paragraph.
                section.AddParagraph();

                //Saves the Word document to  MemoryStream
                MemoryStream stream = new MemoryStream();
                document.Save(stream, FormatType.Docx);
                stream.Position = 0;
                string fileName = Guid.NewGuid() + ".docx";
                //Download Word document in the browser
                return(File(stream, "application/msword", fileName));
            }
            catch (Exception exp)
            {
                TempData["alertMessage"] = "Произошла ошибка при создании файла. Возможно не хватает информации об отправлении.";
                return(RedirectToAction("Index"));
            }
        }