Exemplo n.º 1
0
        static void Main(string[] args)
        {
            //Creates a new Word document
            WordDocument document = new WordDocument();
            //Adds the section into the Word document
            IWSection section  = document.AddSection();
            string    paraText = "AdventureWorks Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company.";
            //Adds the paragraph into the created section
            IWParagraph paragraph = section.AddParagraph();

            //Appends the TOC field with LowerHeadingLevel and UpperHeadingLevel to determines the TOC entries
            paragraph.AppendTOC(1, 3);
            //Adds the section into the Word document
            section = document.AddSection();
            //Adds the paragraph into the created section
            paragraph = section.AddParagraph();
            //Adds the text for the headings
            paragraph.AppendText("First Chapter");
            //Sets a built-in heading style.
            paragraph.ApplyStyle(BuiltinStyle.Heading1);
            //Adds the text into the paragraph
            section.AddParagraph().AppendText(paraText);
            //Adds the section into the Word document
            section = document.AddSection();
            //Adds the paragraph into the created section
            paragraph = section.AddParagraph();
            //Adds the text for the headings
            paragraph.AppendText("Second Chapter");
            //Sets a built-in heading style.
            paragraph.ApplyStyle(BuiltinStyle.Heading2);
            //Adds the text into the paragraph
            section.AddParagraph().AppendText(paraText);
            //Adds the section into the Word document
            section = document.AddSection();
            //Adds the paragraph into the created section
            paragraph = section.AddParagraph();
            //Adds the text into the headings
            paragraph.AppendText("Third Chapter");
            //Sets a built-in heading style
            paragraph.ApplyStyle(BuiltinStyle.Heading3);
            //Adds the text into the paragraph.
            section.AddParagraph().AppendText(paraText);
            //Updates the table of contents
            document.UpdateTableOfContents();
            //Finds the TOC from Word document.
            TableOfContent toc = FindTableOfContent(document);

            //Change tab leader for table of contents in the Word document
            if (toc != null)
            {
                ChangeTabLeaderForTableOfContents(toc, TabLeader.Hyphenated);
            }

            //Saves and closes the Word document
            document.Save("Result.docx");
            document.Close();

            System.Diagnostics.Process.Start("Result.docx");
        }
Exemplo n.º 2
0
        public ActionResult HeaderandFooter(string Group1)
        {
            if (Group1 == null)
            {
                return(View());
            }

            // Creating a new document.
            WordDocument doc = new WordDocument();
            // Add a new section to the document.
            IWSection section1 = doc.AddSection();

            // Set the header/footer setup.
            section1.PageSetup.DifferentFirstPage = true;
            // Inserting Header Footer to first page
            InsertFirstPageHeaderFooter(doc, section1);
            // Inserting Header Footer to all pages
            InsertPageHeaderFooter(doc, section1);

            // Add text to the document body section.
            IWParagraph par;

            par = section1.AddParagraph();

            string basePath = _hostingEnvironment.WebRootPath;
            string dataPath = basePath + @"/DocIO/WinFAQ.txt";
            //Insert Text into the word Document.
            StreamReader reader = new StreamReader(new FileStream(dataPath, FileMode.Open), System.Text.Encoding.ASCII);
            string       text   = reader.ReadToEnd();

            par.AppendText(text);
            reader.Dispose();
            reader = null;

            FormatType type        = FormatType.Docx;
            string     filename    = "Sample.docx";
            string     contenttype = "application/vnd.ms-word.document.12";

            #region Document SaveOption
            //Save as .doc format
            if (Group1 == "WordDoc")
            {
                type        = FormatType.Doc;
                filename    = "Sample.doc";
                contenttype = "application/msword";
            }
            //Save as .xml format
            else if (Group1 == "WordML")
            {
                type        = FormatType.WordML;
                filename    = "Sample.xml";
                contenttype = "application/msword";
            }
            #endregion Document SaveOption
            MemoryStream ms = new MemoryStream();
            doc.Save(ms, type);
            doc.Close();
            ms.Position = 0;
            return(File(ms, contenttype, filename));
        }
Exemplo n.º 3
0
        async void GerarArquivoWord()
        {
            WordDocument localdocumento = new WordDocument();

            IWSection localSection = localdocumento.AddSection();

            IWParagraph localparagraph = localSection.AddParagraph();

            //CachedImage localimagem = new CachedImage();
            //localimagem.Source = "ESFJPDocumento";
            //
            //var localbyte = await localimagem.GetImageAsJpgAsync();
            //IWPicture localpicture = localparagraph.AppendPicture(localbyte);

            var auxiliartexto = "Geral;\r\nProjetos;\r\nMarketing;\r\nPessoas;";

            IWTextRange localtexto = localparagraph.AppendText(auxiliartexto);

            localtexto.CharacterFormat.FontSize  = 14;
            localtexto.CharacterFormat.TextColor = Syncfusion.Drawing.Color.Black;

            MemoryStream arquivostream = new MemoryStream();

            arquivostream.Position = 0;

            localdocumento.Save(arquivostream, Syncfusion.DocIO.FormatType.Docx);

            localdocumento.Close();

            await DependencyService.Get <ISave>().Save("TesteESFJPDocumento.docx", "application/msword", arquivostream);

            //Stream docStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "TesteESFJPDocumento.docx");

            //localdocumento.Open(docStream, Syncfusion.DocIO.FormatType.Docx);
        }
