Exemple #1
0
        public async Task GenerateReports()
        {
            Assembly     assembly = typeof(CreateInvoicePageViewModel).GetTypeInfo().Assembly;
            WordDocument document = new WordDocument();

            WSection    section   = document.AddSection() as WSection;
            IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph();

            paragraph.AppendText("Testing paragraph header");
            paragraph = section.AddParagraph();
            paragraph.AppendText("Hi again.");

            MemoryStream stream = new MemoryStream();

            document.Save(stream, FormatType.Word2010);
            document.Close();

            if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows)
            {
                await DependencyService.Get <ISaveWindowsPhone>().Save("SQReportTest.docx", "application/msword", stream);
            }
            else
            {
                DependencyService.Get <ISave>().Save("SQReportTest.docx", "application/msword", stream);
            }
        }
        /// <summary>
        /// Creates word document with built - in styles
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                WordDocument document = new WordDocument();
                WSection     section  = document.AddSection() as WSection;
                WParagraph   para     = section.AddParagraph() as WParagraph;
                section.AddColumn(100, 100);
                section.AddColumn(100, 100);
                section.MakeColumnsEqual();

                #region Built-in styles
                # region List Style

                //List
                para.AppendText("This para is written with style List").CharacterFormat.UnderlineStyle = UnderlineStyle.Double;
                para = section.AddParagraph() as WParagraph;
                para.ApplyStyle(BuiltinStyle.List);
                para.AppendText("Google Chrome\n");
                para.AppendText("Mozilla Firefox\n");
                para.AppendText("Internet Explorer");

                //List5 style
                para = section.AddParagraph() as WParagraph;
                para.AppendText("\nThis para is written with style List5").CharacterFormat.UnderlineStyle = UnderlineStyle.Double;
                para = section.AddParagraph() as WParagraph;
                para.ApplyStyle(BuiltinStyle.List5);
                para.AppendText("Google Chrome\n");
                para.AppendText("Mozilla Firefox\n");
                para.AppendText("Internet Explorer");

                # endregion

                # region ListNumber Style
Exemple #3
0
        public void Open(string filename)
        {
            m_document = new WordDocument();

            Stream fileStream = Utils.OpenFile(filename);

            fileStream.Position = 0;

            m_document.Open(fileStream, FormatType.Word2013);

            if (m_document.Sections.Count == 0)
            {
                m_section = m_document.AddSection() as WSection;
                m_section.PageSetup.Margins.All = m_margins;
            }
            else
            {
                m_section = m_document.Sections[0];
                m_margins = m_section.PageSetup.Margins.All;
            }
            if (m_section.Paragraphs.Count == 0)
            {
                m_paragraph = m_section.AddParagraph();
            }
            else
            {
                m_paragraph = m_section.Paragraphs[0];
            }

            fileStream.Close();
        }
Exemple #4
0
 public Word(Stream fileInput, string fileNameOutput)
 {
     Response            = HttpContext.Current.Response;
     this.fileNameOutput = fileNameOutput;
     Document            = new WordDocument(fileInput, FormatType.Docx);
     Section             = Document.LastSection;
     GetAllTemplate();
 }
Exemple #5
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();
        }
Exemple #6
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;
            }
        }
Exemple #7
0
        private async void StileOpzioniTabellaWordAsync()
        {
            //Crea una istanza della classe WordDocument
            WordDocument document = new WordDocument();
            //Aggiunge una sezione ad un documento word
            IWSection sectionFirst = document.AddSection();
            //Aggiunge una tabella ad un documento word
            IWTable tableFirst = sectionFirst.AddTable();

            //Dimensiona la tabella
            tableFirst.ResetCells(3, 2);
            //Salva il documento su memory stream
            MemoryStream stream = new MemoryStream();
            await document.SaveAsync(stream, FormatType.Docx);

            document.Open(stream, FormatType.Docx);

            WSection section = document.Sections[0];

            WTable table = section.Tables[0] as WTable;

            //Applica alla tabella lo stile built-in "LightShading"
            table.ApplyStyle(BuiltinTableStyle.LightShading);

            //Abilita una formattazione speciale per le banded columns della tabella
            table.ApplyStyleForBandedColumns = true;

            //Abilita una formattazione speciale per le banded rows of the table
            table.ApplyStyleForBandedRows = true;

            //Disabilita la formattazione speciale per la prima colonna della tabella
            table.ApplyStyleForFirstColumn = false;

            //Abilita una formattazione speciale per la riga di testata della tabella
            table.ApplyStyleForHeaderRow = true;

            //Abilita una formattazione speciale per l'ultima colonna della tabella
            table.ApplyStyleForLastColumn = true;

            //Disabilita la formattazione speciale per l'ultima riga della tabella
            table.ApplyStyleForLastRow = false;

            //Salva e chiudi l'istanza del documento
            //Salva il documento su memory stream
            MemoryStream memoryStream = new MemoryStream();
            await document.SaveAsync(memoryStream, FormatType.Docx);

            //Libera le risorse impegnate dall'istanza WordDocument
            document.Close();

            //Salva lo stream come file di documento Word nella macchina locale
            StorageFile stFile = await Save(memoryStream, "TableStyle.docx");

            DefaultLaunch("TableStyle.docx");
        }
Exemple #8
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());
            }
        }
Exemple #9
0
        void Init()
        {
            if (m_document != null)
            {
                return;
            }
            //Fake(); return;
            m_document = new WordDocument();
            m_section  = m_document.AddSection() as WSection;
            m_section.PageSetup.Margins.All = m_margins;

            AddStyles();
        }