Exemplo n.º 4
0
        private async void MergeCellsOrizzTabellaWord()
        {
            //Crea una istanza della classe WordDocument
            WordDocument document = new WordDocument();

            IWSection section = document.AddSection();

            section.AddParagraph().AppendText("Horizontal merging of Table cells");

            IWTable table = section.AddTable();

            table.ResetCells(5, 5);

            //Specifica il merge orizzontale dalla seconda cella alla quinta cella nella terza riga
            table.ApplyHorizontalMerge(2, 1, 4);

            ////Salva e chiudi l'istanza del documento
            //document.Save("HorizontalMerge.docx", FormatType.Docx);
            //document.Close();
            //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, "HorizontalMerge.docx");

            DefaultLaunch("HorizontalMerge.docx");
        }
Exemplo n.º 5
0
        private void OnButtonClicked(object sender, EventArgs e)
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            //A new document is created.
            WordDocument document = new WordDocument();
            //Add new section to the Word document
            IWSection section = document.AddSection();

            //Set page margins of the section
            section.PageSetup.Margins.All = 72;
            //Add new paragraph to the section
            IWParagraph paragraph = section.AddParagraph();

            //Apply heading style to the title paragraph
            paragraph.ApplyStyle(BuiltinStyle.Heading1);
            //Apply center alignment to the paragraph
            paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
            //Append text to the paragraph
            paragraph.AppendText("Northwind Management Report").CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(46, 116, 181);
            //Add new paragraph
            paragraph = section.AddParagraph();
            //Get chart data from xml file
            List <ProductDetail> Products = LoadXMLData();
            //Create and Append chart to the paragraph
            WChart pieChart = document.LastParagraph.AppendChart(446, 270);

            //Set chart data
            pieChart.ChartType  = OfficeChartType.Pie;
            pieChart.ChartTitle = "Best Selling Products";
            pieChart.ChartTitleArea.FontName = "Calibri (Body)";
            pieChart.ChartTitleArea.Size     = 14;
            for (int i = 0; i < Products.Count; i++)
            {
                ProductDetail product = Products[i];
                pieChart.ChartData.SetValue(i + 2, 1, product.ProductName);
                pieChart.ChartData.SetValue(i + 2, 2, product.Sum);
            }
            //Create a new chart series with the name “Sales”
            IOfficeChartSerie pieSeries = pieChart.Series.Add("Sales");

            pieSeries.Values = pieChart.ChartData[2, 2, 11, 2];
            //Setting data label
            pieSeries.DataPoints.DefaultDataPoint.DataLabels.IsPercentage = true;
            pieSeries.DataPoints.DefaultDataPoint.DataLabels.Position     = OfficeDataLabelPosition.Outside;
            //Setting background color
            pieChart.ChartArea.Fill.ForeColor           = Syncfusion.Drawing.Color.FromArgb(242, 242, 242);
            pieChart.PlotArea.Fill.ForeColor            = Syncfusion.Drawing.Color.FromArgb(242, 242, 242);
            pieChart.ChartArea.Border.LinePattern       = OfficeChartLinePattern.None;
            pieChart.PrimaryCategoryAxis.CategoryLabels = pieChart.ChartData[2, 1, 11, 1];
            MemoryStream stream = new MemoryStream();

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

            if (stream != null)
            {
                SaveAndroid androidSave = new SaveAndroid();
                androidSave.Save("PieChart.docx", "application/msword", stream, m_context);
            }
        }
Exemplo n.º 6
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();
        }
Exemplo n.º 7
0
        //Exports and saves the chart as Word document.
        #region DocIO
        private void buttonDocIO_Click(object sender, EventArgs e)
        {
            try
            {
                exportFileName = fileName + ".doc";
                string file = fileName + ".gif";

                if (!System.IO.File.Exists(file))
                {
                    this.chartControl1.SaveImage(file);
                }

                //Create a new document
                WordDocument document = new WordDocument();
                //Adding a new section to the document.
                IWSection section = document.AddSection();
                //Adding a paragraph to the section
                IWParagraph paragraph = section.AddParagraph();
                //Writing text.
                paragraph.AppendText("Essential Chart");
                //Adding a new paragraph
                paragraph = section.AddParagraph();
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                //Inserting chart.
                paragraph.AppendPicture(Image.FromFile(file));
                //Save the Document to disk.
                document.Save(exportFileName, Syncfusion.DocIO.FormatType.Doc);
                OpenFile("DocIO", exportFileName);
            }
            catch (Exception ex)
            {
                this.toolStripStatusLabel1.Text = "Chart Export failed.";
                Console.WriteLine(ex.ToString());
            }
        }
        /// <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
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            Assembly execAssem = typeof(BarChartDemo).GetTypeInfo().Assembly;
            //A new document is created.
            WordDocument document = new WordDocument();
            //Add new section to the Word document
            IWSection section = document.AddSection();

            //Set page margins of the section
            section.PageSetup.Margins.All = 72;
            //Add new paragraph to the section
            IWParagraph paragraph = section.AddParagraph();

            //Apply heading style to the title paragraph
            paragraph.ApplyStyle(BuiltinStyle.Heading1);
            //Apply center alignment to the paragraph
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            //Append text to the paragraph
            paragraph.AppendText("Northwind Management Report").CharacterFormat.TextColor = Syncfusion.DocIO.DLS.Color.FromArgb(46, 116, 181);
            //Add new paragraph
            paragraph = section.AddParagraph();
            //Set before spacing to the paragraph
            paragraph.ParagraphFormat.BeforeSpacing = 20;
            //Load the excel template as stream
            Stream excelStream = execAssem.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.DocIO.DocIO.Assets.Excel_Template.xlsx");
            //Create and Append chart to the paragraph with excel stream as parameter
            WChart barChart = paragraph.AppendChart(excelStream, 1, "B2:C6", 470, 300);

            //Set chart data
            barChart.ChartType  = OfficeChartType.Bar_Clustered;
            barChart.ChartTitle = "Purchase Details";
            barChart.ChartTitleArea.FontName = "Calibri (Body)";
            barChart.ChartTitleArea.Size     = 14;
            //Set name to chart series
            barChart.Series[0].Name = "Sum of Purchases";
            barChart.Series[1].Name = "Sum of Future Expenses";
            //Set Chart Data table
            barChart.HasDataTable             = true;
            barChart.DataTable.HasBorders     = true;
            barChart.DataTable.HasHorzBorder  = true;
            barChart.DataTable.HasVertBorder  = true;
            barChart.DataTable.ShowSeriesKeys = true;
            barChart.HasLegend = false;
            //Setting background color
            barChart.ChartArea.Fill.ForeColor = Syncfusion.Drawing.Color.FromArgb(208, 206, 206);
            barChart.PlotArea.Fill.ForeColor  = Syncfusion.Drawing.Color.FromArgb(208, 206, 206);
            //Setting line pattern to the chart area
            barChart.PrimaryCategoryAxis.Border.LinePattern           = OfficeChartLinePattern.None;
            barChart.PrimaryValueAxis.Border.LinePattern              = OfficeChartLinePattern.None;
            barChart.ChartArea.Border.LinePattern                     = OfficeChartLinePattern.None;
            barChart.PrimaryValueAxis.MajorGridLines.Border.LineColor = Syncfusion.Drawing.Color.FromArgb(175, 171, 171);
            //Set label for primary catagory axis
            barChart.PrimaryCategoryAxis.CategoryLabels = barChart.ChartData[2, 1, 6, 1];
            #region Saving Document
            SaveDocx(document);
            #endregion
        }
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            //Creates a new word document instance
            WordDocument document = new WordDocument();
            //Adds new section to the document
            IWSection section = document.AddSection();

            //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 = Syncfusion.DocIO.DLS.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
            SaveDocx(document);
        }
Exemplo n.º 12
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");
        }
Exemplo n.º 13
0
        public ActionResult HeaderandFooter(string Group1)
        {
            if (Group1 == null)
            {
                return(View());
            }

            // Creating a new document.
            WordDocument doc = new WordDocument();
            // Add a new section to the document.
            IWSection section1 = doc.AddSection();

            // Set the header/footer setup.
            section1.PageSetup.DifferentFirstPage = true;
            // Inserting Header Footer to first page
            InsertFirstPageHeaderFooter(doc, section1);
            // Inserting Header Footer to all pages
            InsertPageHeaderFooter(doc, section1);

            // Add text to the document body section.
            IWParagraph par;

            par = section1.AddParagraph();

            //Insert Text into the word Document.
            StreamReader reader = new StreamReader(ResolveApplicationDataPath("WinFAQ.txt", "App_Data\\DocIO"), System.Text.Encoding.ASCII);
            string       text   = reader.ReadToEnd();

            par.AppendText(text);

            //Save as .doc format
            if (Group1 == "WordDoc")
            {
                return(doc.ExportAsActionResult("Sample.doc", FormatType.Doc, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment));
            }
            //Save as .docx format
            else if (Group1 == "WordDocx")
            {
                return(doc.ExportAsActionResult("Sample.docx", FormatType.Docx, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment));
            }
            // Save as WordML(.xml) format
            else if (Group1 == "WordML")
            {
                return(doc.ExportAsActionResult("Sample.xml", FormatType.WordML, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment));
            }
            //Save as .pdf format
            else if (Group1 == "Pdf")
            {
                DocToPDFConverter converter = new DocToPDFConverter();
                PdfDocument       pdfDoc    = converter.ConvertToPDF(doc);

                return(pdfDoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save));
            }
            return(View());
        }
Exemplo n.º 14
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;
            }
        }
        public async Task <IActionResult> OnPostGenerateVolunteerReport()
        {
            //Initializing database variables
            var volunteers          = _context.Volunteer;
            var volunteerActivities = _context.VolunteerActivity;
            var initiatives         = _context.Initiative;

            //Pulling currently logged in user
            var user = await _userManager.GetUserAsync(User);

            Volunteer loggedin = await _context.Volunteer
                                 .FirstOrDefaultAsync(m => m.UserName.ToLower() == user.UserName.ToLower());

            //Creating and formatting document
            WordDocument report  = new WordDocument();
            IWSection    section = report.AddSection();

            section.PageSetup.Margins.All = 50f;
            IWParagraph name = section.AddParagraph();

            name.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            name.ParagraphFormat.AfterSpacing        = 18f;
            IWTextRange nameText = name.AppendText(loggedin.FullName);

            //Creating and formatting table
            IWTable info = section.AddTable();

            info.ResetCells(1, 5);
            AddTitlesToTable(info);
            info.Rows[0].Height = 20;

            //Looping through initiatives and filling the table
            int row = 0;

            foreach (CoHO.Models.VolunteerActivity activity in volunteerActivities.ToArray())
            {
                if (activity.VolunteerId == loggedin.VolunteerID)
                {
                    row = AddDataToTable(info, row, activity, initiatives);
                }
            }

            //Assigning font
            nameText.CharacterFormat.FontName = "Times New Roman";
            nameText.CharacterFormat.FontSize = 14;

            //Saving document and downloading to user's computer
            MemoryStream stream = new MemoryStream();

            report.Save(stream, FormatType.Docx);
            report.Close();
            stream.Position = 0;
            return(File(stream, "application/msword", "UserReport.docx"));
        }
Exemplo n.º 16
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());
            }
        }