Exemple #10
0
 static void Main(string[] args)
 {
     using (WordDocument document = new WordDocument())
     {
         document.EnsureMinimal();
         document.LastSection.PageSetup.Margins.All = 72;
         WParagraph para = document.LastParagraph;
         para.AppendText("Essential DocIO - Table of Contents");
         para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
         para.ApplyStyle(BuiltinStyle.Heading4);
         para = document.LastSection.AddParagraph() as WParagraph;
         //Creates the new custom styles.
         WParagraphStyle pStyle1 = (WParagraphStyle)document.AddParagraphStyle("MyStyle1");
         pStyle1.CharacterFormat.FontSize = 18f;
         WParagraphStyle pStyle2 = (WParagraphStyle)document.AddParagraphStyle("MyStyle2");
         pStyle2.CharacterFormat.FontSize = 16f;
         WParagraphStyle pStyle3 = (WParagraphStyle)document.AddParagraphStyle("MyStyle3");
         pStyle3.CharacterFormat.FontSize = 14f;
         para = document.LastSection.AddParagraph() as WParagraph;
         //Insert TOC field in the Word document.
         TableOfContent toc = para.AppendTOC(1, 3);
         //Sets the Heading Styles to false, to define custom levels for TOC.
         toc.UseHeadingStyles = false;
         //Sets the TOC level style which determines; based on which the TOC should be created.
         toc.SetTOCLevelStyle(1, "MyStyle1");
         toc.SetTOCLevelStyle(2, "MyStyle2");
         toc.SetTOCLevelStyle(3, "MyStyle3");
         //Adds content to the Word document with custom styles.
         WSection   section = document.LastSection;
         WParagraph newPara = section.AddParagraph() as WParagraph;
         newPara.AppendBreak(BreakType.PageBreak);
         AddHeading(section, "MyStyle1", "Document with custom styles", "This is the 1st custom style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can insert TOC field in a word document. It can refresh or update TOC field by using UpdateTableOfContents method. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC.");
         AddHeading(section, "MyStyle2", "Section 1", "This is the 2nd custom style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");
         AddHeading(section, "MyStyle3", "Paragraph 1", "This is the 3rd custom style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text.");
         AddHeading(section, "MyStyle3", "Paragraph 2", "This is the 3rd custom style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph.");
         AddHeading(section, "Normal", "Paragraph with normal", "This is the paragraph with normal style. This demonstrates the paragraph with outline level 4 and normal style. This can be attained by formatting outline level of the paragraph.");
         //Adds a new section to the Word document.
         section = document.AddSection() as WSection;
         section.PageSetup.Margins.All = 72;
         section.BreakCode             = SectionBreakCode.NewPage;
         AddHeading(section, "MyStyle2", "Section 2", "This is the 2nd custom style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");
         AddHeading(section, "MyStyle3", "Paragraph 1", "This is the 3rd custom style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text.");
         AddHeading(section, "MyStyle3", "Paragraph 2", "This is the 3rd custom style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph.");
         //Updates the table of contents.
         document.UpdateTableOfContents();
         //Saves the file in the given path
         Stream docStream = File.Create(Path.GetFullPath(@"../../../TOC-custom-style.docx"));
         document.Save(docStream, FormatType.Docx);
         docStream.Dispose();
     }
 }
        /// <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";
        }
Exemple #12
0
 public Word(string fileUrl, string fileNameOutput)
 {
     Response            = HttpContext.Current.Response;
     this.fileNameOutput = fileNameOutput;
     Document            = new WordDocument(fileUrl, FormatType.Docx);
     Section             = Document.LastSection;
     GetAllTemplate();
     //Response = HttpContext.Current.Response;
     //this.fileNameOutput = fileNameOutput;
     //MemoryStream stream = GetFileStreamFromUrl(fileUrl);
     //Document = new WordDocument(stream, FormatType.Docx);
     //Section = Document.LastSection;
     //GetAllTemplate();
 }
Exemple #13
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            WordDocument document = new WordDocument();

            WSection section = document.AddSection() as WSection;

            //Set Margin of the section
            section.PageSetup.Margins.All = 72;
            WParagraph para = section.AddParagraph() as WParagraph;

            section.AddColumn(100, 100);
            section.AddColumn(100, 100);
            section.MakeColumnsEqual();

            #region Built-in styles
            # region List Style
Exemple #14
0
        void OnButtonClicked(object sender, EventArgs e)
        {
            // Creating a new document.
            WordDocument document = new WordDocument();

            WSection section = document.AddSection() as WSection;

            //Set Margin of the section
            section.PageSetup.Margins.All = 72;
            WParagraph para = section.AddParagraph() as WParagraph;

            section.AddColumn(100, 100);
            section.AddColumn(100, 100);
            section.MakeColumnsEqual();

            #region Built-in styles
            # region List Style
Exemple #15
0
        private async void StileTabellaWordAsync()
        {
            //Crea una istanza della classe WordDocument
            WordDocument document = new WordDocument();

            //Apre un documento word esistente nella istanza DocIO
            //document.Open("Table.docx", FormatType.Docx);
            StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
            StorageFile   storageFile;

            try
            {
                storageFile = await local.GetFileAsync("Table.docx");
            }
            catch (Exception)
            {
                return;
            }
            var streamFile = await storageFile.OpenStreamForReadAsync();

            document.Open(streamFile, FormatType.Docx);

            WSection section = document.Sections[0];

            WTable table = section.Tables[0] as WTable;

            //Applica alla tabella lo stile built-in "LightShading"
            table.ApplyStyle(BuiltinTableStyle.LightShading);

            //Salva e chiudi l'istanza del documento
            //Salva il documento su memory stream
            MemoryStream stream = new MemoryStream();
            await document.SaveAsync(stream, FormatType.Docx);

            //Libera le risorse impegnate dall'istanza WordDocument
            document.Close();

            //Salva lo stream come file di documento Word nella macchina locale
            StorageFile stFile = await Save(stream, "TableStyle.docx");

            DefaultLaunch("TableStyle.docx");
        }
Exemple #16
0
 static void Main(string[] args)
 {
     using (WordDocument document = new WordDocument())
     {
         document.EnsureMinimal();
         document.LastSection.PageSetup.Margins.All = 72;
         WParagraph para = document.LastParagraph;
         para.AppendText("Essential DocIO - Table of Contents");
         para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
         para.ApplyStyle(BuiltinStyle.Heading4);
         para = document.LastSection.AddParagraph() as WParagraph;
         para = document.LastSection.AddParagraph() as WParagraph;
         //Insert TOC field in the Word document.
         TableOfContent toc = para.AppendTOC(1, 3);
         //Sets the heading levels 1 to 3, to include in TOC.
         toc.LowerHeadingLevel = 1;
         toc.UpperHeadingLevel = 3;
         //Adds content to the Word document with built-in heading styles.
         WSection   section = document.LastSection;
         WParagraph newPara = section.AddParagraph() as WParagraph;
         newPara.AppendBreak(BreakType.PageBreak);
         AddHeading(section, BuiltinStyle.Heading1, "Document with built-in heading styles", "This is the built-in heading 1 style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can insert TOC field in a word document. It can refresh or update TOC field by using UpdateTableOfContents method. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC.");
         AddHeading(section, BuiltinStyle.Heading2, "Section 1", "This is the built-in heading 2 style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");
         AddHeading(section, BuiltinStyle.Heading3, "Paragraph 1", "This is the built-in heading 3 style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text.");
         AddHeading(section, BuiltinStyle.Heading3, "Paragraph 2", "This is the built-in heading 3 style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph.");
         //Adds a new section to the Word document.
         section = document.AddSection() as WSection;
         section.PageSetup.Margins.All = 72;
         section.BreakCode             = SectionBreakCode.NewPage;
         AddHeading(section, BuiltinStyle.Heading2, "Section 2", "This is the built-in heading 2 style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");
         AddHeading(section, BuiltinStyle.Heading3, "Paragraph 1", "This is the built-in heading 3 style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text.");
         AddHeading(section, BuiltinStyle.Heading3, "Paragraph 2", "This is the built-in heading 3 style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph.");
         //Updates the table of contents.
         document.UpdateTableOfContents();
         //Saves the file in the given path
         Stream docStream = File.Create(Path.GetFullPath(@"../../../TOC-creation.docx"));
         document.Save(docStream, FormatType.Docx);
         docStream.Dispose();
     }
 }
        public ActionResult Styles(string Group1, string Group2)
        {
            if (Group1 == null)
            {
                return(View());
            }
            WordDocument document = null;

            #region Built-in Style
            if (Group1 == "Built-in")
            {
                document = new WordDocument();
                WSection   section = document.AddSection() as WSection;
                WParagraph para    = section.AddParagraph() as WParagraph;

                section.AddColumn(100, 100);
                section.AddColumn(100, 100);
                section.MakeColumnsEqual();

                # region List Style
                //List
                //para = section.AddParagraph() as WParagraph;
                para.AppendText("This para is written with style List").CharacterFormat.UnderlineStyle = UnderlineStyle.Double;
                para = section.AddParagraph() as WParagraph;
                para.ApplyStyle(BuiltinStyle.List);
                para.AppendText("Google Chrome\n");
                para.AppendText("Mozilla Firefox\n");
                para.AppendText("Internet Explorer");

                //List5 style
                para = section.AddParagraph() as WParagraph;
                para.AppendText("\nThis para is written with style List5").CharacterFormat.UnderlineStyle = UnderlineStyle.Double;
                para = section.AddParagraph() as WParagraph;
                para.ApplyStyle(BuiltinStyle.List5);
                para.AppendText("Google Chrome\n");
                para.AppendText("Mozilla Firefox\n");
                para.AppendText("Internet Explorer");
                # endregion

                # region ListNumber Style
        void OnButtonClicked(object sender, EventArgs e)
        {
            Assembly assembly = typeof(CreateEquation).GetTypeInfo().Assembly;

#if COMMONSB
            string rootPath = "SampleBrowser.Samples.DocIO.Samples.Templates.";
#else
            string rootPath = "SampleBrowser.DocIO.Samples.Templates.";
#endif
            Stream inputStream = assembly.GetManifestResourceStream(rootPath + "CreateEquation.docx");

            // Loads the stream into Word Document.
            WordDocument document = new WordDocument(inputStream, Syncfusion.DocIO.FormatType.Automatic);
            //Gets the last section in the document
            WSection section = document.LastSection;
            //Sets page margins
            document.LastSection.PageSetup.Margins.All = 72;
            //Adds new paragraph to the section
            IWParagraph paragraph = section.AddParagraph();

            //Appends text to paragraph
            IWTextRange textRange = paragraph.AppendText("Mathematical equations");
            textRange.CharacterFormat.FontSize            = 28;
            paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
            paragraph.ParagraphFormat.AfterSpacing        = 12;

            #region Sum to the power of n
            //Adds new paragraph to the section
            paragraph = AddParagraph(section, "This is an expansion of the sum (1+X) to the power of n.");
            //Creates an equation with sum to the power of N
            CreateSumToThePowerOfN(paragraph);
            #endregion

            #region Fourier series
            //Adds new paragraph to the section
            paragraph = AddParagraph(section, "This is a Fourier series for the function of period 2L");
            //Creates a Fourier series equation
            CreateFourierseries(paragraph);
            #endregion

            #region Triple scalar product
            //Adds new paragraph to the section
            paragraph = AddParagraph(section, "This is an expansion of triple scalar product");
            //Creates a triple scalar product equation
            CreateTripleScalarProduct(paragraph);
            #endregion

            #region Gamma function
            //Adds new paragraph to the section
            paragraph = AddParagraph(section, "This is an expansion of gamma function");
            //Creates a gamma function equation
            CreateGammaFunction(paragraph);
            #endregion

            #region Vector relation
            //Adds new paragraph to the section
            paragraph = AddParagraph(section, "This is an expansion of vector relation ");
            //Creates a vector relation equation
            CreateVectorRelation(paragraph);
            #endregion

            string       filename     = "";
            string       contenttype  = "";
            MemoryStream outputStream = new MemoryStream();
            if (this.pdfButton.IsChecked != null && (bool)this.pdfButton.IsChecked)
            {
                filename    = "CreateEquation.pdf";
                contenttype = "application/pdf";
                DocIORenderer renderer = new DocIORenderer();
                PdfDocument   pdfDoc   = renderer.ConvertToPDF(document);
                pdfDoc.Save(outputStream);
                pdfDoc.Close();
            }
            else
            {
                filename    = "CreateEquation.docx";
                contenttype = "application/msword";
                document.Save(outputStream, FormatType.Docx);
            }
            document.Close();

            if (Device.RuntimePlatform == Device.UWP)
            {
                Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save(filename, contenttype, outputStream);
            }
            else
            {
                Xamarin.Forms.DependencyService.Get <ISave>().Save(filename, contenttype, outputStream);
            }
        }
Exemple #19
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);
            }
        }
        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());
                    }
                }
            }
        }