Exemplo n.º 17
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            Assembly execAssem = typeof(Common.MainPage).GetTypeInfo().Assembly;
            //A new document is created.
            WordDocument document = new WordDocument();
            //Add new section to the Word document
            IWSection section = document.AddSection();

            //Set page margins of the section
            section.PageSetup.Margins.All = 72;
            //Add new paragraph to the section
            IWParagraph paragraph = section.AddParagraph();

            //Apply heading style to the title paragraph
            paragraph.ApplyStyle(BuiltinStyle.Heading1);
            //Apply center alignment to the paragraph
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            //Append text to the paragraph
            paragraph.AppendText("Northwind Management Report").CharacterFormat.TextColor = Syncfusion.DocIO.DLS.Color.FromArgb(46, 116, 181);
            //Add new paragraph
            paragraph = section.AddParagraph();
            //Get chart data from xml file
            List <ProductDetail> Products = LoadXMLData();
            //Create and Append chart to the paragraph
            WChart pieChart = document.LastParagraph.AppendChart(446, 270);

            //Set chart data
            pieChart.ChartType  = OfficeChartType.Pie;
            pieChart.ChartTitle = "Best Selling Products";
            pieChart.ChartTitleArea.FontName = "Calibri (Body)";
            pieChart.ChartTitleArea.Size     = 14;
            for (int i = 0; i < Products.Count; i++)
            {
                ProductDetail product = Products[i];
                pieChart.ChartData.SetValue(i + 2, 1, product.ProductName);
                pieChart.ChartData.SetValue(i + 2, 2, product.Sum);
            }
            //Create a new chart series with the name “Sales”
            IOfficeChartSerie pieSeries = pieChart.Series.Add("Sales");

            pieSeries.Values = pieChart.ChartData[2, 2, 11, 2];
            //Setting data label
            pieSeries.DataPoints.DefaultDataPoint.DataLabels.IsPercentage = true;
            pieSeries.DataPoints.DefaultDataPoint.DataLabels.Position     = OfficeDataLabelPosition.Outside;
            //Setting background color
            pieChart.ChartArea.Fill.ForeColor           = Syncfusion.Drawing.Color.FromArgb(242, 242, 242);
            pieChart.PlotArea.Fill.ForeColor            = Syncfusion.Drawing.Color.FromArgb(242, 242, 242);
            pieChart.ChartArea.Border.LinePattern       = OfficeChartLinePattern.None;
            pieChart.PrimaryCategoryAxis.CategoryLabels = pieChart.ChartData[2, 1, 11, 1];
            #region Saving Document
            MemoryStream ms = new MemoryStream();
            SaveDocx(document);
            #endregion
        }
Exemplo n.º 18
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();
        }
Exemplo n.º 19
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();
     }
 }
Exemplo n.º 20
0
        /// <summary>
        /// Create a simple Word document
        /// </summary>
        /// <returns>Return the created Word document as stream</returns>
        public MemoryStream HeaderandFooter(string documentType)
        {
            // Creating a new document.
            WordDocument doc = new WordDocument();
            // Add a new section to the document.
            IWSection section1 = doc.AddSection();

            // Set the header/footer setup.
            section1.PageSetup.DifferentFirstPage = true;
            // Inserting Header Footer to first page
            InsertFirstPageHeaderFooter(doc, section1);
            // Inserting Header Footer to all pages
            InsertPageHeaderFooter(doc, section1);

            // Add text to the document body section.
            IWParagraph par;

            par = section1.AddParagraph();

            string basePath = _hostingEnvironment.WebRootPath;
            string dataPath = basePath + @"/data/docio/win-faq.txt";
            //Insert Text into the word Document.
            StreamReader reader = new StreamReader(new FileStream(dataPath, FileMode.Open), System.Text.Encoding.ASCII);
            string       text   = reader.ReadToEnd();

            par.AppendText(text);
            reader.Dispose();
            reader = null;

            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);
            }
        }
Exemplo n.º 21
0
        private async void MergeCellsVertTabellaWord()
        {
            //Crea una istanza della classe WordDocument

            WordDocument document = new WordDocument();

            IWSection section = document.AddSection();

            section.AddParagraph().AppendText("Vertical merging of Table cells");

            IWTable table = section.AddTable();

            table.ResetCells(2, 2);

            //Aggiunge contenuto alle celle della tabella

            table[0, 0].AddParagraph().AppendText("First row, First cell");

            table[0, 1].AddParagraph().AppendText("First row, Second cell");

            table[1, 0].AddParagraph().AppendText("Second row, First cell");

            table[1, 1].AddParagraph().AppendText("Second row, Second cell");

            //Specifica che il vertical merge inizia dalla prima cella della prima riga

            table[0, 0].CellFormat.VerticalMerge = CellMerge.Start;

            //Modifica il contenuto della cella

            table[0, 0].Paragraphs[0].Text = "Vertically merged cell";

            //Specifica che il vertical merge continua sulla prima cela della seconda riga

            table[1, 0].CellFormat.VerticalMerge = CellMerge.Continue;

            ////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, "VerticalMerge.docx");

            DefaultLaunch("VerticalMerge.docx");
        }