Exemple #21
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);
            }
        }
        void OnButtonClicked(object sender, EventArgs e)
        {
            WordDocument doc = new WordDocument();

            doc.EnsureMinimal();

            WParagraph para = doc.LastParagraph;

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

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

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

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

            para.ApplyStyle(BuiltinStyle.Heading4);

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

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

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

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

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

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

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

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

            toc.IncludePageNumbers    = true;
            toc.RightAlignPageNumbers = true;
            toc.UseHyperlinks         = true;
            toc.LowerHeadingLevel     = 1;
            toc.UpperHeadingLevel     = 3;

            toc.UseOutlineLevels = true;

            //Updates the table of contents.
            doc.UpdateTableOfContents();
            string       filename     = "";
            string       contenttype  = "";
            MemoryStream outputStream = new MemoryStream();
            if (pdfButton != null && (bool)pdfButton.IsChecked)
            {
                filename    = "Table Of Contents.pdf";
                contenttype = "application/pdf";
                DocIORenderer renderer = new DocIORenderer();
                PdfDocument   pdfDoc   = renderer.ConvertToPDF(doc);
                pdfDoc.Save(outputStream);
                pdfDoc.Close();
            }
            else
            {
                filename    = "Table Of Contents.docx";
                contenttype = "application/msword";
                doc.Save(outputStream, FormatType.Docx);
            }

            doc.Close();
            if (Device.RuntimePlatform == Device.UWP)
            {
                DependencyService.Get <ISaveWindowsPhone>()
                .Save(filename, contenttype, outputStream);
            }
            else
            {
                DependencyService.Get <ISave>().Save(filename, contenttype, outputStream);
            }
        }
        void OnButtonClicked(object sender, EventArgs e)
        {
            string   resourcePath = "SampleBrowser.Samples.DocIO.Templates.CreateEquation.docx";
            Assembly assembly     = Assembly.GetExecutingAssembly();
            Stream   fileStream   = assembly.GetManifestResourceStream(resourcePath);

            // Loads the stream into Word Document.
            WordDocument document = new WordDocument(fileStream, Syncfusion.DocIO.FormatType.Automatic);
            //Gets the last section in the document
            WSection section = document.LastSection;

            //Sets page margins
            document.LastSection.PageSetup.Margins.All = 72;
            //Adds new paragraph to the section
            IWParagraph paragraph = section.AddParagraph();

            //Appends text to paragraph
            IWTextRange textRange = paragraph.AppendText("Mathematical equations");

            textRange.CharacterFormat.FontSize            = 28;
            paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
            paragraph.ParagraphFormat.AfterSpacing        = 12;

            #region Sum to the power of n
            //Adds new paragraph to the section
            paragraph = AddParagraph(section, "This is an expansion of the sum (1+X) to the power of n.");
            //Creates an equation with sum to the power of N
            CreateSumToThePowerOfN(paragraph);
            #endregion

            #region Fourier series
            //Adds new paragraph to the section
            paragraph = AddParagraph(section, "This is a Fourier series for the function of period 2L");
            //Creates a Fourier series equation
            CreateFourierseries(paragraph);
            #endregion

            #region Triple scalar product
            //Adds new paragraph to the section
            paragraph = AddParagraph(section, "This is an expansion of triple scalar product");
            //Creates a triple scalar product equation
            CreateTripleScalarProduct(paragraph);
            #endregion

            #region Gamma function
            //Adds new paragraph to the section
            paragraph = AddParagraph(section, "This is an expansion of gamma function");
            //Creates a gamma function equation
            CreateGammaFunction(paragraph);
            #endregion

            #region Vector relation
            //Adds new paragraph to the section
            paragraph = AddParagraph(section, "This is an expansion of vector relation ");
            //Creates a vector relation equation
            CreateVectorRelation(paragraph);
            #endregion

            MemoryStream stream = new MemoryStream();
            //Set file content type
            string contentType = null;
            string fileName    = null;
            if (docxButton.Checked)
            {
                fileName    = "CreateEquation.docx";
                contentType = "application/msword";
                document.Save(stream, FormatType.Docx);
            }
            else
            {
                fileName    = "CreateEquation.pdf";
                contentType = "application/pdf";
                DocIORenderer renderer = new DocIORenderer();
                PdfDocument   pdfDoc   = renderer.ConvertToPDF(document);
                pdfDoc.Save(stream);

                pdfDoc.Close();
            }

            document.Dispose();
            if (stream != null)
            {
                SaveAndroid androidSave = new SaveAndroid();
                androidSave.Save(fileName, contentType, stream, m_context);
            }
        }
Exemple #24
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);
        }
Exemple #25
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);
            }
        }