Exemplo n.º 22
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
Exemplo n.º 23
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            // Creating a new document.
            WordDocument doc = new WordDocument();

            // Add a new section to the document.
            IWSection section1 = doc.AddSection();

            Assembly execAssm = typeof(HeadersAndFootersDemo).GetTypeInfo().Assembly;

            #region Header Footer
            //Add different Header Footer for first and other pages
            if (checkBox1.IsChecked == true && checkBox2.IsChecked == true)
            {
                // Set the header/footer setup.
                section1.PageSetup.DifferentFirstPage = true;
                // Inserting Header Footer to first page
                InsertFirstPageHeaderFooter(doc, section1);
                // Inserting Header Footer to all pages
                InsertPageHeaderFooter(doc, section1);
            }
            //Add Header Footer only for first page
            if (checkBox1.IsChecked == true && checkBox2.IsChecked != true)
            {
                // Set the header/footer setup.
                section1.PageSetup.DifferentFirstPage = true;
                // Inserting Header Footer to first page
                InsertFirstPageHeaderFooter(doc, section1);
            }
            //Add same Header Footer for all the pages
            if (checkBox2.IsChecked == true && checkBox1.IsChecked != true)
            {
                // Inserting Header Footer to all pages
                InsertPageHeaderFooter(doc, section1);
            }
            #endregion

            // Add text to the document body section.
            IWParagraph par;
            par = section1.AddParagraph();
            //Insert Text into the word Document.
            Stream       inputStream = execAssm.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.DocIO.DocIO.Assets.WinFAQ.txt");
            StreamReader reader      = new StreamReader(inputStream, System.Text.Encoding.Unicode);
            string       text        = reader.ReadToEnd();
            par.AppendText(text);
            Save(rdDoc.IsChecked == true, doc);
        }
Exemplo n.º 24
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
Exemplo n.º 25
0
 static void Main(string[] args)
 {
     //Creates new Word document instance for Word processing
     using (WordDocument document = new WordDocument())
     {
         //Adds a section to the Word document
         IWSection section = document.AddSection();
         //Sets the page margin
         section.PageSetup.Margins.All = 72;
         //Adds a paragrah to the section
         IWParagraph paragraph = section.AddParagraph();
         paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
         paragraph.ParagraphFormat.AfterSpacing        = 20;
         IWTextRange textRange = paragraph.AppendText("Suppliers");
         textRange.CharacterFormat.FontSize  = 14;
         textRange.CharacterFormat.Bold      = true;
         textRange.CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(255, 50, 62, 79);
         //Modifies the font size as 10 for default paragraph style
         WParagraphStyle style = document.Styles.FindByName("Normal") as WParagraphStyle;
         style.CharacterFormat.FontSize = 10;
         //Adds a table to the section
         WTable table = section.AddTable() as WTable;
         table.ResetCells(1, 6);
         table[0, 0].Width = 52f;
         table[0, 0].AddParagraph().AppendText("Supplier ID");
         table[0, 1].Width = 128f;
         table[0, 1].AddParagraph().AppendText("Company Name");
         table[0, 2].Width = 70f;
         table[0, 2].AddParagraph().AppendText("Contact Name");
         table[0, 3].Width = 92f;
         table[0, 3].AddParagraph().AppendText("Address");
         table[0, 4].Width = 66.5f;
         table[0, 4].AddParagraph().AppendText("City");
         table[0, 5].Width = 56f;
         table[0, 5].AddParagraph().AppendText("Country");
         //Imports data to the table.
         ImportDataToTable(table);
         //Applies the built-in table style (Medium Shading 1 Accent 1) to the table
         table.ApplyStyle(BuiltinTableStyle.MediumShading1Accent1);
         //Saves the file in the given path
         Stream docStream = File.Create(Path.GetFullPath(@"Result.docx"));
         document.Save(docStream, FormatType.Docx);
         docStream.Dispose();
     }
 }
Exemplo n.º 26
0
        public MemoryStream ExportQuizQuestions(DetailsQuizViewModel model)
        {
            WordDocument document = new WordDocument();
            //Adds new section to the document
            IWSection section = document.AddSection();

            IWParagraph paragraph = section.AddParagraph();

            paragraph.ApplyStyle(BuiltinStyle.Heading1);
            paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
            paragraph.AppendText($"{model.CategoryName} - {model.Title}");

            foreach (var question in model.Questions)
            {
                paragraph = section.AddParagraph();
                //Applies default numbered list style
                paragraph.ListFormat.ApplyDefNumberedStyle();
                //Adds text to the paragraph
                paragraph.AppendText($"{question.Value}");

                //Continues the list defined
                paragraph.ListFormat.ContinueListNumbering();
                paragraph = section.AddParagraph();
                paragraph.ListFormat.IncreaseIndentLevel();

                foreach (var answer in question.Answers)
                {
                    paragraph.AppendText($"{answer.Value}");
                    //Continues the list defined
                    paragraph.ListFormat.ContinueListNumbering();
                    paragraph = section.AddParagraph();
                }
                paragraph.ListFormat.DecreaseIndentLevel();
            }

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

            document.Save(stream, FormatType.Docx);
            stream.Position = 0;

            //Download Word document in the browser
            return(stream);
        }
Exemplo n.º 27
0
        public MemoryStream GetWord(List <Book> books)
        {
            var         word    = new WordDocument();
            IWSection   section = word.AddSection();
            IWTextRange title   = section.AddParagraph().AppendText("Filtered Books");

            title.CharacterFormat.Bold = true;
            section.AddParagraph();

            IWTable table = section.AddTable();

            table.Title       = "Filtered books";
            table.Description = "Books found based on applied filters";

            var headers = new List <string>()
            {
                "Title", "Author", "Price", "Bestseller", "Availability"
            };

            table.ResetCells(books.Count + 1, headers.Count);

            //Add table row with headers
            for (int i = 0; i < headers.Count; i++)
            {
                table[0, i].AddParagraph().AppendText(headers[i]);
            }

            //Add table rows with book values
            for (int i = 0; i < books.Count; i++)
            {
                table[i + 1, 0].AddParagraph().AppendText(books[i].Title);
                table[i + 1, 1].AddParagraph().AppendText(GetAuthorString(books[i].Author));;
                table[i + 1, 2].AddParagraph().AppendText(GetPriceString(books[i].Price));
                table[i + 1, 3].AddParagraph().AppendText(GetBestsellerString(books[i].IsBestSeller));
                table[i + 1, 4].AddParagraph().AppendText(GetStockString(books[i].AvailableStock));
            }

            MemoryStream stream = new MemoryStream();

            word.Save(stream, FormatType.Docx);

            return(stream);
        }