Exemple #26
0
        //Exporting data to word
        public void ExportToWord()
        {
            //A new document is created.
            WordDocument document = new WordDocument();

            //Adding new table to the document
            WTable doctable = new WTable(document);

            //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(800, 792);

            //Create Paragraph styles
            WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle;

            style.CharacterFormat.FontName = "Calibri";
            style.CharacterFormat.FontSize = 11f;

            WCharacterFormat charFormat = new WCharacterFormat(document);

            charFormat.TextColor = System.Drawing.Color.White;
            charFormat.Bold      = true;

            doctable.AddRow(true, false);
            WTableCell cell = new WTableCell(document);

            cell.AddParagraph().AppendText("Customer Id").ApplyCharacterFormat(charFormat);
            cell.Width = 90;
            doctable.Rows[0].Cells.Add(cell);
            cell = new WTableCell(document);
            cell.AddParagraph().AppendText("Full Name").ApplyCharacterFormat(charFormat);
            cell.Width = 90;
            doctable.Rows[0].Cells.Add(cell);
            cell = new WTableCell(document);
            cell.AddParagraph().AppendText("Age").ApplyCharacterFormat(charFormat);
            cell.Width = 90;
            doctable.Rows[0].Cells.Add(cell);
            cell = new WTableCell(document);
            cell.AddParagraph().AppendText("Email Id").ApplyCharacterFormat(charFormat);
            cell.Width = 180;
            doctable.Rows[0].Cells.Add(cell);
            cell = new WTableCell(document);
            cell.AddParagraph().AppendText("Phone Number").ApplyCharacterFormat(charFormat);
            cell.Width = 90;
            doctable.Rows[0].Cells.Add(cell);
            cell = new WTableCell(document);
            cell.AddParagraph().AppendText("Modified Date").ApplyCharacterFormat(charFormat);
            cell.Width = 90;
            doctable.Rows[0].Cells.Add(cell);

            //Reading each row from the fetched result
            for (int i = 0; i < result.Count(); i++)
            {
                HiveRecord records = result[i];
                doctable.AddRow(true, false);

                //Reading each field from the row
                for (int j = 0; j < records.Count; j++)
                {
                    Object fields = records[j];

                    //Adding new cell to the document
                    cell = new WTableCell(document);

                    //Adding each field to the cell
                    cell.AddParagraph().AppendText(fields.ToString());
                    if (j == 3)
                    {
                        cell.Width = 180;
                    }
                    else
                    {
                        cell.Width = 90;
                    }

                    //Adding cell to the table
                    doctable.Rows[i + 1].Cells.Add(cell);
                    doctable.Rows[0].Cells[j].CellFormat.BackColor = System.Drawing.Color.FromArgb(51, 153, 51);
                }
            }

            //Adding table to the section
            section.Tables.Add(doctable);
            //Save as word 2003 format
            if (rdbWord2003.IsChecked.Value)
            {
                //Saving the document to disk.
                document.Save("Sample.doc");

                //Message box confirmation to view the created document.
                if (MessageBox.Show("Do you want to view the MS Word document?", "Document has been created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                {
                    //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
                    System.Diagnostics.Process.Start("Sample.doc");
                    //Exit
                    this.Close();
                }
            }
            //Save as word 2007 format
            else if (rdbWord2007.IsChecked.Value)
            {
                //Saving the document as .docx
                document.Save("Sample.docx", FormatType.Word2007);
                //Message box confirmation to view the created document.
                if (MessageBox.Show("Do you want to view the MS Word document?", "Document has been created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                {
                    try
                    {
                        //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
                        System.Diagnostics.Process.Start("Sample.docx");
                        //Exit
                        this.Close();
                    }
                    catch (Win32Exception ex)
                    {
                        MessageBox.Show("Word 2007 is not installed in this system");
                        Console.WriteLine(ex.ToString());
                    }
                }
            }
            //Save as word 2010  format
            else if (rdbWord2010.IsChecked.Value)
            {
                //Saving the document as .docx
                document.Save("Sample.docx", FormatType.Word2010);
                //Message box confirmation to view the created document.
                if (MessageBox.Show("Do you want to view the MS Word document?", "Document has been created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                {
                    try
                    {
                        //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
                        System.Diagnostics.Process.Start("Sample.docx");
                        //Exit
                        this.Close();
                    }
                    catch (Win32Exception ex)
                    {
                        MessageBox.Show("Word 2010 is not installed in this system");
                        Console.WriteLine(ex.ToString());
                    }
                }
            }
            //Save as word 2013  format
            else if (rdbWord2013.IsChecked.Value)
            {
                //Saving the document as .docx
                document.Save("Sample.docx", FormatType.Word2013);
                //Message box confirmation to view the created document.
                if (MessageBox.Show("Do you want to view the MS Word document?", "Document has been created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                {
                    try
                    {
                        //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
                        System.Diagnostics.Process.Start("Sample.docx");
                        //Exit
                        this.Close();
                    }
                    catch (Win32Exception ex)
                    {
                        MessageBox.Show("Word 2013 is not installed in this system");
                        Console.WriteLine(ex.ToString());
                    }
                }
            }
            else
            {
                // Exit
                this.Close();
            }
        }
Exemple #27
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            ErrorMessage.InnerText = "";
            if (hdnGroup.Value == "Word")
            {
                CheckFileStatus FileStatus = new CheckFileStatus();
                string          path       = string.Format("{0}\\..\\Data\\AdventureWorks\\AdventureWorks_Person_Contact.csv", Request.PhysicalPath.ToLower().Split(new string[] { "\\c# hive samples" }, StringSplitOptions.None));
                ErrorMessage.InnerText = FileStatus.CheckFile(path);
                if (ErrorMessage.InnerText == "")
                {
                    try
                    {
                        //Create a new document
                        WordDocument document = new WordDocument();

                        //Adding new table to the document
                        WTable doctable = new WTable(document);

                        //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(800, 792);

                        //Create Paragraph styles
                        WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle;
                        style.CharacterFormat.FontName = "Calibri";
                        style.CharacterFormat.FontSize = 11f;

                        //Create a character format for declaring font color and style for the text inside the cell
                        WCharacterFormat charFormat = new WCharacterFormat(document);
                        charFormat.TextColor = System.Drawing.Color.White;
                        charFormat.Bold      = true;

                        //Initializing the hive server connection
                        HqlConnection con = new HqlConnection("localhost", 10000, HiveServer.HiveServer2);

                        //To initialize a Hive server connection with secured cluster
                        //HqlConnection con = new HqlConnection("<Secured cluster Namenode IP>", 10000, HiveServer.HiveServer2,"<username>","<password>");

                        //To initialize a Hive server connection with Azure cluster
                        //HqlConnection con = new HqlConnection("<FQDN name of Azure cluster>", 8004, HiveServer.HiveServer2,"<username>","<password>");

                        con.Open();

                        //Create table for adventure person contacts
                        HqlCommand createCommand = new HqlCommand("CREATE EXTERNAL TABLE IF NOT EXISTS AdventureWorks_Person_Contact(ContactID int,FullName string,Age int,EmailAddress string,PhoneNo string,ModifiedDate string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' LOCATION '/Data/AdventureWorks'", con);
                        createCommand.ExecuteNonQuery();
                        HqlCommand command = new HqlCommand("Select * from AdventureWorks_Person_Contact", con);

                        //Executing the query
                        HqlDataReader reader = command.ExecuteReader();
                        reader.FetchSize = 100;

                        //Fetches the result from the reader and store it in HiveResultSet
                        HiveResultSet result = reader.FetchResult();

                        //Adding headertext for the table
                        doctable.AddRow(true, false);
                        //Creating new cell
                        WTableCell cell = new WTableCell(document);
                        cell.AddParagraph().AppendText("Customer Id").ApplyCharacterFormat(charFormat);
                        cell.Width = 75;
                        //Adding cell to the row
                        doctable.Rows[0].Cells.Add(cell);
                        cell = new WTableCell(document);
                        cell.AddParagraph().AppendText("Full Name").ApplyCharacterFormat(charFormat);
                        cell.Width = 75;
                        doctable.Rows[0].Cells.Add(cell);
                        cell = new WTableCell(document);
                        cell.AddParagraph().AppendText("Age").ApplyCharacterFormat(charFormat);
                        cell.Width = 75;
                        doctable.Rows[0].Cells.Add(cell);
                        cell = new WTableCell(document);
                        cell.AddParagraph().AppendText("Email Id").ApplyCharacterFormat(charFormat);
                        cell.Width = 75;
                        doctable.Rows[0].Cells.Add(cell);
                        cell = new WTableCell(document);
                        cell.AddParagraph().AppendText("Phone Number").ApplyCharacterFormat(charFormat);
                        cell.Width = 75;
                        doctable.Rows[0].Cells.Add(cell);
                        cell = new WTableCell(document);
                        cell.AddParagraph().AppendText("Modified Date").ApplyCharacterFormat(charFormat);
                        cell.Width = 75;
                        doctable.Rows[0].Cells.Add(cell);

                        //Reading each row from the fetched result
                        for (int i = 0; i < result.Count(); i++)
                        {
                            HiveRecord records = result[i];
                            doctable.AddRow(true, false);

                            //Reading each data from the row
                            for (int j = 0; j < records.Count; j++)
                            {
                                Object fields = records[j];

                                //Adding new cell to the document
                                cell = new WTableCell(document);

                                //Adding each data to the cell
                                cell.AddParagraph().AppendText(fields.ToString());
                                cell.Width = 75;

                                //Adding cell to the table
                                doctable.Rows[i + 1].Cells.Add(cell);
                                doctable.Rows[0].Cells[j].CellFormat.BackColor = Color.FromArgb(51, 153, 51);
                            }
                        }
                        //Adding table to the section
                        section.Tables.Add(doctable);
                        //Save as word 2007 format
                        if (rBtnWord2003.Checked == true)
                        {
                            document.Save("Sample.doc", FormatType.Doc, Response, HttpContentDisposition.Attachment);
                        }
                        else if (rBtnWord2007.Checked == true)
                        {
                            document.Save("Sample.docx", FormatType.Word2007, Response, HttpContentDisposition.Attachment);
                        }
                        //Save as word 2010 format
                        else if (rbtnWord2010.Checked == true)
                        {
                            document.Save("Sample.docx", FormatType.Word2010, Response, HttpContentDisposition.Attachment);
                        }
                        //Save as word 2013 format
                        else if (rbtnWord2013.Checked == true)
                        {
                            document.Save("Sample.docx", FormatType.Word2013, Response, HttpContentDisposition.Attachment);
                        }

                        //Closing the hive connection
                        con.Close();
                    }
                    catch (HqlConnectionException)
                    {
                        ErrorMessage.InnerText = "Could not establish a connection to the HiveServer. Please run HiveServer2 from the Syncfusion service manager dashboard.";
                    }
                }
            }
            else if (hdnGroup.Value == "Excel")
            {
                ErrorMessage.InnerText = "";
                CheckFileStatus FileStatus = new CheckFileStatus();
                string          path       = string.Format("{0}\\..\\Data\\AdventureWorks\\AdventureWorks_Person_Contact.csv", Request.PhysicalPath.ToLower().Split(new string[] { "\\c# hive samples" }, StringSplitOptions.None));
                ErrorMessage.InnerText = FileStatus.CheckFile(path);
                if (ErrorMessage.InnerText == "")
                {
                    try
                    {
                        //Instantiate the spreadsheet creation engine.
                        ExcelEngine excelEngine = new ExcelEngine();

                        //Instantiate the excel application object.
                        IApplication application = excelEngine.Excel;

                        //A new workbook is created.[Equivalent to creating a new workbook in MS Excel]
                        //The new workbook will have 1 worksheets
                        IWorkbook workbook = application.Workbooks.Create(1);

                        //The first worksheet object in the worksheets collection is accessed.
                        IWorksheet worksheet = workbook.Worksheets[0];

                        //Adding header text for worksheet
                        worksheet[1, 1].Text = "ContactID";
                        worksheet[1, 2].Text = "FullName";
                        worksheet[1, 3].Text = "Age";
                        worksheet[1, 4].Text = "EmailAddress";
                        worksheet[1, 5].Text = "PhoneNo";
                        worksheet[1, 6].Text = "ModifiedDate";

                        //Initializing the hive server connection
                        HqlConnection con = new HqlConnection("localhost", 10000, HiveServer.HiveServer2);

                        //To initialize a Hive server connection with secured cluster
                        //HqlConnection con = new HqlConnection("<Secured cluster Namenode IP>", 10000, HiveServer.HiveServer2,"<username>","<password>");

                        con.Open();

                        //Create table for adventure person contacts
                        HqlCommand createCommand = new HqlCommand("CREATE EXTERNAL TABLE IF NOT EXISTS AdventureWorks_Person_Contact(ContactID int,FullName string,Age int,EmailAddress string,PhoneNo string,ModifiedDate string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' LOCATION '/Data/AdventureWorks'", con);
                        createCommand.ExecuteNonQuery();

                        //Passing the hive query
                        HqlCommand command = new HqlCommand("Select * from AdventureWorks_Person_Contact", con);

                        //Executing the query
                        HqlDataReader reader = command.ExecuteReader();
                        reader.FetchSize = 100;

                        //Fetches the result from the reader and store it in a seperate set
                        HiveResultSet result = reader.FetchResult();

                        //Reading each row from the fetched result
                        for (int i = 0; i < result.Count(); i++)
                        {
                            HiveRecord records = result[i];

                            //Reading each field from the row
                            for (int j = 0; j < records.Count; j++)
                            {
                                Object fields = records[j];
                                //Assigning each field value to the worksheet based on index
                                worksheet[i + 2, j + 1].Text = fields.ToString();
                            }
                        }
                        worksheet.Range["A1:F1"].CellStyle.Font.Color = Syncfusion.XlsIO.ExcelKnownColors.White;
                        worksheet.Range["A1:F1"].CellStyle.Font.Bold  = true;
                        worksheet.Range["A1:F1"].CellStyle.Color      = System.Drawing.Color.FromArgb(51, 153, 51);
                        worksheet.UsedRange.AutofitColumns();

                        //Saving workbook on user relevant name
                        string fileName = "Sample.xlsx";

                        //conditions for selecting version
                        //Save as Excel 97to2003 format
                        if (rBtn2003.Checked == true)
                        {
                            workbook.Version = ExcelVersion.Excel97to2003;
                            workbook.SaveAs("Sample.xls", Response, ExcelDownloadType.PromptDialog);
                        }
                        //Save as Excel 2007 formt
                        else if (rBtn2007.Checked == true)
                        {
                            workbook.Version = ExcelVersion.Excel2007;
                            workbook.SaveAs("Sample.xlsx", Response, ExcelDownloadType.PromptDialog);
                        }
                        //Save as Excel 2010 format
                        else if (rbtn2010.Checked == true)
                        {
                            workbook.Version = ExcelVersion.Excel2010;
                            workbook.SaveAs("Sample.xlsx", Response, ExcelDownloadType.PromptDialog);
                        }
                        //Save as Excel 2013 format
                        else if (rbtn2013.Checked == true)
                        {
                            workbook.Version = ExcelVersion.Excel2013;
                            workbook.SaveAs("Sample.xlsx", Response, ExcelDownloadType.PromptDialog);
                        }

                        //closing the workwook
                        workbook.Close();

                        //Closing the excel engine
                        excelEngine.Dispose();


                        //Closing the hive connection
                        con.Close();
                    }
                    catch (HqlConnectionException)
                    {
                        ErrorMessage.InnerText = "Could not establish a connection to the HiveServer. Please run HiveServer2 from the Syncfusion service manager dashboard.";
                    }
                }
            }
        }
Exemple #28
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                // Get XML file path.
                string dataPath = Application.StartupPath + @"..\..\..\..\..\..\..\..\Common\Data\DocIO\";
                //Opens an existing Word document
                WordDocument document = new WordDocument(dataPath + "Mathematical Equation.docx");

                //Gets the last section in the document
                WSection section = document.LastSection;
                //Gets paragraph from Word document
                WParagraph paragraph = document.LastSection.Body.ChildEntities[3] as WParagraph;

                //Gets MathML from the paragraph
                WMath math = paragraph.ChildEntities[0] as WMath;
                //Gets the radical equation
                IOfficeMathRadical mathRadical = math.MathParagraph.Maths[0].Functions[1] as IOfficeMathRadical;
                //Gets the fraction equation in radical
                IOfficeMathFraction mathFraction = mathRadical.Equation.Functions[0] as IOfficeMathFraction;
                //Gets the n-array in fraction
                IOfficeMathNArray mathNAry = mathFraction.Numerator.Functions[0] as IOfficeMathNArray;
                //Gets the math script in n-array
                IOfficeMathScript mathScript = mathNAry.Equation.Functions[0] as IOfficeMathScript;
                //Gets the delimiter in math script
                IOfficeMathDelimiter mathDelimiter = mathScript.Equation.Functions[0] as IOfficeMathDelimiter;
                //Gets the math script in delimiter
                mathScript = mathDelimiter.Equation[0].Functions[0] as IOfficeMathScript;
                //Gets the math run element in math script
                IOfficeMathRunElement mathParaItem = mathScript.Equation.Functions[0] as IOfficeMathRunElement;
                //Modifies the math text value
                (mathParaItem.Item as WTextRange).Text = "x";

                //Gets the math bar in delimiter
                IOfficeMathBar mathBar = mathDelimiter.Equation[0].Functions[2] as IOfficeMathBar;
                //Gets the math run element in bar
                mathParaItem = mathBar.Equation.Functions[0] as IOfficeMathRunElement;
                //Modifies the math text value
                (mathParaItem.Item as WTextRange).Text = "x";

                //Gets the paragraph from Word document
                paragraph = document.LastSection.Body.ChildEntities[6] as WParagraph;
                //Gets MathML from the paragraph
                math = paragraph.ChildEntities[0] as WMath;
                //Gets the math script equation
                mathScript = math.MathParagraph.Maths[0].Functions[0] as IOfficeMathScript;
                //Gets the math run element in math script
                mathParaItem = mathScript.Equation.Functions[0] as IOfficeMathRunElement;
                //Modifies the math text value
                (mathParaItem.Item as WTextRange).Text = "x";

                //Gets the paragraph from Word document
                paragraph = document.LastSection.Body.ChildEntities[7] as WParagraph;
                //Gets MathML from the paragraph
                WMath math2 = paragraph.ChildEntities[0] as WMath;
                //Gets bar equation
                mathBar = math2.MathParagraph.Maths[0].Functions[0] as IOfficeMathBar;
                //Gets the math run element in bar
                mathParaItem = mathBar.Equation.Functions[0] as IOfficeMathRunElement;
                //Gets the math text
                (mathParaItem.Item as WTextRange).Text = "x";

                //Saving the document as .docx
                document.Save("Sample.docx", FormatType.Docx);
                document.Close();

                //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());
                    }
                }
                else
                {
                    // Exit
                    this.Close();
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
        public IActionResult EditEquation(string Button, string Group1)
        {
            if (Button == null)
            {
                return(View());
            }
            string basePath    = _hostingEnvironment.WebRootPath;
            string dataPath    = basePath + @"/DocIO/Mathematical Equation.docx";
            string contenttype = "application/vnd.ms-word.document.12";
            // Load Template document stream.
            FileStream fileStream = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            if (Button == "View Template")
            {
                return(File(fileStream, contenttype, "Mathematical Equation.docx"));
            }

            // Creates an empty Word document instance.
            WordDocument document = new WordDocument();

            // Opens template document.
            document.Open(fileStream, FormatType.Docx);
            fileStream.Dispose();
            fileStream = null;
            //Gets the last section in the document
            WSection section = document.LastSection;
            //Gets paragraph from Word document
            WParagraph paragraph = document.LastSection.Body.ChildEntities[3] as WParagraph;

            //Gets MathML from the paragraph
            WMath math = paragraph.ChildEntities[0] as WMath;
            //Gets the radical equation
            IOfficeMathRadical mathRadical = math.MathParagraph.Maths[0].Functions[1] as IOfficeMathRadical;
            //Gets the fraction equation in radical
            IOfficeMathFraction mathFraction = mathRadical.Equation.Functions[0] as IOfficeMathFraction;
            //Gets the n-array in fraction
            IOfficeMathNArray mathNAry = mathFraction.Numerator.Functions[0] as IOfficeMathNArray;
            //Gets the math script in n-array
            IOfficeMathScript mathScript = mathNAry.Equation.Functions[0] as IOfficeMathScript;
            //Gets the delimiter in math script
            IOfficeMathDelimiter mathDelimiter = mathScript.Equation.Functions[0] as IOfficeMathDelimiter;

            //Gets the math script in delimiter
            mathScript = mathDelimiter.Equation[0].Functions[0] as IOfficeMathScript;
            //Gets the math run element in math script
            IOfficeMathRunElement mathParaItem = mathScript.Equation.Functions[0] as IOfficeMathRunElement;

            //Modifies the math text value
            (mathParaItem.Item as WTextRange).Text = "x";

            //Gets the math bar in delimiter
            IOfficeMathBar mathBar = mathDelimiter.Equation[0].Functions[2] as IOfficeMathBar;

            //Gets the math run element in bar
            mathParaItem = mathBar.Equation.Functions[0] as IOfficeMathRunElement;
            //Modifies the math text value
            (mathParaItem.Item as WTextRange).Text = "x";

            //Gets the paragraph from Word document
            paragraph = document.LastSection.Body.ChildEntities[6] as WParagraph;
            //Gets MathML from the paragraph
            math = paragraph.ChildEntities[0] as WMath;
            //Gets the math script equation
            mathScript = math.MathParagraph.Maths[0].Functions[0] as IOfficeMathScript;
            //Gets the math run element in math script
            mathParaItem = mathScript.Equation.Functions[0] as IOfficeMathRunElement;
            //Modifies the math text value
            (mathParaItem.Item as WTextRange).Text = "x";

            //Gets the paragraph from Word document
            paragraph = document.LastSection.Body.ChildEntities[7] as WParagraph;
            //Gets MathML from the paragraph
            WMath math2 = paragraph.ChildEntities[0] as WMath;

            //Gets bar equation
            mathBar = math2.MathParagraph.Maths[0].Functions[0] as IOfficeMathBar;
            //Gets the math run element in bar
            mathParaItem = mathBar.Equation.Functions[0] as IOfficeMathRunElement;
            //Gets the math text
            (mathParaItem.Item as WTextRange).Text = "x";

            string       filename = "";
            MemoryStream ms       = new MemoryStream();

            #region Document SaveOption
            if (Group1 == "WordDocx")
            {
                filename    = "EditEquation.docx";
                contenttype = "application/msword";
                document.Save(ms, FormatType.Docx);
            }
            else
            {
                filename    = "EditEquation.pdf";
                contenttype = "application/pdf";
                DocIORenderer renderer = new DocIORenderer();
                renderer.ConvertToPDF(document).Save(ms);
            }
            #endregion Document SaveOption
            document.Close();
            ms.Position = 0;
            return(File(ms, contenttype, filename));
        }
Exemple #30
0
        public MemoryStream EditEquation(string documentType)
        {
            string     basePath   = @"wwwroot/";
            string     dataPath   = basePath + @"data/docio/mathematical-equation.docx";
            FileStream fileStream = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            // Creates an empty Word document instance
            WordDocument document = new WordDocument();

            // Opens template document
            document.Open(fileStream, FormatType.Docx);
            fileStream.Dispose();
            fileStream = null;
            //Gets the last section in the document
            WSection section = document.LastSection;
            //Gets paragraph from Word document
            WParagraph paragraph = document.LastSection.Body.ChildEntities[3] as WParagraph;

            //Gets MathML from the paragraph
            WMath math = paragraph.ChildEntities[0] as WMath;
            //Gets the radical equation
            IOfficeMathRadical mathRadical = math.MathParagraph.Maths[0].Functions[1] as IOfficeMathRadical;
            //Gets the fraction equation in radical
            IOfficeMathFraction mathFraction = mathRadical.Equation.Functions[0] as IOfficeMathFraction;
            //Gets the n-array in fraction
            IOfficeMathNArray mathNAry = mathFraction.Numerator.Functions[0] as IOfficeMathNArray;
            //Gets the math script in n-array
            IOfficeMathScript mathScript = mathNAry.Equation.Functions[0] as IOfficeMathScript;
            //Gets the delimiter in math script
            IOfficeMathDelimiter mathDelimiter = mathScript.Equation.Functions[0] as IOfficeMathDelimiter;

            //Gets the math script in delimiter
            mathScript = mathDelimiter.Equation[0].Functions[0] as IOfficeMathScript;
            //Gets the math run element in math script
            IOfficeMathRunElement mathParaItem = mathScript.Equation.Functions[0] as IOfficeMathRunElement;

            //Modifies the math text value
            (mathParaItem.Item as WTextRange).Text = "x";

            //Gets the math bar in delimiter
            IOfficeMathBar mathBar = mathDelimiter.Equation[0].Functions[2] as IOfficeMathBar;

            //Gets the math run element in bar
            mathParaItem = mathBar.Equation.Functions[0] as IOfficeMathRunElement;
            //Modifies the math text value
            (mathParaItem.Item as WTextRange).Text = "x";

            //Gets the paragraph from Word document
            paragraph = document.LastSection.Body.ChildEntities[6] as WParagraph;
            //Gets MathML from the paragraph
            math = paragraph.ChildEntities[0] as WMath;
            //Gets the math script equation
            mathScript = math.MathParagraph.Maths[0].Functions[0] as IOfficeMathScript;
            //Gets the math run element in math script
            mathParaItem = mathScript.Equation.Functions[0] as IOfficeMathRunElement;
            //Modifies the math text value
            (mathParaItem.Item as WTextRange).Text = "x";

            //Gets the paragraph from Word document
            paragraph = document.LastSection.Body.ChildEntities[7] as WParagraph;
            //Gets MathML from the paragraph
            WMath math2 = paragraph.ChildEntities[0] as WMath;

            //Gets bar equation
            mathBar = math2.MathParagraph.Maths[0].Functions[0] as IOfficeMathBar;
            //Gets the math run element in bar
            mathParaItem = mathBar.Equation.Functions[0] as IOfficeMathRunElement;
            //Gets the math text
            (mathParaItem.Item as WTextRange).Text = "x";


            FormatType type = FormatType.Docx;

            //Save as .pdf format
            if (documentType == "PDF")
            {
                DocIORenderer render = new DocIORenderer();
                // Converts Word document into PDF document.
                PdfDocument pdf = render.ConvertToPDF(document);
                //Save the document as a stream and retrun the stream
                using (MemoryStream stream = new MemoryStream())
                {
                    //Save the created PDF document to MemoryStream
                    pdf.Save(stream);
                    render.Dispose();
                    pdf.Close();
                    document.Close();
                    stream.Position = 0;
                    return(stream);
                }
            }
            else
            {
                using (MemoryStream stream = new MemoryStream())
                {
                    //Save the created Word document to MemoryStream
                    document.Save(stream, type);
                    document.Close();
                    stream.Position = 0;
                    return(stream);
                }
            }
        }