Exemplo n.º 28
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(App).GetTypeInfo().Assembly;
            // 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

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

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

            # endregion

            # region ListNumber Style

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

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

            # endregion

            # region TOA Heading Style

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

            # endregion

            para = section.AddParagraph() as WParagraph;
            section.BreakCode = SectionBreakCode.NewColumn;

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

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

            # endregion

            # region List Continue Style

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

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

            # endregion

            # region HTMLSample Style

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

            # endregion

            section = document.AddSection() as WSection;
            section.BreakCode = SectionBreakCode.NoBreak;

            # region Document Map Style

            //Docuemnt Map
            para = section.AddParagraph() as WParagraph;
            para.AppendText("This para is written with style DocumentMap\n").CharacterFormat.UnderlineStyle = Syncfusion.Drawing.UnderlineStyle.Double;
            para = section.AddParagraph() as WParagraph;
            para.ApplyStyle(BuiltinStyle.DocumentMap);
            IWTextRange textrange = para.AppendText("Google Chrome\n");
            textrange.CharacterFormat.TextBackgroundColor = Syncfusion.Drawing.Color.Red;
            textrange = para.AppendText("Mozilla Firefox\n");
            textrange.CharacterFormat.TextBackgroundColor = Syncfusion.Drawing.Color.Red;
            textrange = para.AppendText("Internet Explorer");
            textrange.CharacterFormat.TextBackgroundColor = Syncfusion.Drawing.Color.Red;

            #endregion

            # region Heading Styles
            //Heading Styles
            para = section.AddParagraph() as WParagraph;
            para.ApplyStyle(BuiltinStyle.Heading1);
            para.AppendText("Hello World. This para is written with style " + para.StyleName.ToString());

            para = section.AddParagraph() as WParagraph;
            para.ApplyStyle(BuiltinStyle.Heading2);
            para.AppendText("Hello World. This para is written with style " + para.StyleName.ToString());

            para = section.AddParagraph() as WParagraph;
            para.ApplyStyle(BuiltinStyle.Heading3);
            para.AppendText("Hello World. This para is written with style " + para.StyleName.ToString());

            para = section.AddParagraph() as WParagraph;
            para.ApplyStyle(BuiltinStyle.Heading4);
            para.AppendText("Hello World. This para is written with style " + para.StyleName.ToString());

            para = section.AddParagraph() as WParagraph;
            para.ApplyStyle(BuiltinStyle.Heading5);
            para.AppendText("Hello World. This para is written with style " + para.StyleName.ToString());

            para = section.AddParagraph() as WParagraph;
            para.ApplyStyle(BuiltinStyle.Heading6);
            para.AppendText("Hello World. This para is written with style " + para.StyleName.ToString());

            para = section.AddParagraph() as WParagraph;
            para.ApplyStyle(BuiltinStyle.Heading7);
            para.AppendText("Hello World. This para is written with style " + para.StyleName.ToString());

            para = section.AddParagraph() as WParagraph;
            para.ApplyStyle(BuiltinStyle.Heading8);
            para.AppendText("Hello World. This para is written with style " + para.StyleName.ToString());

            para = section.AddParagraph() as WParagraph;
            para.ApplyStyle(BuiltinStyle.Heading9);
            para.AppendText("Hello World. This para is written with style " + para.StyleName.ToString());

            # endregion

            #endregion Built-in styles

            #region Saving Document
            MemoryStream stream = new MemoryStream();
            document.Save(stream, FormatType.Word2013);
            document.Close();
            if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows)
                Xamarin.Forms.DependencyService.Get<ISaveWindowsPhone>().Save("WordDocument_BuiltInStyles.docx", "application/msword", stream);
            else
                Xamarin.Forms.DependencyService.Get<ISave>().Save("WordDocument_BuiltInStyles.docx", "application/msword", stream);
            #endregion
        }
Exemplo n.º 31
0
        public async Task<bool> GenerateCV(StorageFile file, User user, string languageTag)
        {
            ReswStringsProvider stringsProvider = new ReswStringsProvider();
            WordDocument document = new WordDocument();
            IWSection section = document.AddSection();
            
            IWParagraph contactParagraph = section.AddParagraph();
            contactParagraph.AppendText(String.Format("{0} {1}", user.FirstName, user.LastName));
            contactParagraph.AppendBreak(BreakType.LineBreak);
            contactParagraph.AppendText(user.Address.ToString());
            contactParagraph.AppendBreak(BreakType.LineBreak);
            contactParagraph.AppendText(user.Phone.ToString());
            contactParagraph.AppendBreak(BreakType.LineBreak);
            contactParagraph.AppendText(user.Email.ToString());
            if (!String.IsNullOrWhiteSpace(user.Fax))
            {
                contactParagraph.AppendBreak(BreakType.LineBreak);
                contactParagraph.AppendText(user.Fax.ToString());
                contactParagraph.AppendBreak(BreakType.LineBreak);
            }

            PeriodFormater formater = new PeriodFormater();

            var eduParagraph = section.AddParagraph();
            eduParagraph.ApplyStyle(BuiltinStyle.Heading1);
            eduParagraph.AppendText(stringsProvider.GetLocalizedString(user.Education.ResourceStringName, languageTag));
            foreach (var item in user.Education.Items)
            {
                if (item.Translations.Contains(languageTag)) {
                    var txt = item.Translations[languageTag];
                    eduParagraph = section.AddParagraph();
                    eduParagraph.ApplyStyle(BuiltinStyle.ListBullet);
                    eduParagraph.AppendText(string.Format("{0} {1}", txt.SchoolName, formater.Convert(item.TimePeriod, typeof(string),null,languageTag)));
                    eduParagraph = section.AddParagraph();
                    eduParagraph.ApplyStyle(BuiltinStyle.ListContinue2);
                    eduParagraph.AppendText(string.Format("{0} {1}", txt.Domain, txt.Description));
                }
            }

            var jobParagraph = section.AddParagraph();
            jobParagraph.ApplyStyle(BuiltinStyle.Heading1);
            jobParagraph.AppendText(stringsProvider.GetLocalizedString(user.Jobs.ResourceStringName, languageTag));
            foreach (var item in user.Jobs.Items)
            {
                if (item.Translations.Contains(languageTag))
                {
                    var txt = item.Translations[languageTag];
                    jobParagraph = section.AddParagraph();
                    jobParagraph.ApplyStyle(BuiltinStyle.ListBullet);
                    jobParagraph.AppendText(string.Format("{0}, {1} {2}", txt.CompanyName, txt.Position, formater.Convert(item.TimePeriod, typeof(string), null, languageTag)));
                    jobParagraph = section.AddParagraph();
                    jobParagraph.ApplyStyle(BuiltinStyle.ListContinue2);
                    jobParagraph.AppendText(string.Format("{0}", txt.Responsibilities));
                }
            }

            var projectParagraph = section.AddParagraph();
            projectParagraph.ApplyStyle(BuiltinStyle.Heading1);
            projectParagraph.AppendText(stringsProvider.GetLocalizedString(user.Projects.ResourceStringName, languageTag));
            foreach (var item in user.Projects.Items)
            {
                if (item.Translations.Contains(languageTag))
                {
                    var txt = item.Translations[languageTag];
                    projectParagraph = section.AddParagraph();
                    projectParagraph.ApplyStyle(BuiltinStyle.ListBullet);
                    projectParagraph.AppendText(string.Format("{0} {1}", txt.Name, formater.Convert(item.TimePeriod, typeof(string), null, languageTag)));
                    projectParagraph = section.AddParagraph();
                    projectParagraph.ApplyStyle(BuiltinStyle.ListContinue2);
                    projectParagraph.AppendText(string.Format("{0}", txt.Description));
                }
            }

            return await document.SaveAsync(file, Syncfusion.DocIO.FormatType.Docx);
        }
        void OnButtonClicked(object sender, EventArgs e)
        {
            WordDocument document = new WordDocument();
            IWParagraphStyle style = null;
            // Adding a new section to the document.
            WSection section = document.AddSection() as WSection;
            //Set Margin of the section
            section.PageSetup.Margins.All = 72;
            IWParagraph par = document.LastSection.AddParagraph();
            WTextRange range = par.AppendText("Using CustomStyles") as WTextRange;
            range.CharacterFormat.TextBackgroundColor = Syncfusion.Drawing.Color.Red;
            range.CharacterFormat.TextColor = Syncfusion.Drawing.Color.White;
            range.CharacterFormat.FontSize = 18f;
            document.LastParagraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;

            // Create Paragraph styles
            style = document.AddParagraphStyle("MyStyle_Normal");
            style.CharacterFormat.FontName = "Bitstream Vera Serif";
            style.CharacterFormat.FontSize = 10f;
            style.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify;
            style.CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(0, 21, 84);

            style = document.AddParagraphStyle("MyStyle_Low");
            style.CharacterFormat.FontName = "Times New Roman";
            style.CharacterFormat.FontSize = 16f;
            style.CharacterFormat.Bold = true;

            style = document.AddParagraphStyle("MyStyle_Medium");
            style.CharacterFormat.FontName = "Monotype Corsiva";
            style.CharacterFormat.FontSize = 18f;
            style.CharacterFormat.Bold = true;
            style.CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(51, 66, 125);

            style = document.AddParagraphStyle("Mystyle_High");
            style.CharacterFormat.FontName = "Bitstream Vera Serif";
            style.CharacterFormat.FontSize = 20f;
            style.CharacterFormat.Bold = true;
            style.CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(242, 151, 50);

            IWParagraph paragraph = null;
            for (int i = 1; i < document.Styles.Count; i++)
            {
                // Getting styles from Document.
                style = (IWParagraphStyle)document.Styles[i];
                // Adding a new paragraph
                section.AddParagraph();
                paragraph = section.AddParagraph();
                // Applying styles to the current paragraph.
                paragraph.ApplyStyle(style.Name);
                // Writing Text with the current style and formatting.
                paragraph.AppendText("Northwind Database with [" + style.Name + "] Style");
                // Adding a new paragraph
                section.AddParagraph();
                paragraph = section.AddParagraph();
                // Applying another style to the current paragraph.
                paragraph.ApplyStyle("MyStyle_Normal");
                // Writing text with current style.
                paragraph.AppendText("The Northwind sample database (Northwind.mdb) is included with all versions of Access. It provides data you can experiment with and database objects that demonstrate features you might want to implement in your own databases. Using Northwind, you can become familiar with how a relational database is structured and how the database objects work together to help you enter, store, manipulate, and print your data.");
            }
            #region Saving Document
            MemoryStream stream = new MemoryStream();
            document.Save(stream, FormatType.Word2013);
            document.Close();
            if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows)
                Xamarin.Forms.DependencyService.Get<ISaveWindowsPhone>().Save("WordDocument_CustomStyles.docx", "application/msword", stream);
            else
                Xamarin.Forms.DependencyService.Get<ISave>().Save("WordDocument_CustomStyles.docx", "application/msword", stream);
            #endregion
        }
Exemplo n.º 33
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                //A new document is created.
                WordDocument document = new WordDocument();

                //Adding a section to the document.
                IWSection section = document.AddSection();

                //Adding a paragraph to the section.
                IWParagraph paragraph = section.AddParagraph();

                #region DocVariable
                string name    = "John Smith";
                string address = "Cary, NC";
                //Get the variables in the existing document
                DocVariables dVariable = document.Variables;
                //Add doc variables
                dVariable.Add("Customer Name", name);
                dVariable.Add("Customer Address", address);
                #endregion DocVariable

                #region Document Properties
                //Setting document Properties
                document.BuiltinDocumentProperties.Author          = "Essential DocIO";
                document.BuiltinDocumentProperties.ApplicationName = "Essential DocIO";
                document.BuiltinDocumentProperties.Category        = "Document Generator";
                document.BuiltinDocumentProperties.Comments        = "This document was generated using Essential DocIO";
                document.BuiltinDocumentProperties.Company         = "Syncfusion Inc";
                document.BuiltinDocumentProperties.Subject         = "Native Word Generator";
                document.BuiltinDocumentProperties.Keywords        = "Syncfusion";
                document.BuiltinDocumentProperties.Manager         = "Sync Manager";
                document.BuiltinDocumentProperties.Title           = "Essential DocIO";

                // Add a custom document Property
                document.CustomDocumentProperties.Add("My_Doc_Date", DateTime.Today);
                document.CustomDocumentProperties.Add("My_Doc", true);
                document.CustomDocumentProperties.Add("My_ID", 1031);
                document.CustomDocumentProperties.Add("My_Comment", "Essential DocIO");
                //Remove a custome property
                document.CustomDocumentProperties.Remove("My_Doc");

                #endregion


                IWTextRange text = paragraph.AppendText("");
                text.CharacterFormat.FontName = "Calibri";
                text.CharacterFormat.FontSize = 13;
                text = paragraph.AppendText("This document is created with various Document Properties Summary Information and page settings information \n\n You can view Document Properties through: File -> Properties -> Summary/Custom.");
                text.CharacterFormat.FontName = "Calibri";
                text.CharacterFormat.FontSize = 13;


                #region Page setup

                // Write section properties
                section.PageSetup.PageSize             = new SizeF(500, 750);
                section.PageSetup.Orientation          = PageOrientation.Landscape;
                section.PageSetup.Margins.Bottom       = 100;
                section.PageSetup.Margins.Top          = 100;
                section.PageSetup.Margins.Left         = 50;
                section.PageSetup.Margins.Right        = 50;
                section.PageSetup.PageBordersApplyType = PageBordersApplyType.AllPages;
                section.PageSetup.Borders.BorderType   = Syncfusion.DocIO.DLS.BorderStyle.DoubleWave;
                section.PageSetup.Borders.Color        = Color.DarkBlue;
                section.PageSetup.VerticalAlignment    = PageAlignment.Middle;

                #endregion

                paragraph = section.AddParagraph();
                text      = paragraph.AppendText("");
                text.CharacterFormat.FontName = "Calibri";
                text.CharacterFormat.FontSize = 13;
                text = paragraph.AppendText("\n\n You can view Page setup options through File -> PageSetup.");
                text.CharacterFormat.FontName = "Calibri";
                text.CharacterFormat.FontSize = 13;

                #region Get document variables
                paragraph = document.LastSection.AddParagraph();
                dVariable = document.Variables;
                text      = paragraph.AppendText("\n\n Document Variables\n");
                text.CharacterFormat.FontName = "Calibri";
                text.CharacterFormat.FontSize = 13;
                text.CharacterFormat.Bold     = true;
                text = paragraph.AppendText("\n" + dVariable.GetNameByIndex(1) + ": " + dVariable.GetValueByIndex(1));
                text.CharacterFormat.FontName = "Calibri";
                text.CharacterFormat.FontSize = 13;
                //Display the current variable count
                text = paragraph.AppendText("\n\nDocument Variables Count: " + dVariable.Count);
                text.CharacterFormat.FontName = "Calibri";
                text.CharacterFormat.FontSize = 13;

                #endregion Get document variables

                //Save as doc format
                if (wordDocRadioBtn.Checked)
                {
                    //Saving the document to disk.
                    document.Save("Sample.doc");

                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
#if NETCORE
                        System.Diagnostics.Process process = new System.Diagnostics.Process();
                        process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.doc")
                        {
                            UseShellExecute = true
                        };
                        process.Start();
#else
                        System.Diagnostics.Process.Start("Sample.doc");
#endif
                        //Exit
                        this.Close();
                    }
                }
                //Save as docx format
                else if (wordDocxRadioBtn.Checked)
                {
                    //Saving the document as .docx
                    document.Save("Sample.docx", FormatType.Docx);
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
#if NETCORE
                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.docx")
                            {
                                UseShellExecute = true
                            };
                            process.Start();
#else
                            System.Diagnostics.Process.Start("Sample.docx");
#endif
                            //Exit
                            this.Close();
                        }
                        catch (Win32Exception ex)
                        {
                            MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                else
                {
                    // Exit
                    this.Close();
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
        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);
        }