Beispiel #1
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");
        }
Beispiel #2
0
        private void AddTeamCompositionTable()
        {
            IWTable unit_team_table = GetCurrentSection().AddTable();

            unit_team_table.ResetCells(6, 2);
            unit_team_table[0, 0].AddParagraph().AppendText(Resources.Language.pt_local.Type);
            unit_team_table[0, 1].AddParagraph().AppendText(Resources.Language.pt_local.Quantity);

            // Public
            unit_team_table[1, 0].AddParagraph().AppendText(Resources.Language.pt_local.Public);
            unit_team_table[1, 1].AddParagraph().AppendText(apr.unit.team.generalPublicCount.ToString());

            // Students
            unit_team_table[2, 0].AddParagraph().AppendText(Resources.Language.pt_local.Students);
            unit_team_table[2, 1].AddParagraph().AppendText(apr.unit.team.studentsCount.ToString());

            // Teachers
            unit_team_table[3, 0].AddParagraph().AppendText(Resources.Language.pt_local.Teachers);
            unit_team_table[3, 1].AddParagraph().AppendText(apr.unit.team.teachersCount.ToString());

            // Technics
            unit_team_table[4, 0].AddParagraph().AppendText(Resources.Language.pt_local.Technics);
            unit_team_table[4, 1].AddParagraph().AppendText(apr.unit.team.technicsCount.ToString());

            // Other
            if (apr.unit.team.otherDescription != null)
            {
                unit_team_table[5, 0].AddParagraph().AppendText(apr.unit.team.otherDescription);
                unit_team_table[5, 1].AddParagraph().AppendText(apr.unit.team.otherCount.ToString());
            }
        }
Beispiel #3
0
        private void AddChemicalResidueTable()
        {
            IWTable chemicalResiduesTable = GetCurrentSection().AddTable();

            chemicalResiduesTable.ResetCells(apr.lab.manipulatedChemicalResidues.Count + 1, 8);
            chemicalResiduesTable[0, 0].AddParagraph().AppendText(Resources.Language.pt_local.Name);
            chemicalResiduesTable[0, 1].AddParagraph().AppendText(Resources.Language.pt_local.PhysicalState);
            chemicalResiduesTable[0, 2].AddParagraph().AppendText(Resources.Language.pt_local.Origin);
            chemicalResiduesTable[0, 3].AddParagraph().AppendText(Resources.Language.pt_local.Quantity);
            chemicalResiduesTable[0, 4].AddParagraph().AppendText(Resources.Language.pt_local.DangerCharacteristics);
            chemicalResiduesTable[0, 5].AddParagraph().AppendText(Resources.Language.pt_local.Inert);
            chemicalResiduesTable[0, 6].AddParagraph().AppendText(Resources.Language.pt_local.Container);
            chemicalResiduesTable[0, 7].AddParagraph().AppendText(Resources.Language.pt_local.StorageInfo);

            for (int i = 0; i < apr.lab.manipulatedChemicalResidues.Count; i++)
            {
                chemicalResiduesTable[i + 1, 0].AddParagraph().AppendText(apr.lab.manipulatedChemicalResidues[i].name);
                chemicalResiduesTable[i + 1, 1].AddParagraph().AppendText(apr.lab.manipulatedChemicalResidues[i].physicalState);
                chemicalResiduesTable[i + 1, 2].AddParagraph().AppendText(apr.lab.manipulatedChemicalResidues[i].origin);
                chemicalResiduesTable[i + 1, 3].AddParagraph().AppendText(apr.lab.manipulatedChemicalResidues[i].quantity + " " + apr.lab.manipulatedChemicalResidues[i].measurementUnit);
                chemicalResiduesTable[i + 1, 4].AddParagraph().AppendText(apr.lab.manipulatedChemicalResidues[i].dangerCharacteristics);
                chemicalResiduesTable[i + 1, 5].AddParagraph().AppendText(apr.lab.manipulatedChemicalResidues[i].inert ? Resources.Language.pt_local.Yes : Resources.Language.pt_local.No);
                chemicalResiduesTable[i + 1, 6].AddParagraph().AppendText(apr.lab.manipulatedChemicalResidues[i].container);
                chemicalResiduesTable[i + 1, 7].AddParagraph().AppendText(apr.lab.manipulatedChemicalResidues[i].storageDetails);
            }
        }
Beispiel #4
0
 public void AddTable(int rows, int cols, string styleStr)
 {
     m_table = m_section.AddTable();
     m_table.ResetCells(rows, cols);
     m_table.TableFormat.Borders.BorderType = SfUtils.String2BorderStyle(styleStr);
     m_table.TableFormat.IsAutoResized      = true;
 }
        static void Main(string[] args)
        {
            using (WordDocument document = new WordDocument(@"InputWordFile.docx"))
            {
                int sectionCount = document.Sections.Count;
                for (int i = 0; i < sectionCount; i++)
                {
                    IWSection section     = document.Sections[i];
                    int       entityCount = section.Body.ChildEntities.Count;
                    for (int j = 0; j < entityCount; j++)
                    {
                        IEntity entity = section.Body.ChildEntities[j];
                        switch (entity.EntityType)
                        {
                        case EntityType.Paragraph:
                            IWParagraph paragraph = entity.Clone() as IWParagraph;
                            document.LastSection.Body.ChildEntities.Add(paragraph);
                            break;

                        case EntityType.Table:
                            IWTable table = entity.Clone() as IWTable;
                            document.LastSection.Body.ChildEntities.Add(table);
                            break;
                        }
                    }
                }
                document.Save("ResultDocument.docx");
            }
        }
 private static void AddTitlesToTable(IWTable info)
 {
     info.Rows[0].Cells[0].AddParagraph().AppendText("Date");
     info.Rows[0].Cells[1].AddParagraph().AppendText("Initiative");
     info.Rows[0].Cells[2].AddParagraph().AppendText("Start Time");
     info.Rows[0].Cells[3].AddParagraph().AppendText("End Time");
     info.Rows[0].Cells[4].AddParagraph().AppendText("Elapsed Time");
 }
Beispiel #7
0
        private void InsertFirstPageHeaderFooter(WordDocument doc, IWSection section)
        {
            Assembly execAssm = typeof(HeadersAndFootersDemo).GetTypeInfo().Assembly;

            Stream inputStream = execAssm.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.DocIO.DocIO.Assets.Northwind_logo.png");

            // Add a new paragraph for header to the document.
            IWParagraph headerPar = new WParagraph(doc);

            // Add a new table to the header.
            IWTable table = section.HeadersFooters.FirstPageHeader.AddTable();

            RowFormat format = new RowFormat();

            // Setting cleared table border style.
            format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Cleared;

            // Inserting table with a row and two columns.
            table.ResetCells(1, 2, format, 265);

            // Inserting logo image to the table first cell.
            headerPar = table[0, 0].AddParagraph() as WParagraph;
            headerPar.AppendPicture(inputStream);
            //Set Image size
            (headerPar.Items[0] as WPicture).Width  = 232.5f;
            (headerPar.Items[0] as WPicture).Height = 54.75f;
            // Inserting text to the table second cell.
            headerPar = table[0, 1].AddParagraph() as WParagraph;
            IWTextRange txt = headerPar.AppendText("Company Headquarters,\n2501 Aerial Center Parkway,\nSuite 110, Morrisville, NC 27560,\nTEL 1-888-936-8638.");

            txt.CharacterFormat.FontSize                  = 12;
            txt.CharacterFormat.CharacterSpacing          = 1.7f;
            headerPar.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Right;
            // Add a new paragraph to the header with address text.
            headerPar = new WParagraph(doc);
            headerPar.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            txt = headerPar.AppendText("\nFirst Page Header");
            txt.CharacterFormat.CharacterSpacing = 1.7f;
            section.HeadersFooters.FirstPageHeader.Paragraphs.Add(headerPar);

            // Add a footer paragraph text to the document.
            WParagraph footerPar = new WParagraph(doc);

            footerPar.ParagraphFormat.Tabs.AddTab(523f, TabJustification.Right, TabLeader.NoLeader);
            // Add text.
            footerPar.AppendText("Copyright Northwind Inc. 2001 - 2015");
            // Add page and Number of pages field to the document.
            footerPar.AppendText("\tFirst Page ");
            footerPar.AppendField("Page", FieldType.FieldPage);
            section.HeadersFooters.FirstPageFooter.Paragraphs.Add(footerPar);
            #region Page Number Settings
            section.PageSetup.RestartPageNumbering = true;
            section.PageSetup.PageStartingNumber   = Convert.ToInt32(this.numericUpDown1.Value);
            section.PageSetup.PageNumberStyle      = (PageNumberStyle)Enum.Parse(typeof(PageNumberStyle), this.comboBox1.SelectedItem.ToString(), true);
            #endregion
        }
Beispiel #8
0
        private void exportarWord()
        {
            using (MemoryStream ms = new MemoryStream())
            {
                WordDocument document = new WordDocument();

                WSection section = document.AddSection() as WSection;

                section.PageSetup.Margins.All = 72;

                IWParagraph paragraph = section.AddParagraph();

                paragraph.ApplyStyle("Normal");

                paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;

                WTextRange textRange = paragraph.AppendText(tituloReporte) as WTextRange;
                textRange.CharacterFormat.FontSize  = 20f;
                textRange.CharacterFormat.FontName  = "Calibri";
                textRange.CharacterFormat.TextColor = Syncfusion.Drawing.Color.Blue;

                IWTable table           = section.AddTable();
                int     numeroCabeceras = cabecalho.Length;
                int     numeroFilas     = lista.Length;
                table.ResetCells(numeroFilas + 1, numeroCabeceras);

                for (int i = 0; i < numeroCabeceras; i++)
                {
                    table[0, i].AddParagraph().AppendText(cabecalho[i]);
                }

                int fila = 1;
                int col  = 0;
                foreach (object item in lista)
                {
                    col = 0;
                    foreach (string prop in nomesPropriedadesCabecalho)
                    {
                        table[fila, col].AddParagraph().AppendText(
                            item.GetType().GetProperty(prop).GetValue(item).ToString()
                            );
                        col++;
                    }
                    fila++;
                }


                document.Save(ms, FormatType.Docx);

                byte[] buffer = ms.ToArray();
                string base64 = Convert.ToBase64String(buffer);

                word = "data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64," + base64;
            }
        }
Beispiel #9
0
        private void InsertFirstPageHeaderFooter(WordDocument doc, IWSection section)
        {
            // Add a new paragraph for header to the document.
            IWParagraph headerPar = new WParagraph(doc);

            // Add a new table to the header.
            IWTable table = section.HeadersFooters.FirstPageHeader.AddTable();

            RowFormat format = new RowFormat();

            // Setting cleared table border style.
            format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Cleared;

            // Inserting table with a row and two columns.
            table.ResetCells(1, 2, format, 265);

            // Inserting logo image to the table first cell.
            headerPar = table[0, 0].AddParagraph() as WParagraph;
            string     basePath    = _hostingEnvironment.WebRootPath;
            FileStream imageStream = new FileStream(basePath + @"/images/DocIO/Northwind_logo.png", FileMode.Open, FileAccess.Read);

            headerPar.AppendPicture(imageStream);
            //Set Image size
            (headerPar.Items[0] as WPicture).Width  = 232.5f;
            (headerPar.Items[0] as WPicture).Height = 54.75f;
            // Inserting text to the table second cell.
            headerPar = table[0, 1].AddParagraph() as WParagraph;
            IWTextRange txt = headerPar.AppendText("Company Headquarters,\n2501 Aerial Center Parkway,\nSuite 110, Morrisville, NC 27560,\nTEL 1-888-936-8638.");

            txt.CharacterFormat.FontSize                  = 12;
            txt.CharacterFormat.CharacterSpacing          = 1.7f;
            headerPar.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Right;
            // Add a new paragraph to the header with address text.
            headerPar = new WParagraph(doc);
            headerPar.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            txt = headerPar.AppendText("\nFirst Page Header");
            txt.CharacterFormat.CharacterSpacing = 1.7f;
            section.HeadersFooters.FirstPageHeader.Paragraphs.Add(headerPar);

            // Add a footer paragraph text to the document.
            WParagraph footerPar = new WParagraph(doc);

            footerPar.ParagraphFormat.Tabs.AddTab(523f, TabJustification.Right, TabLeader.NoLeader);
            // Add text.
            footerPar.AppendText("Copyright Northwind Inc. 2001 - 2017");
            // Add page and Number of pages field to the document.
            footerPar.AppendText("\tFirst Page ");
            footerPar.AppendField("Page", FieldType.FieldPage);
            section.HeadersFooters.FirstPageFooter.Paragraphs.Add(footerPar);
            #region Page Number Settings
            section.PageSetup.RestartPageNumbering = true;
            section.PageSetup.PageStartingNumber   = 1;
            section.PageSetup.PageNumberStyle      = PageNumberStyle.Arabic;
            #endregion Page Number Settings
        }
Beispiel #10
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");
        }
        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"));
        }
Beispiel #12
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());
            }
        }
Beispiel #13
0
        /// <summary>
        /// Inserts Header and Footer to first page.
        /// </summary>
        private void InsertFirstPageHeaderFooter(WordDocument doc, IWSection section)
        {
            //Adds a new table to the header.
            IWTable table = section.HeadersFooters.FirstPageHeader.AddTable();

            RowFormat format = new();

            //Sets cleared table border style.
            format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Cleared;

            //Inserts table with a row and two columns.
            table.ResetCells(1, 2, format, 265);

            //Inserts logo image to the table first cell.
            IWParagraph headerPara  = table[0, 0].AddParagraph() as WParagraph;
            Stream      imageStream = assembly.GetManifestResourceStream("syncfusion.dociodemos.winui.Assets.DocIO.Northwindlogo.png");

            headerPara.AppendPicture(imageStream);
            //Sets Image size
            (headerPara.Items[0] as WPicture).Width  = 232.5f;
            (headerPara.Items[0] as WPicture).Height = 54.75f;

            //Inserts text to the table second cell.
            headerPara = table[0, 1].AddParagraph() as WParagraph;
            IWTextRange txt = headerPara.AppendText("Company Headquarters,\n2501 Aerial Center Parkway,\nSuite 110, Morrisville, NC 27560,\nTEL 1-888-936-8638.");

            txt.CharacterFormat.FontSize                   = 12;
            txt.CharacterFormat.CharacterSpacing           = 1.7f;
            headerPara.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Right;
            //Adds a new paragraph to the header with address text.
            headerPara = new WParagraph(doc);
            headerPara.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            txt = headerPara.AppendText("\nFirst Page Header");
            txt.CharacterFormat.CharacterSpacing = 1.7f;
            section.HeadersFooters.FirstPageHeader.Paragraphs.Add(headerPara);

            //Adds a footer paragraph text to the document.
            WParagraph footerPara = new(doc);

            footerPara.ParagraphFormat.Tabs.AddTab(523f, TabJustification.Right, TabLeader.NoLeader);
            //Adds text.
            footerPara.AppendText("Copyright Northwind Inc. 2001 - 2021");
            //Adds page and Number of pages field to the document.
            footerPara.AppendText("\tPage ");
            footerPara.AppendField("Page", FieldType.FieldPage);
            footerPara.AppendText(" of ");
            footerPara.AppendField("NumPages", FieldType.FieldNumPages);
            section.HeadersFooters.FirstPageFooter.Paragraphs.Add(footerPara);
            #region Page Number Settings
            section.PageSetup.RestartPageNumbering = true;
            section.PageSetup.PageStartingNumber   = 1;
            section.PageSetup.PageNumberStyle      = PageNumberStyle.Arabic;
            #endregion Page Number Settings
        }
Beispiel #14
0
        private void InsertPageHeaderFooter(WordDocument doc, IWSection section1)
        {
             // Add a new paragraph for header to the document.
            IWParagraph headerPar = new WParagraph(doc);

            // Add a new table to the header
            IWTable table = section1.HeadersFooters.Header.AddTable();

            RowFormat format = new RowFormat();

            // Setting Single table border style.
            format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;

            // Inserting table with a row and two columns.
            table.ResetCells(1, 2, format, 265);

            // Inserting logo image to the table first cell.
            headerPar = table[0, 0].AddParagraph() as WParagraph;
#if NETCORE
            headerPar.AppendPicture(Image.FromFile(@"..\..\..\..\..\..\..\..\Common\images\DocIO\Northwind_logo.png"));
#else                       
            headerPar.AppendPicture(Image.FromFile(@"..\..\..\..\..\..\..\Common\images\DocIO\Northwind_logo.png"));
#endif				
            //Set Image size.
            (headerPar.Items[0] as WPicture).Width = 232.5f;
            (headerPar.Items[0] as WPicture).Height = 54.75f;
            // Inserting text to the table second cell.
            headerPar = table[0, 1].AddParagraph() as WParagraph;
            IWTextRange txt = headerPar.AppendText("Company Headquarters,\n2501 Aerial Center Parkway,\nSuite 110, Morrisville, NC 27560,\nTEL 1-888-936-8638.");
            txt.CharacterFormat.FontSize = 12;
            txt.CharacterFormat.CharacterSpacing = 1.7f;
            headerPar.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Right;

            // Add a footer paragraph text to the document.
            WParagraph footerPar = new WParagraph(doc);
            footerPar.ParagraphFormat.Tabs.AddTab(523f, TabJustification.Right, TabLeader.NoLeader);
            // Add text.
            footerPar.AppendText("Copyright Northwind Inc. 2001 - 2017");
            // Add page and Number of pages field to the document.
            footerPar.AppendText("\tPage ");
            IWField ff = footerPar.AppendField("Page", Syncfusion.DocIO.FieldType.FieldPage);

            section1.HeadersFooters.Footer.Paragraphs.Add(footerPar);

            #region Page Number Settings
            section1.PageSetup.RestartPageNumbering = true;
            section1.PageSetup.PageStartingNumber = Convert.ToInt32(this.numericUpDown1.Value);
            section1.PageSetup.PageNumberStyle = (PageNumberStyle)Enum.Parse(typeof(PageNumberStyle), this.comboBox1.SelectedItem.ToString(), true);
            #endregion

        }
Beispiel #15
0
        private void InsertPageHeaderFooter(WordDocument doc, IWSection section1)
        {
            // Add a new paragraph for header to the document.
            IWParagraph headerPar = new WParagraph(doc);

            // Add a new table to the header
            IWTable table = section1.HeadersFooters.Header.AddTable();

            RowFormat format = new RowFormat();

            // Setting Single table border style.
            format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;

            // Inserting table with a row and two columns.
            table.ResetCells(1, 2, format, 265);

            // Inserting logo image to the table first cell.
            headerPar = table[0, 0].AddParagraph() as WParagraph;
            string s = ResolveApplicationDataPath("Northwind_logo.png", "Content\\DocIO");

            headerPar.AppendPicture(System.Drawing.Image.FromFile(s));
            //Set Image size.
            (headerPar.Items[0] as WPicture).Width  = 232.5f;
            (headerPar.Items[0] as WPicture).Height = 54.75f;
            // Inserting text to the table second cell.
            headerPar = table[0, 1].AddParagraph() as WParagraph;
            IWTextRange txt = headerPar.AppendText("Company Headquarters,\n2501 Aerial Center Parkway,\nSuite 110, Morrisville, NC 27560,\nTEL 1-888-936-8638.");

            txt.CharacterFormat.FontSize                  = 12;
            txt.CharacterFormat.CharacterSpacing          = 1.7f;
            headerPar.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Right;

            // Add a footer paragraph text to the document.
            WParagraph footerPar = new WParagraph(doc);

            footerPar.ParagraphFormat.Tabs.AddTab(523f, TabJustification.Right, TabLeader.NoLeader);
            // Add text.
            footerPar.AppendText("Copyright Northwind Inc. 2001 - 2017");
            // Add page and Number of pages field to the document.
            footerPar.AppendText("\tPage ");
            IWField ff = footerPar.AppendField("Page", FieldType.FieldPage);

            section1.HeadersFooters.Footer.Paragraphs.Add(footerPar);

            #region Page Number Settings
            section1.PageSetup.RestartPageNumbering = true;
            section1.PageSetup.PageStartingNumber   = 1;
            section1.PageSetup.PageNumberStyle      = PageNumberStyle.Arabic;
            #endregion Page Number Settings
        }
Beispiel #16
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");
        }
Beispiel #17
0
        private void AddMechanicalAgentsTable()
        {
            IWTable mechanicalAgentsTable = GetCurrentSection().AddTable();

            mechanicalAgentsTable.ResetCells(apr.lab.mechanicalAgentsInfo.Count + 1, 3);
            mechanicalAgentsTable[0, 0].AddParagraph().AppendText(Resources.Language.pt_local.Agent);
            mechanicalAgentsTable[0, 1].AddParagraph().AppendText(Resources.Language.pt_local.AssociatedRisk);
            mechanicalAgentsTable[0, 2].AddParagraph().AppendText(Resources.Language.pt_local.AdditionalInformation);
            for (int i = 0; i < apr.lab.mechanicalAgentsInfo.Count; i++)
            {
                mechanicalAgentsTable[i + 1, 0].AddParagraph().AppendText(apr.lab.mechanicalAgentsInfo[i].name);
                mechanicalAgentsTable[i + 1, 1].AddParagraph().AppendText(apr.lab.mechanicalAgentsInfo[i].associatedRisk);
                mechanicalAgentsTable[i + 1, 2].AddParagraph().AppendText(apr.lab.mechanicalAgentsInfo[i].additionalInfo);
            }
        }
Beispiel #18
0
        private void AddPhysicalAgentsTable()
        {
            IWTable physicalAgentsTable = GetCurrentSection().AddTable();

            physicalAgentsTable.ResetCells(apr.lab.physicalAgentsInfo.Count + 1, 3);
            physicalAgentsTable[0, 0].AddParagraph().AppendText(Resources.Language.pt_local.Equipment);
            physicalAgentsTable[0, 1].AddParagraph().AppendText(Resources.Language.pt_local.Usage);
            physicalAgentsTable[0, 2].AddParagraph().AppendText(Resources.Language.pt_local.AssociatedRisk);
            for (int i = 0; i < apr.lab.physicalAgentsInfo.Count; i++)
            {
                physicalAgentsTable[i + 1, 0].AddParagraph().AppendText(apr.lab.physicalAgentsInfo[i].equipment);
                physicalAgentsTable[i + 1, 1].AddParagraph().AppendText(apr.lab.physicalAgentsInfo[i].usage);
                physicalAgentsTable[i + 1, 2].AddParagraph().AppendText(apr.lab.physicalAgentsInfo[i].generatedRisks);
            }
        }
Beispiel #19
0
        private void AddBiologicalAgentsTable()
        {
            IWTable bioAgentsTable = GetCurrentSection().AddTable();

            bioAgentsTable.ResetCells(apr.lab.biologicalAgentsInfo.biologicalAgentList.Count + 1, 3);
            bioAgentsTable[0, 0].AddParagraph().AppendText(Resources.Language.pt_local.Name);
            bioAgentsTable[0, 1].AddParagraph().AppendText(Resources.Language.pt_local.RiskClassification);
            bioAgentsTable[0, 2].AddParagraph().AppendText(Resources.Language.pt_local.Usage);

            for (int i = 0; i < apr.lab.biologicalAgentsInfo.biologicalAgentList.Count; i++)
            {
                bioAgentsTable[i + 1, 0].AddParagraph().AppendText(apr.lab.biologicalAgentsInfo.biologicalAgentList[i].name);
                bioAgentsTable[i + 1, 1].AddParagraph().AppendText(apr.lab.biologicalAgentsInfo.biologicalAgentList[i].riskClassification);
                bioAgentsTable[i + 1, 2].AddParagraph().AppendText(apr.lab.biologicalAgentsInfo.biologicalAgentList[i].usageScenarios);
            }
        }
Beispiel #20
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);
        }
Beispiel #21
0
        private void AddIdentifiedRisksTable()
        {
            IWTable risksTable = GetCurrentSection().AddTable();

            risksTable.ResetCells(apr.lab.riskAnalysisInformation.identifiedRisks.Count + 1, 6);
            risksTable[0, 0].AddParagraph().AppendText(Resources.Language.pt_local.Risk);
            risksTable[0, 1].AddParagraph().AppendText(Resources.Language.pt_local.Danger);
            risksTable[0, 2].AddParagraph().AppendText(Resources.Language.pt_local.SafetyNet);
            risksTable[0, 3].AddParagraph().AppendText(Resources.Language.pt_local.SeverityClassification);
            risksTable[0, 4].AddParagraph().AppendText(Resources.Language.pt_local.FrequencyClassification);
            risksTable[0, 5].AddParagraph().AppendText(Resources.Language.pt_local.RiskClassification);

            for (int i = 0; i < apr.lab.riskAnalysisInformation.identifiedRisks.Count; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    risksTable[i + 1, j].AddParagraph().AppendText(apr.lab.riskAnalysisInformation.GetFormattedRiskList()[i][j]);
                }
            }
        }
Beispiel #22
0
        private void AddRoomsBuildingsTimesTable()
        {
            // Create table with rooms, buildings and time ranges
            IWTable unit_spaces_table = GetCurrentSection().AddTable();

            unit_spaces_table.ResetCells(apr.unit.structure.spaces.Count + 1, 6);
            unit_spaces_table[0, 0].AddParagraph().AppendText(Resources.Language.pt_local.Building);
            unit_spaces_table[0, 1].AddParagraph().AppendText(Resources.Language.pt_local.Room);
            unit_spaces_table[0, 2].AddParagraph().AppendText(Resources.Language.pt_local.Floor);
            unit_spaces_table[0, 3].AddParagraph().AppendText(Resources.Language.pt_local.UsagePeriod);
            unit_spaces_table[0, 4].AddParagraph().AppendText(Resources.Language.pt_local.SurroundingsComments);
            unit_spaces_table[0, 5].AddParagraph().AppendText(Resources.Language.pt_local.Days);
            for (int i = 0; i < apr.unit.structure.spaces.Count; i++)
            {
                unit_spaces_table[i + 1, 0].AddParagraph().AppendText(apr.unit.structure.spaces[i].buildingIdentifier);
                unit_spaces_table[i + 1, 1].AddParagraph().AppendText(apr.unit.structure.spaces[i].roomIdentifier);
                unit_spaces_table[i + 1, 2].AddParagraph().AppendText(apr.unit.structure.spaces[i].floorIdentifier);
                unit_spaces_table[i + 1, 3].AddParagraph().AppendText(apr.unit.structure.spaces[i].turnStart.ToString() + " - " + apr.unit.structure.spaces[i].turnEnd.ToString());
                unit_spaces_table[i + 1, 4].AddParagraph().AppendText(apr.unit.structure.spaces[i].surroundingsComments);
                unit_spaces_table[i + 1, 5].AddParagraph().AppendText(apr.unit.structure.spaces[i].weekDays);
            }
        }
Beispiel #23
0
        private void AddTeamCompositionTableForLabs()
        {
            IWTable labTeamTable = GetCurrentSection().AddTable();

            labTeamTable.ResetCells(5, 2);
            labTeamTable[0, 0].AddParagraph().AppendText(Resources.Language.pt_local.Type);
            labTeamTable[0, 1].AddParagraph().AppendText(Resources.Language.pt_local.Quantity);

            // Public
            labTeamTable[1, 0].AddParagraph().AppendText(Resources.Language.pt_local.Public);
            labTeamTable[1, 1].AddParagraph().AppendText(apr.lab.spaceCharacterization.generalPublicCount.ToString());

            // Students
            labTeamTable[2, 0].AddParagraph().AppendText(Resources.Language.pt_local.Students);
            labTeamTable[2, 1].AddParagraph().AppendText(apr.lab.spaceCharacterization.studentsCount.ToString());

            // Teachers
            labTeamTable[3, 0].AddParagraph().AppendText(Resources.Language.pt_local.Teachers);
            labTeamTable[3, 1].AddParagraph().AppendText(apr.lab.spaceCharacterization.teachersCount.ToString());

            // Technics
            labTeamTable[4, 0].AddParagraph().AppendText(Resources.Language.pt_local.Technics);
            labTeamTable[4, 1].AddParagraph().AppendText(apr.lab.spaceCharacterization.technicsCount.ToString());
        }
        private static int AddDataToTable(IWTable info, int row, VolunteerActivity activity, DbSet <Initiative> initiatives)
        {
            info.AddRow();
            row += 1;
            info.Rows[row].Height = 20;
            string Start = activity.StartTime.ToString();
            string End   = activity.EndTime.ToString();


            var StartAMPM = activity.StartTime.ToString("hh:mm:ss tt", CultureInfo.InvariantCulture);
            var EndAMPM   = activity.EndTime.ToString("hh:mm:ss tt", CultureInfo.InvariantCulture);


            int id = activity.InitiativeId;

            info.Rows[row].Cells[0].AddParagraph().AppendText(Start.Split(' ')[0]);
            info.Rows[row].Cells[1].AddParagraph().AppendText(initiatives.Single(m => m.InitiativeID == id).Description);
            // info.Rows[row].Cells[2].AddParagraph().AppendText(Start.Split(' ')[1]);
            info.Rows[row].Cells[2].AddParagraph().AppendText(StartAMPM);
            info.Rows[row].Cells[3].AddParagraph().AppendText(EndAMPM);
            // info.Rows[row].Cells[3].AddParagraph().AppendText(End.Split(' ')[1]);
            info.Rows[row].Cells[4].AddParagraph().AppendText(activity.ElapsedTime.ToString().Split('.')[0]);
            return(row);
        }
Beispiel #25
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                // Create a new document.
                WordDocument document = new WordDocument();
                // Adding a new section to the document.
                IWSection section = document.AddSection();
                section.PageSetup.Margins.All        = 50;
                section.PageSetup.DifferentFirstPage = true;
                IWTextRange textRange;
                IWParagraph paragraph = section.AddParagraph();


                #region Table Cell Spacing.
                // --------------------------------------------
                // Table Cell Spacing.
                // --------------------------------------------
                paragraph.AppendText("Table Cell spacing...").CharacterFormat.FontSize = 14;

                section.AddParagraph();
                paragraph = section.AddParagraph();
                WTextBody textBody = section.Body;

                // Adding a new Table to the textbody.
                IWTable table = textBody.AddTable();
                table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
                table.TableFormat.Paddings.All       = 5.4f;
                RowFormat format = new RowFormat();

                format.Paddings.All       = 5;
                format.CellSpacing        = 2;
                format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DotDash;
                format.IsBreakAcrossPages = true;
                table.ResetCells(25, 5, format, 90);
                IWTextRange text;
                table.Rows[0].IsHeader = true;

                for (int i = 0; i < table.Rows[0].Cells.Count; i++)
                {
                    paragraph = table[0, i].AddParagraph() as WParagraph;
                    paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                    text = paragraph.AppendText(string.Format("Header {0}", i + 1));
                    text.CharacterFormat.Font        = new Font("Bitstream Vera Serif", 10);
                    text.CharacterFormat.Bold        = true;
                    text.CharacterFormat.TextColor   = Color.FromArgb(0, 21, 84);
                    table[0, i].CellFormat.BackColor = Color.FromArgb(203, 211, 226);
                }

                for (int i = 1; i < table.Rows.Count; i++)
                {
                    for (int j = 0; j < 5; j++)
                    {
                        paragraph = table[i, j].AddParagraph() as WParagraph;
                        paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;

                        text = paragraph.AppendText(string.Format("Cell {0} , {1}", i, j + 1));
                        text.CharacterFormat.TextColor = Color.FromArgb(242, 151, 50);
                        text.CharacterFormat.Bold      = true;
                        if (i % 2 != 1)
                        {
                            table[i, j].CellFormat.BackColor = Color.FromArgb(231, 235, 245);
                        }
                        else
                        {
                            table[i, j].CellFormat.BackColor = Color.FromArgb(246, 249, 255);
                        }
                    }
                }
                (table as WTable).AutoFit(AutoFitType.FitToContent);
                #endregion Table Cell Spacing.

                #region Nested Table
                // --------------------------------------------
                // Nested Table.
                // --------------------------------------------

                section.AddParagraph();
                paragraph = section.AddParagraph();
                paragraph.ParagraphFormat.PageBreakBefore = true;
                paragraph.AppendText("Nested Table...").CharacterFormat.FontSize = 14;

                section.AddParagraph();
                paragraph = section.AddParagraph();
                textBody  = section.Body;

                // Adding a new Table to the textbody.
                table = textBody.AddTable();

                format = new RowFormat();
                format.Paddings.All       = 5;
                format.CellSpacing        = 2.5f;
                format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DotDash;
                table.ResetCells(5, 3, format, 100);


                for (int i = 0; i < table.Rows[0].Cells.Count; i++)
                {
                    paragraph = table[0, i].AddParagraph() as WParagraph;
                    paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                    text = paragraph.AppendText(string.Format("Header {0}", i + 1));
                    text.CharacterFormat.Font        = new Font("Bitstream Vera Serif", 10);
                    text.CharacterFormat.Bold        = true;
                    text.CharacterFormat.TextColor   = Color.FromArgb(0, 21, 84);
                    table[0, i].CellFormat.BackColor = Color.FromArgb(242, 151, 50);
                }
                table[0, 2].Width = 200;
                for (int i = 1; i < table.Rows.Count; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        paragraph = table[i, j].AddParagraph() as WParagraph;
                        paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;

                        if ((i == 2) && (j == 2))
                        {
                            text = paragraph.AppendText("Nested Table");
                        }

                        else
                        {
                            text = paragraph.AppendText(string.Format("Cell {0} , {1}", i, j + 1));
                        }

                        if ((j == 2))
                        {
                            table[i, j].Width = 200;
                        }

                        text.CharacterFormat.TextColor = Color.FromArgb(242, 151, 50);
                        text.CharacterFormat.Bold      = true;
                    }
                }

                // Adding a nested Table.
                IWTable nestTable = table[2, 2].AddTable();

                format = new RowFormat();

                format.Borders.BorderType  = Syncfusion.DocIO.DLS.BorderStyle.DotDash;
                format.HorizontalAlignment = RowAlignment.Center;
                nestTable.ResetCells(3, 3, format, 45);

                for (int i = 0; i < nestTable.Rows.Count; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        paragraph = nestTable[i, j].AddParagraph() as WParagraph;
                        paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;

                        nestTable[i, j].CellFormat.BackColor = Color.FromArgb(231, 235, 245);
                        text = paragraph.AppendText(string.Format("Cell {0} , {1}", i, j + 1));
                        text.CharacterFormat.TextColor = Color.Black;
                        text.CharacterFormat.Bold      = true;
                    }
                }
                (nestTable as WTable).AutoFit(AutoFitType.FitToContent);
                (table as WTable).AutoFit(AutoFitType.FitToWindow);
                #endregion Nested Table

                #region Table with Images
                string dataPath = Application.StartupPath + @"..\..\..\..\..\..\..\..\Common\images\DocIO\";

                //Add a new section to the document.
                section = document.AddSection();
                //Add paragraph to the section.
                paragraph = section.AddParagraph();
                //Writing text.
                textRange = paragraph.AppendText("Table with Images");
                textRange.CharacterFormat.FontSize  = 13f;
                textRange.CharacterFormat.TextColor = Color.DarkBlue;
                textRange.CharacterFormat.Bold      = true;

                //Add paragraph to the section.
                section.AddParagraph();
                paragraph = section.AddParagraph();

                text = null;

                //Adding a new Table to the paragraph.
                table = section.Body.AddTable();
                table.ResetCells(1, 3);

                //Adding rows to the table.
                WTableRow row = table.Rows[0];
                //Set heading row height
                row.Height = 25f;
                //set heading values to the Table.
                for (int i = 0; i < 3; i++)
                {
                    //Add paragraph for writing Text to the cells.
                    paragraph = (IWParagraph)row.Cells[i].AddParagraph();
                    //Set Horizontal Alignment as Center.
                    paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                    //Writing Row Heading
                    switch (i)
                    {
                    case 0:
                        text = paragraph.AppendText("SNO");
                        row.Cells[i].Width = 50f; break;

                    case 1: text = paragraph.AppendText("Drinks"); break;

                    case 2: text = paragraph.AppendText("Showcase Image"); row.Cells[i].Width = 200f; break;
                    }
                    //Set row Heading formatting
                    text.CharacterFormat.Bold      = true;
                    text.CharacterFormat.FontName  = "Cambria";
                    text.CharacterFormat.FontSize  = 11f;
                    text.CharacterFormat.TextColor = Color.White;

                    //Set row cells formatting
                    row.Cells[i].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                    row.Cells[i].CellFormat.BackColor         = Color.FromArgb(157, 161, 190);

                    row.Cells[i].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
                }

                int sno = 1;
                //Writing Sno, Product name and Product Images to the Table.

                WTableRow row1 = table.AddRow(false);

                //Writing SNO to the table with formatting text.
                paragraph = (IWParagraph)row1.Cells[0].AddParagraph();
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                text = paragraph.AppendText(sno.ToString());
                text.CharacterFormat.Bold     = true;
                text.CharacterFormat.FontSize = 10f;
                row1.Cells[0].CellFormat.VerticalAlignment  = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                row1.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
                row1.Cells[0].CellFormat.BackColor          = Color.FromArgb(217, 223, 239);
                //Writing Product Name to the table with Formatting.
                paragraph = (IWParagraph)row1.Cells[1].AddParagraph();
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                text = paragraph.AppendText("Apple Juice");
                text.CharacterFormat.Bold                   = true;
                text.CharacterFormat.FontSize               = 10f;
                text.CharacterFormat.TextColor              = Color.FromArgb(50, 65, 124);
                row1.Cells[1].CellFormat.VerticalAlignment  = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                row1.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
                row1.Cells[1].CellFormat.BackColor          = Color.FromArgb(217, 223, 239);

                //Writing Product Images to the Table.
                paragraph = (IWParagraph)row1.Cells[2].AddParagraph();
                paragraph.AppendPicture(Image.FromFile(dataPath + "Apple Juice.png"));
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                row1.Cells[2].CellFormat.VerticalAlignment    = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                row1.Cells[2].CellFormat.Borders.BorderType   = Syncfusion.DocIO.DLS.BorderStyle.Single;
                row1.Cells[2].CellFormat.BackColor            = Color.FromArgb(217, 223, 239);
                sno++;
                row1 = table.AddRow(false);

                //Writing SNO to the table with formatting text.
                paragraph = (IWParagraph)row1.Cells[0].AddParagraph();
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                text = paragraph.AppendText(sno.ToString());
                text.CharacterFormat.Bold     = true;
                text.CharacterFormat.FontSize = 10f;
                row1.Cells[0].CellFormat.VerticalAlignment  = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                row1.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
                row1.Cells[0].CellFormat.BackColor          = Color.FromArgb(217, 223, 239);
                //Writing Product Name to the table with Formatting.
                paragraph = (IWParagraph)row1.Cells[1].AddParagraph();
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                text = paragraph.AppendText("Grape Juice");
                text.CharacterFormat.Bold                   = true;
                text.CharacterFormat.FontSize               = 10f;
                text.CharacterFormat.TextColor              = Color.FromArgb(50, 65, 124);
                row1.Cells[1].CellFormat.VerticalAlignment  = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                row1.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
                row1.Cells[1].CellFormat.BackColor          = Color.FromArgb(217, 223, 239);

                //Writing Product Images to the Table.
                paragraph = (IWParagraph)row1.Cells[2].AddParagraph();
                paragraph.AppendPicture(Image.FromFile(dataPath + "Grape Juice.png"));
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                row1.Cells[2].CellFormat.VerticalAlignment    = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                row1.Cells[2].CellFormat.Borders.BorderType   = Syncfusion.DocIO.DLS.BorderStyle.Single;
                row1.Cells[2].CellFormat.BackColor            = Color.FromArgb(217, 223, 239);
                sno++;
                row1 = table.AddRow(false);

                //Writing SNO to the table with formatting text.
                paragraph = (IWParagraph)row1.Cells[0].AddParagraph();
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                text = paragraph.AppendText(sno.ToString());
                text.CharacterFormat.Bold     = true;
                text.CharacterFormat.FontSize = 10f;
                row1.Cells[0].CellFormat.VerticalAlignment  = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                row1.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
                row1.Cells[0].CellFormat.BackColor          = Color.FromArgb(217, 223, 239);
                //Writing Product Name to the table with Formatting.
                paragraph = (IWParagraph)row1.Cells[1].AddParagraph();
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                text = paragraph.AppendText("Hot Soup");
                text.CharacterFormat.Bold                   = true;
                text.CharacterFormat.FontSize               = 10f;
                text.CharacterFormat.TextColor              = Color.FromArgb(50, 65, 124);
                row1.Cells[1].CellFormat.VerticalAlignment  = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                row1.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
                row1.Cells[1].CellFormat.BackColor          = Color.FromArgb(217, 223, 239);

                //Writing Product Images to the Table.
                paragraph = (IWParagraph)row1.Cells[2].AddParagraph();
                paragraph.AppendPicture(Image.FromFile(dataPath + "Hot Soup.png"));
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                row1.Cells[2].CellFormat.VerticalAlignment    = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                row1.Cells[2].CellFormat.Borders.BorderType   = Syncfusion.DocIO.DLS.BorderStyle.Single;
                row1.Cells[2].CellFormat.BackColor            = Color.FromArgb(217, 223, 239);
                sno++;
                (table as WTable).AutoFit(AutoFitType.FixedColumnWidth);
                #endregion Table with Images
                //Save as doc format
                if (wordDocRadioBtn.Checked)
                {
                    //Saving the document to disk.
                    document.Save("Sample.doc");

                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
#if NETCORE
                        System.Diagnostics.Process process = new System.Diagnostics.Process();
                        process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.doc")
                        {
                            UseShellExecute = true
                        };
                        process.Start();
#else
                        System.Diagnostics.Process.Start("Sample.doc");
#endif
                        //Exit
                        this.Close();
                    }
                }
                //Save as docx format
                else if (wordDocxRadioBtn.Checked)
                {
                    //Saving the document as .docx
                    document.Save("Sample.docx", FormatType.Docx);
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
#if NETCORE
                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.docx")
                            {
                                UseShellExecute = true
                            };
                            process.Start();
#else
                            System.Diagnostics.Process.Start("Sample.docx");
#endif
                            //Exit
                            this.Close();
                        }
                        catch (Win32Exception ex)
                        {
                            MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                //Save as pdf format
                else if (pdfRadioBtn.Checked)
                {
                    DocToPDFConverter converter = new DocToPDFConverter();
                    //Convert word document into PDF document
                    PdfDocument pdfDoc = converter.ConvertToPDF(document);
                    //Save the pdf file
                    pdfDoc.Save("Sample.pdf");
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
#if NETCORE
                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.pdf")
                            {
                                UseShellExecute = true
                            };
                            process.Start();
#else
                            System.Diagnostics.Process.Start("Sample.pdf");
#endif
                            //Exit
                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBoxAdv.Show("PDF Viewer is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                else
                {
                    // Exit
                    this.Close();
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
Beispiel #26
0
        private void Bwprint_DoWork(object sender, DoWorkEventArgs e)
        {
            if (done)
            {
                try
                {
                    WordDocument document = new WordDocument(System.Windows.Forms.Application.StartupPath + @"\Samples\defaulters_sample.docx", FormatType.Docx);

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

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

                    //Modifies the text

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

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

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

                    #endregion

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

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

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

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

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

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

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

                    WTextRange MonthYear = textSelection.GetAsOneRange();

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

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

                    WTextRange Defaulters = textSelection.GetAsOneRange();

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



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

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

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

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

                        montharray.Add(month.ToString());

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

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

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


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

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

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


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

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

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

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


                    //Saves the document in the given name and format

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

                    //Releases the resources occupied by WordDocument instance

                    document.Close();

                    PrintWord(System.Windows.Forms.Application.StartupPath + @"\" + savepath, "Microsoft Print to PDF");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString(), "Error - Student Management System", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        public ActionResult FormatTable(string Group1)
        {
            if (Group1 == null)
            {
                return(View());
            }
            // Create a new document.
            WordDocument document = new WordDocument();

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

            section.PageSetup.DifferentFirstPage = true;
            IWTextRange textRange;
            IWParagraph paragraph = section.AddParagraph();

            // --------------------------------------------
            // Table in page header
            // --------------------------------------------


            IWParagraph hParagraph = new WParagraph(document);

            hParagraph.AppendText("Header text\r\n").CharacterFormat.FontSize = 14;

            section.HeadersFooters.FirstPageHeader.Paragraphs.Add(hParagraph);


            IWTable hTable = document.LastSection.HeadersFooters.FirstPageHeader.AddTable();

            hTable.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
            hTable.TableFormat.Paddings.All       = 5.4f;
            hTable.ResetCells(2, 2);

            hTable[0, 0].AddParagraph().AppendText("1");
            hTable[0, 1].AddParagraph().AppendText("2");
            hTable[1, 0].AddParagraph().AppendText("3");
            hTable[1, 1].AddParagraph().AppendText("4");


            // --------------------------------------------
            // Tiny table
            // --------------------------------------------

            paragraph = section.AddParagraph();

            paragraph.AppendText("Tiny table\r\n").CharacterFormat.FontSize = 14;
            paragraph = section.AddParagraph();
            WTextBody textBody = section.Body;
            IWTable   table    = textBody.AddTable();

            table.ResetCells(2, 2);
            table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
            table.TableFormat.Paddings.All       = 5.4f;
            WTableRow row_0 = table.Rows[0];

            row_0.Cells[0].AddParagraph().AppendText("A");
            row_0.Cells[0].AddParagraph().AppendText("AA");
            row_0.Cells[0].AddParagraph().AppendText("AAA");

            WTableRow row_1 = table.Rows[1];

            row_1.Cells[1].AddParagraph().AppendText("B");
            row_1.Cells[1].AddParagraph().AppendText("BB\r\nBBB");
            row_1.Cells[1].AddParagraph().AppendText("BBB");

            textBody.AddParagraph().AppendText("Text after table...").CharacterFormat.FontSize = 14;

            // --------------------------------------------
            // Table with different formatting
            // --------------------------------------------

            section.AddParagraph();
            paragraph = section.AddParagraph();
            paragraph.AppendText("Table with different formatting\r\n").CharacterFormat.FontSize = 14;
            paragraph = section.AddParagraph();
            textBody  = section.Body;
            table     = textBody.AddTable();
            table.ResetCells(3, 3);

            /* ------- First Row -------- */

            WTableRow row0 = table.Rows[0];

            paragraph = (IWParagraph)row0.Cells[0].AddParagraph();
            textRange = paragraph.AppendText("1");
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left;
            textRange.CharacterFormat.FontName            = "Arial";
            textRange.CharacterFormat.Bold             = true;
            textRange.CharacterFormat.FontSize         = 14f;
            row0.Cells[0].CellFormat.Borders.LineWidth = 2f;
            row0.Cells[0].CellFormat.Borders.Color     = Color.Magenta;

            paragraph = (IWParagraph)row0.Cells[1].AddParagraph();
            textRange = paragraph.AppendText("2");
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Right;
            textRange.CharacterFormat.Emboss            = true;
            textRange.CharacterFormat.FontSize          = 15f;
            row0.Cells[1].CellFormat.Borders.LineWidth  = 1.3f;
            row0.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DoubleWave;

            paragraph = (IWParagraph)row0.Cells[2].AddParagraph();
            textRange = paragraph.AppendText("3");
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left;
            textRange.CharacterFormat.Engrave             = true;
            textRange.CharacterFormat.FontSize            = 15f;
            row0.Cells[2].CellFormat.Borders.BorderType   = Syncfusion.DocIO.DLS.BorderStyle.Emboss3D;

            /* ------- Second Row -------- */

            WTableRow row1 = table.Rows[1];

            paragraph = (IWParagraph)row1.Cells[0].AddParagraph();
            textRange = paragraph.AppendText("4");
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            textRange.CharacterFormat.SmallCaps           = true;
            textRange.CharacterFormat.FontName            = "Comic Sans MS";
            textRange.CharacterFormat.FontSize            = 16;
            row1.Cells[0].CellFormat.Borders.LineWidth    = 2f;
            row1.Cells[0].CellFormat.Borders.BorderType   = Syncfusion.DocIO.DLS.BorderStyle.DashDotStroker;

            paragraph = (IWParagraph)row1.Cells[1].AddParagraph();
            textRange = paragraph.AppendText("5");
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            textRange.CharacterFormat.FontName            = "Times New Roman";
            textRange.CharacterFormat.Shadow = true;
            textRange.CharacterFormat.TextBackgroundColor = Color.Orange;
            textRange.CharacterFormat.FontSize            = 15f;
            row1.Cells[1].CellFormat.Borders.LineWidth    = 2f;
            row1.Cells[1].CellFormat.Borders.Color        = Color.Brown;

            paragraph = (IWParagraph)row1.Cells[2].AddParagraph();
            textRange = paragraph.AppendText("6");
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            textRange.CharacterFormat.Bold             = true;
            textRange.CharacterFormat.FontSize         = 14f;
            row1.Cells[2].CellFormat.BackColor         = Color.FromArgb(51, 51, 101);
            row1.Cells[2].CellFormat.VerticalAlignment = VerticalAlignment.Middle;

            /* ------- Third Row -------- */

            WTableRow row2 = table.Rows[2];

            paragraph = (IWParagraph)row2.Cells[0].AddParagraph();
            textRange = paragraph.AppendText("7");
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Right;
            textRange.CharacterFormat.FontSize            = 13f;
            row2.Cells[0].CellFormat.Borders.LineWidth    = 1.5f;
            row2.Cells[0].CellFormat.Borders.BorderType   = Syncfusion.DocIO.DLS.BorderStyle.DashLargeGap;

            paragraph = (IWParagraph)row2.Cells[1].AddParagraph();
            textRange = paragraph.AppendText("8");
            textRange.CharacterFormat.TextColor         = Color.Blue;
            textRange.CharacterFormat.FontSize          = 16f;
            row2.Cells[1].CellFormat.Borders.LineWidth  = 3f;
            row2.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Wave;

            paragraph = (IWParagraph)row2.Cells[2].AddParagraph();
            textRange = paragraph.AppendText("9");
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Right;
            row2.Cells[2].CellFormat.Borders.LineWidth    = 2f;
            row2.Cells[2].CellFormat.Borders.Color        = Color.Cyan;
            row2.Cells[2].CellFormat.Borders.Shadow       = true;
            row2.Cells[2].CellFormat.Borders.Space        = 20;

            // --------------------------------------------
            // Table Cell Merging.
            // --------------------------------------------

            section.AddParagraph();
            paragraph = section.AddParagraph();
            paragraph.AppendText("Table Cell Merging...").CharacterFormat.FontSize = 14;
            section.AddParagraph();
            paragraph = section.AddParagraph();
            textBody  = section.Body;

            // Adding a new Table to the textbody.
            table = textBody.AddTable();

            RowFormat format = new RowFormat();

            format.Paddings.All       = 5;
            format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Dot;
            format.Borders.LineWidth  = 2;

            // Inserting rows to the table.
            table.ResetCells(6, 6, format, 80);

            // Table formatting with cell merging.
            table.Rows[0].Cells[0].CellFormat.HorizontalMerge   = CellMerge.Start;
            table.Rows[0].Cells[1].CellFormat.HorizontalMerge   = CellMerge.Continue;
            table.Rows[0].Cells[0].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
            table.Rows[0].Cells[0].CellFormat.BackColor         = Color.FromArgb(218, 230, 246);
            IWParagraph par = table.Rows[0].Cells[0].AddParagraph();

            par.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            par.AppendText("Horizontal Merge").CharacterFormat.Bold = true;


            table.Rows[2].Cells[3].CellFormat.VerticalMerge = CellMerge.Start;
            table.Rows[3].Cells[3].CellFormat.VerticalMerge = CellMerge.Continue;

            table.Rows[2].Cells[3].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
            par = table.Rows[2].Cells[3].AddParagraph();
            table.Rows[2].Cells[3].CellFormat.BackColor           = Color.FromArgb(252, 172, 85);
            par.ParagraphFormat.HorizontalAlignment               = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            par.AppendText("Vertical Merge").CharacterFormat.Bold = true;

            #region Table Cell Spacing.
            // --------------------------------------------
            // Table Cell Spacing.
            // --------------------------------------------

            section.AddParagraph();
            paragraph = section.AddParagraph();
            paragraph.AppendText("Table Cell spacing...").CharacterFormat.FontSize = 14;

            section.AddParagraph();
            paragraph = section.AddParagraph();
            textBody  = section.Body;

            // Adding a new Table to the textbody.
            table = textBody.AddTable();
            table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
            table.TableFormat.Paddings.All       = 5.4f;
            format = new RowFormat();

            format.Paddings.All       = 5;
            format.CellSpacing        = 2;
            format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DotDash;
            format.IsBreakAcrossPages = true;
            table.ResetCells(25, 5, format, 90);
            IWTextRange text;
            table.Rows[0].IsHeader = true;

            for (int i = 0; i < table.Rows[0].Cells.Count; i++)
            {
                paragraph = table[0, i].AddParagraph() as WParagraph;
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                text = paragraph.AppendText(string.Format("Header {0}", i + 1));
                text.CharacterFormat.Font        = new Font("Bitstream Vera Serif", 10);
                text.CharacterFormat.Bold        = true;
                text.CharacterFormat.TextColor   = Color.FromArgb(0, 21, 84);
                table[0, i].CellFormat.BackColor = Color.FromArgb(203, 211, 226);
            }

            for (int i = 1; i < table.Rows.Count; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    paragraph = table[i, j].AddParagraph() as WParagraph;
                    paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;

                    text = paragraph.AppendText(string.Format("Cell {0} , {1}", i, j + 1));
                    text.CharacterFormat.TextColor = Color.FromArgb(242, 151, 50);
                    text.CharacterFormat.Bold      = true;
                    if (i % 2 != 1)
                    {
                        table[i, j].CellFormat.BackColor = Color.FromArgb(231, 235, 245);
                    }
                    else
                    {
                        table[i, j].CellFormat.BackColor = Color.FromArgb(246, 249, 255);
                    }
                }
            }
            #endregion Table Cell Spacing.

            #region Nested Table
            // --------------------------------------------
            // Nested Table.
            // --------------------------------------------

            section.AddParagraph();
            paragraph = section.AddParagraph();
            paragraph.ParagraphFormat.PageBreakBefore = true;
            paragraph.AppendText("Nested Table...").CharacterFormat.FontSize = 14;

            section.AddParagraph();
            paragraph = section.AddParagraph();
            textBody  = section.Body;

            // Adding a new Table to the textbody.
            table = textBody.AddTable();

            format = new RowFormat();
            format.Paddings.All       = 5;
            format.CellSpacing        = 2.5f;
            format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.DotDash;
            table.ResetCells(5, 3, format, 100);

            for (int i = 0; i < table.Rows[0].Cells.Count; i++)
            {
                paragraph = table[0, i].AddParagraph() as WParagraph;
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                text = paragraph.AppendText(string.Format("Header {0}", i + 1));
                text.CharacterFormat.Font        = new Font("Bitstream Vera Serif", 10);
                text.CharacterFormat.Bold        = true;
                text.CharacterFormat.TextColor   = Color.FromArgb(0, 21, 84);
                table[0, i].CellFormat.BackColor = Color.FromArgb(242, 151, 50);
            }
            table[0, 2].Width = 200;
            for (int i = 1; i < table.Rows.Count; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    paragraph = table[i, j].AddParagraph() as WParagraph;
                    paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;

                    if ((i == 2) && (j == 2))
                    {
                        text = paragraph.AppendText("Nested Table");
                    }

                    else
                    {
                        text = paragraph.AppendText(string.Format("Cell {0} , {1}", i, j + 1));
                    }

                    if ((j == 2))
                    {
                        table[i, j].Width = 200;
                    }

                    text.CharacterFormat.TextColor = Color.FromArgb(242, 151, 50);
                    text.CharacterFormat.Bold      = true;
                }
            }

            // Adding a nested Table.
            IWTable nestTable = table[2, 2].AddTable();

            format = new RowFormat();

            format.Borders.BorderType  = Syncfusion.DocIO.DLS.BorderStyle.DotDash;
            format.HorizontalAlignment = RowAlignment.Center;
            nestTable.ResetCells(3, 3, format, 45);

            for (int i = 0; i < nestTable.Rows.Count; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    paragraph = nestTable[i, j].AddParagraph() as WParagraph;
                    paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;

                    nestTable[i, j].CellFormat.BackColor = Color.FromArgb(231, 235, 245);
                    text = paragraph.AppendText(string.Format("Cell {0} , {1}", i, j + 1));
                    text.CharacterFormat.TextColor = Color.Black;
                    text.CharacterFormat.Bold      = true;
                }
            }
            #endregion Nested Table
            #region Table with Images
            string dataPath = ResolveApplicationDataPath("", "Content\\DocIO");

            //Add a new section to the document.
            section = document.AddSection();
            //Add paragraph to the section.
            paragraph = section.AddParagraph();
            //Writing text.
            textRange = paragraph.AppendText("Table with Images");
            textRange.CharacterFormat.FontSize  = 13f;
            textRange.CharacterFormat.TextColor = Color.DarkBlue;
            textRange.CharacterFormat.Bold      = true;

            //Add paragraph to the section.
            section.AddParagraph();
            paragraph = section.AddParagraph();

            text = null;

            //Adding a new Table to the paragraph.
            table = section.Body.AddTable();
            table.ResetCells(1, 3);

            //Adding rows to the table.
            WTableRow row = table.Rows[0];
            //Set heading row height
            row.Height = 25f;
            //set heading values to the Table.
            for (int i = 0; i < 3; i++)
            {
                //Add paragraph for writing Text to the cells.
                paragraph = (IWParagraph)row.Cells[i].AddParagraph();
                //Set Horizontal Alignment as Center.
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                //Writing Row Heading
                switch (i)
                {
                case 0: text           = paragraph.AppendText("SNO");
                    row.Cells[i].Width = 50f; break;

                case 1: text = paragraph.AppendText("Drinks"); break;

                case 2: text = paragraph.AppendText("Showcase Image"); row.Cells[i].Width = 200f; break;
                }
                //Set row Heading formatting
                text.CharacterFormat.Bold      = true;
                text.CharacterFormat.FontName  = "Cambria";
                text.CharacterFormat.FontSize  = 11f;
                text.CharacterFormat.TextColor = Color.White;

                //Set row cells formatting
                row.Cells[i].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                row.Cells[i].CellFormat.BackColor         = Color.FromArgb(157, 161, 190);

                row.Cells[i].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
            }

            int sno = 1;
            //Writing Sno, Product name and Product Images to the Table.

            row1 = table.AddRow(false);

            //Writing SNO to the table with formatting text.
            paragraph = (IWParagraph)row1.Cells[0].AddParagraph();
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            text = paragraph.AppendText(sno.ToString());
            text.CharacterFormat.Bold     = true;
            text.CharacterFormat.FontSize = 10f;
            row1.Cells[0].CellFormat.VerticalAlignment  = VerticalAlignment.Middle;
            row1.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
            row1.Cells[0].CellFormat.BackColor          = Color.FromArgb(217, 223, 239);
            //Writing Product Name to the table with Formatting.
            paragraph = (IWParagraph)row1.Cells[1].AddParagraph();
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            text = paragraph.AppendText("Apple Juice");
            text.CharacterFormat.Bold                   = true;
            text.CharacterFormat.FontSize               = 10f;
            text.CharacterFormat.TextColor              = Color.FromArgb(50, 65, 124);
            row1.Cells[1].CellFormat.VerticalAlignment  = VerticalAlignment.Middle;
            row1.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
            row1.Cells[1].CellFormat.BackColor          = Color.FromArgb(217, 223, 239);

            //Writing Product Images to the Table.
            paragraph = (IWParagraph)row1.Cells[2].AddParagraph();
            paragraph.AppendPicture(Image.FromFile(dataPath + "Apple Juice.png"));
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            row1.Cells[2].CellFormat.VerticalAlignment    = VerticalAlignment.Middle;
            row1.Cells[2].CellFormat.Borders.BorderType   = Syncfusion.DocIO.DLS.BorderStyle.Single;
            row1.Cells[2].CellFormat.BackColor            = Color.FromArgb(217, 223, 239);
            sno++;
            row1 = table.AddRow(false);

            //Writing SNO to the table with formatting text.
            paragraph = (IWParagraph)row1.Cells[0].AddParagraph();
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            text = paragraph.AppendText(sno.ToString());
            text.CharacterFormat.Bold     = true;
            text.CharacterFormat.FontSize = 10f;
            row1.Cells[0].CellFormat.VerticalAlignment  = VerticalAlignment.Middle;
            row1.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
            row1.Cells[0].CellFormat.BackColor          = Color.FromArgb(217, 223, 239);
            //Writing Product Name to the table with Formatting.
            paragraph = (IWParagraph)row1.Cells[1].AddParagraph();
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            text = paragraph.AppendText("Grape Juice");
            text.CharacterFormat.Bold                   = true;
            text.CharacterFormat.FontSize               = 10f;
            text.CharacterFormat.TextColor              = Color.FromArgb(50, 65, 124);
            row1.Cells[1].CellFormat.VerticalAlignment  = VerticalAlignment.Middle;
            row1.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
            row1.Cells[1].CellFormat.BackColor          = Color.FromArgb(217, 223, 239);

            //Writing Product Images to the Table.
            paragraph = (IWParagraph)row1.Cells[2].AddParagraph();
            paragraph.AppendPicture(Image.FromFile(dataPath + "Grape Juice.png"));
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            row1.Cells[2].CellFormat.VerticalAlignment    = VerticalAlignment.Middle;
            row1.Cells[2].CellFormat.Borders.BorderType   = Syncfusion.DocIO.DLS.BorderStyle.Single;
            row1.Cells[2].CellFormat.BackColor            = Color.FromArgb(217, 223, 239);
            sno++;
            row1 = table.AddRow(false);

            //Writing SNO to the table with formatting text.
            paragraph = (IWParagraph)row1.Cells[0].AddParagraph();
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            text = paragraph.AppendText(sno.ToString());
            text.CharacterFormat.Bold     = true;
            text.CharacterFormat.FontSize = 10f;
            row1.Cells[0].CellFormat.VerticalAlignment  = VerticalAlignment.Middle;
            row1.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
            row1.Cells[0].CellFormat.BackColor          = Color.FromArgb(217, 223, 239);
            //Writing Product Name to the table with Formatting.
            paragraph = (IWParagraph)row1.Cells[1].AddParagraph();
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            text = paragraph.AppendText("Hot Soup");
            text.CharacterFormat.Bold                   = true;
            text.CharacterFormat.FontSize               = 10f;
            text.CharacterFormat.TextColor              = Color.FromArgb(50, 65, 124);
            row1.Cells[1].CellFormat.VerticalAlignment  = VerticalAlignment.Middle;
            row1.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
            row1.Cells[1].CellFormat.BackColor          = Color.FromArgb(217, 223, 239);

            //Writing Product Images to the Table.
            paragraph = (IWParagraph)row1.Cells[2].AddParagraph();
            paragraph.AppendPicture(Image.FromFile(dataPath + "Hot Soup.png"));
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            row1.Cells[2].CellFormat.VerticalAlignment    = VerticalAlignment.Middle;
            row1.Cells[2].CellFormat.Borders.BorderType   = Syncfusion.DocIO.DLS.BorderStyle.Single;
            row1.Cells[2].CellFormat.BackColor            = Color.FromArgb(217, 223, 239);
            sno++;
            #endregion Table with Images

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

                return(pdfDoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save));
            }
            return(View());
        }
Beispiel #28
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                // Create a new document.
                WordDocument document = new WordDocument();

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

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


                #region Document formatting
                //Set background color.
                document.Background.Gradient.Color1         = Color.FromArgb(232, 232, 232);
                document.Background.Gradient.Color2         = Color.FromArgb(255, 255, 255);
                document.Background.Type                    = BackgroundType.Gradient;
                document.Background.Gradient.ShadingStyle   = GradientShadingStyle.Horizontal;
                document.Background.Gradient.ShadingVariant = GradientShadingVariant.ShadingDown;

                section.PageSetup.Margins.All = 72f;
                section.PageSetup.PageSize    = new SizeF(612, 792);

                #endregion

                #region Title Section
                IWTable table = section.Body.AddTable();
                table.ResetCells(1, 2);

                WTableRow row = table.Rows[0];
                row.Height = 25f;

                IWParagraph cellPara = row.Cells[0].AddParagraph();
                Image       img      = Image.FromFile(@"..\..\..\..\..\..\..\Common\images\DocIO\Image.jpg");
                IWPicture   pic      = cellPara.AppendPicture(img);
                pic.Height = 80;
                pic.Width  = 180;

                cellPara = row.Cells[1].AddParagraph();
                row.Cells[1].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                row.Cells[1].CellFormat.BackColor         = Color.FromArgb(173, 215, 255);
                IWTextRange txt = cellPara.AppendText("Job Application Form");
                cellPara.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                txt.CharacterFormat.Bold     = true;
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 18f;

                row.Cells[0].Width = 200;
                row.Cells[1].Width = 300;
                row.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Hairline;
                #endregion

                section.AddParagraph();

                #region General Information
                table = section.Body.AddTable();
                table.TableFormat.Paddings.All = 5.4f;
                table.ResetCells(2, 1);
                row                = table.Rows[0];
                row.Height         = 20;
                row.Cells[0].Width = 500;
                cellPara           = row.Cells[0].AddParagraph();
                row.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Thick;
                row.Cells[0].CellFormat.Borders.Color      = Color.FromArgb(155, 205, 255);
                row.Cells[0].CellFormat.BackColor          = Color.FromArgb(198, 227, 255);
                row.Cells[0].CellFormat.VerticalAlignment  = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                txt = cellPara.AppendText(" General Information");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.Bold     = true;
                txt.CharacterFormat.FontSize = 11f;

                row                = table.Rows[1];
                cellPara           = row.Cells[0].AddParagraph();
                row.Cells[0].Width = 500;
                row.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Hairline;
                row.Cells[0].CellFormat.Borders.Color      = Color.FromArgb(155, 205, 255);
                row.Cells[0].CellFormat.BackColor          = Color.FromArgb(222, 239, 255);

                txt = cellPara.AppendText("\n Full Name:\t\t\t\t");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 11f;
                WTextFormField txtField = cellPara.AppendTextFormField(null);
                txtField.TextRange.CharacterFormat.TextColor = Color.MidnightBlue;
                txtField.TextRange.CharacterFormat.FontName  = "Arial";
                txtField.TextRange.CharacterFormat.FontSize  = 11f;

                txt = cellPara.AppendText("\n\n Birth Date:\t\t\t\t");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 11f;
                txtField = cellPara.AppendTextFormField("BirthDayField", DateTime.Now.ToString("M/d/yyyy"));
                txtField.StringFormat = "M/d/yyyy";
                txtField.Type         = TextFormFieldType.DateText;
                txtField.TextRange.CharacterFormat.TextColor = Color.MidnightBlue;
                txtField.TextRange.CharacterFormat.FontName  = "Arial";
                txtField.TextRange.CharacterFormat.FontSize  = 11f;
                txtField.CharacterFormat.TextColor           = Color.MidnightBlue;
                txtField.CharacterFormat.FontName            = "Arial";
                txtField.CharacterFormat.FontSize            = 11f;

                txt = cellPara.AppendText("\n\n Address:\t\t\t\t");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 11f;
                txtField      = cellPara.AppendTextFormField(null);
                txtField.Type = TextFormFieldType.RegularText;
                txtField.TextRange.CharacterFormat.TextColor = Color.MidnightBlue;
                txtField.TextRange.CharacterFormat.FontName  = "Arial";
                txtField.TextRange.CharacterFormat.FontSize  = 11f;

                txt = cellPara.AppendText("\n\n Phone:\t\t\t\t");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 11f;
                txtField = cellPara.AppendTextFormField(null);
                txtField.TextRange.CharacterFormat.TextColor = Color.MidnightBlue;
                txtField.TextRange.CharacterFormat.FontName  = "Arial";
                txtField.TextRange.CharacterFormat.FontSize  = 11f;

                txt = cellPara.AppendText("\n\n Email:\t\t\t\t\t");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 11f;
                txtField = cellPara.AppendTextFormField(null);
                txtField.TextRange.CharacterFormat.TextColor = Color.MidnightBlue;
                txtField.TextRange.CharacterFormat.FontName  = "Arial";
                txtField.TextRange.CharacterFormat.FontSize  = 11f;
                cellPara.AppendText("\n");
                #endregion

                section.AddParagraph();

                #region Educational Qualification
                table = section.Body.AddTable();
                table.TableFormat.Paddings.All = 5.4f;
                table.ResetCells(2, 1);
                row                = table.Rows[0];
                row.Height         = 20;
                row.Cells[0].Width = 500;
                cellPara           = row.Cells[0].AddParagraph();
                row.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Thick;
                row.Cells[0].CellFormat.Borders.Color      = Color.FromArgb(155, 205, 255);
                row.Cells[0].CellFormat.BackColor          = Color.FromArgb(198, 227, 255);
                row.Cells[0].CellFormat.VerticalAlignment  = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                txt = cellPara.AppendText(" Educational Qualification");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.Bold     = true;
                txt.CharacterFormat.FontSize = 11f;

                row                = table.Rows[1];
                cellPara           = row.Cells[0].AddParagraph();
                row.Cells[0].Width = 500;
                row.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Hairline;
                row.Cells[0].CellFormat.Borders.Color      = Color.FromArgb(155, 205, 255);
                row.Cells[0].CellFormat.BackColor          = Color.FromArgb(222, 239, 255);

                txt = cellPara.AppendText("\n Type:\t\t\t\t\t");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 11f;
                WDropDownFormField dropField = cellPara.AppendDropDownFormField();
                dropField.DropDownItems.Add("Higher");
                dropField.DropDownItems.Add("Vocational");
                dropField.DropDownItems.Add("Universal");
                dropField.CharacterFormat.TextColor = Color.MidnightBlue;
                dropField.CharacterFormat.FontName  = "Arial";
                dropField.CharacterFormat.FontSize  = 11f;

                txt = cellPara.AppendText("\n\n Institution:\t\t\t\t");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 11f;
                txtField = cellPara.AppendTextFormField(null);
                txtField.TextRange.CharacterFormat.TextColor = Color.MidnightBlue;
                txtField.TextRange.CharacterFormat.FontName  = "Arial";
                txtField.CharacterFormat.FontSize            = 11f;

                txt = cellPara.AppendText("\n\n Programming Languages:");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 11f;
                txt = cellPara.AppendText("\n\n\t C#:\t\t\t\t");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 9f;
                dropField = cellPara.AppendDropDownFormField();
                dropField.DropDownItems.Add("Perfect");
                dropField.DropDownItems.Add("Good");
                dropField.DropDownItems.Add("Excellent");
                dropField.CharacterFormat.TextColor = Color.MidnightBlue;
                dropField.CharacterFormat.FontName  = "Arial";
                dropField.CharacterFormat.FontSize  = 11f;

                txt = cellPara.AppendText("\n\n\t VB:\t\t\t\t");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 9f;
                dropField = cellPara.AppendDropDownFormField();
                dropField.DropDownItems.Add("Perfect");
                dropField.DropDownItems.Add("Good");
                dropField.DropDownItems.Add("Excellent");
                dropField.CharacterFormat.TextColor = Color.MidnightBlue;
                dropField.CharacterFormat.FontName  = "Arial";
                dropField.CharacterFormat.FontSize  = 11f;
                #endregion

                btnFill.Enabled = true;

                //Protect document
                document.ProtectionType = ProtectionType.AllowOnlyFormFields;
                document.Save("Sample.doc", FormatType.Doc);
                //Save as doc format
                if (wordDocRadioBtn.Checked)
                {
                    //Saving the document to disk.
                    document.Save("Sample.doc");

                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
                        System.Diagnostics.Process.Start("Sample.doc");
                        //Exit
                        this.Close();
                    }
                }
                //Save as docx format
                else if (wordDocxRadioBtn.Checked)
                {
                    //Saving the document as .docx
                    document.Save("Sample.docx", FormatType.Docx);
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
                            System.Diagnostics.Process.Start("Sample.docx");
                            //Exit
                            this.Close();
                        }
                        catch (Win32Exception ex)
                        {
                            MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                //Save as pdf format
                else if (pdfRadioBtn.Checked)
                {
                    DocToPDFConverter converter = new DocToPDFConverter();
                    //Convert word document into PDF document
                    PdfDocument pdfDoc = converter.ConvertToPDF(document);
                    //Save the pdf file
                    pdfDoc.Save("Sample.pdf");
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            System.Diagnostics.Process.Start("Sample.pdf");
                            //Exit
                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBoxAdv.Show("PDF Viewer is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                else
                {
                    // Exit
                    this.Close();
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
        public ActionResult Forms(string Group1)
        {
            if (Group1 == null)
            {
                return(View());
            }
            #region CreateForm
            // Create a new document.
            WordDocument document = new WordDocument();

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

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

            #region Document formatting
            //Set background color.
            document.Background.Gradient.Color1         = Color.FromArgb(232, 232, 232);
            document.Background.Gradient.Color2         = Color.FromArgb(255, 255, 255);
            document.Background.Type                    = BackgroundType.Gradient;
            document.Background.Gradient.ShadingStyle   = GradientShadingStyle.Horizontal;
            document.Background.Gradient.ShadingVariant = GradientShadingVariant.ShadingDown;

            section.PageSetup.Margins.All = 30f;
            section.PageSetup.PageSize    = new SizeF(600, 600f);
            #endregion

            #region Title Section
            IWTable table = section.Body.AddTable();
            table.ResetCells(1, 2);

            WTableRow row = table.Rows[0];
            row.Height = 25f;

            IWParagraph          cellPara = row.Cells[0].AddParagraph();
            string               s        = ResolveApplicationDataPath("image.jpg", "Images\\DocIO");
            System.Drawing.Image img      = System.Drawing.Image.FromFile(s);
            IWPicture            pic      = cellPara.AppendPicture(img);
            pic.Height = 80;
            pic.Width  = 180;

            cellPara = row.Cells[1].AddParagraph();
            row.Cells[1].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
            row.Cells[1].CellFormat.BackColor         = Color.FromArgb(173, 215, 255);
            IWTextRange txt = cellPara.AppendText("Job Application Form");
            cellPara.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            txt.CharacterFormat.Bold     = true;
            txt.CharacterFormat.FontName = "Arial";
            txt.CharacterFormat.FontSize = 18f;

            row.Cells[0].Width = 200;
            row.Cells[1].Width = 300;
            //row.Cells[1].CellFormat.FitText = true;
            row.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Hairline;
            #endregion

            section.AddParagraph();

            #region General Information
            table = section.Body.AddTable();
            table.TableFormat.Paddings.All = 5.4f;
            table.ResetCells(2, 1);
            row                = table.Rows[0];
            row.Height         = 20;
            row.Cells[0].Width = 500;
            cellPara           = row.Cells[0].AddParagraph();
            row.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Thick;
            row.Cells[0].CellFormat.Borders.Color      = Color.FromArgb(155, 205, 255);
            row.Cells[0].CellFormat.BackColor          = Color.FromArgb(198, 227, 255);
            row.Cells[0].CellFormat.VerticalAlignment  = VerticalAlignment.Middle;
            txt = cellPara.AppendText(" General Information");
            txt.CharacterFormat.FontName = "Arial";
            txt.CharacterFormat.Bold     = true;
            txt.CharacterFormat.FontSize = 11f;

            row                = table.Rows[1];
            cellPara           = row.Cells[0].AddParagraph();
            row.Cells[0].Width = 500;
            row.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Hairline;
            row.Cells[0].CellFormat.Borders.Color      = Color.FromArgb(155, 205, 255);
            row.Cells[0].CellFormat.BackColor          = Color.FromArgb(222, 239, 255);

            txt = cellPara.AppendText("\n Full Name:\t\t\t\t");
            txt.CharacterFormat.FontName = "Arial";
            txt.CharacterFormat.FontSize = 11f;
            WTextFormField txtField = cellPara.AppendTextFormField("John");
            txtField.TextRange.CharacterFormat.TextColor = Color.MidnightBlue;
            txtField.TextRange.CharacterFormat.FontName  = "Arial";
            txtField.TextRange.CharacterFormat.FontSize  = 11f;

            txt = cellPara.AppendText("\n\n Birth Date:\t\t\t\t");
            txt.CharacterFormat.FontName = "Arial";
            txt.CharacterFormat.FontSize = 11f;
            txtField = cellPara.AppendTextFormField("BirthDayField", DateTime.Now.ToString("M/d/yyyy"));
            txtField.StringFormat = "M/d/yyyy";
            txtField.Type         = TextFormFieldType.DateText;
            txtField.TextRange.CharacterFormat.TextColor = Color.MidnightBlue;
            txtField.TextRange.CharacterFormat.FontName  = "Arial";
            txtField.TextRange.CharacterFormat.FontSize  = 11f;
            txtField.CharacterFormat.TextColor           = Color.MidnightBlue;
            txtField.CharacterFormat.FontName            = "Arial";
            txtField.CharacterFormat.FontSize            = 11f;

            txt = cellPara.AppendText("\n\n Address:\t\t\t\t");
            txt.CharacterFormat.FontName = "Arial";
            txt.CharacterFormat.FontSize = 11f;
            txtField      = cellPara.AppendTextFormField("221b Baker Street");
            txtField.Type = TextFormFieldType.RegularText;
            txtField.TextRange.CharacterFormat.TextColor = Color.MidnightBlue;
            txtField.TextRange.CharacterFormat.FontName  = "Arial";
            txtField.TextRange.CharacterFormat.FontSize  = 11f;

            txt = cellPara.AppendText("\n\n Phone:\t\t\t\t");
            txt.CharacterFormat.FontName = "Arial";
            txt.CharacterFormat.FontSize = 11f;
            txtField = cellPara.AppendTextFormField("(206)555-3412");
            txtField.TextRange.CharacterFormat.TextColor = Color.MidnightBlue;
            txtField.TextRange.CharacterFormat.FontName  = "Arial";
            txtField.TextRange.CharacterFormat.FontSize  = 11f;

            txt = cellPara.AppendText("\n\n Email:\t\t\t\t\t");
            txt.CharacterFormat.FontName = "Arial";
            txt.CharacterFormat.FontSize = 11f;
            txtField = cellPara.AppendTextFormField("*****@*****.**");
            txtField.TextRange.CharacterFormat.TextColor = Color.MidnightBlue;
            txtField.TextRange.CharacterFormat.FontName  = "Arial";
            txtField.TextRange.CharacterFormat.FontSize  = 11f;
            cellPara.AppendText("\n");
            #endregion

            section.AddParagraph();

            #region Educational Qualification
            table = section.Body.AddTable();
            table.ResetCells(2, 1);
            table.TableFormat.Paddings.All = 5.4f;
            row                = table.Rows[0];
            row.Height         = 20;
            row.Cells[0].Width = 500;
            cellPara           = row.Cells[0].AddParagraph();
            row.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Thick;
            row.Cells[0].CellFormat.Borders.Color      = Color.FromArgb(155, 205, 255);
            row.Cells[0].CellFormat.BackColor          = Color.FromArgb(198, 227, 255);
            row.Cells[0].CellFormat.VerticalAlignment  = VerticalAlignment.Middle;
            txt = cellPara.AppendText(" Educational Qualification");
            txt.CharacterFormat.FontName = "Arial";
            txt.CharacterFormat.Bold     = true;
            txt.CharacterFormat.FontSize = 11f;

            row                = table.Rows[1];
            cellPara           = row.Cells[0].AddParagraph();
            row.Cells[0].Width = 500;
            row.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Hairline;
            row.Cells[0].CellFormat.Borders.Color      = Color.FromArgb(155, 205, 255);
            row.Cells[0].CellFormat.BackColor          = Color.FromArgb(222, 239, 255);

            txt = cellPara.AppendText("\n Type:\t\t\t\t\t");
            txt.CharacterFormat.FontName = "Arial";
            txt.CharacterFormat.FontSize = 11f;
            WDropDownFormField dropField = cellPara.AppendDropDownFormField();
            dropField.DropDownItems.Add("Higher");
            dropField.DropDownItems.Add("Vocational");
            dropField.DropDownItems.Add("Universal");
            dropField.CharacterFormat.TextColor = Color.MidnightBlue;
            dropField.CharacterFormat.FontName  = "Arial";
            dropField.CharacterFormat.FontSize  = 11f;

            txt = cellPara.AppendText("\n\n Institution:\t\t\t\t");
            txt.CharacterFormat.FontName = "Arial";
            txt.CharacterFormat.FontSize = 11f;
            txtField = cellPara.AppendTextFormField("Michigan University");
            txtField.TextRange.CharacterFormat.TextColor = Color.MidnightBlue;
            txtField.TextRange.CharacterFormat.FontName  = "Arial";
            txtField.CharacterFormat.FontSize            = 11f;

            txt = cellPara.AppendText("\n\n Programming Languages:");
            txt.CharacterFormat.FontName = "Arial";
            txt.CharacterFormat.FontSize = 11f;
            txt = cellPara.AppendText("\n\n\t C#:\t\t\t\t");
            txt.CharacterFormat.FontName = "Arial";
            txt.CharacterFormat.FontSize = 9f;
            dropField = cellPara.AppendDropDownFormField();
            dropField.DropDownItems.Add("Perfect");
            dropField.DropDownItems.Add("Good");
            dropField.DropDownItems.Add("Excellent");
            dropField.CharacterFormat.TextColor = Color.MidnightBlue;
            dropField.CharacterFormat.FontName  = "Arial";
            dropField.CharacterFormat.FontSize  = 11f;

            txt = cellPara.AppendText("\n\n\t VB:\t\t\t\t");
            txt.CharacterFormat.FontName = "Arial";
            txt.CharacterFormat.FontSize = 9f;
            dropField = cellPara.AppendDropDownFormField();
            dropField.DropDownItems.Add("Perfect");
            dropField.DropDownItems.Add("Good");
            dropField.DropDownItems.Add("Excellent");
            dropField.CharacterFormat.TextColor = Color.MidnightBlue;
            dropField.CharacterFormat.FontName  = "Arial";
            dropField.CharacterFormat.FontSize  = 11f;
            #endregion
            //Protect document
            document.ProtectionType = ProtectionType.AllowOnlyFormFields;
            MemoryStream st = new MemoryStream();
            document.Save(st, FormatType.Doc);
            st.Seek(0, SeekOrigin.Begin);
            #endregion CreateForm

            #region FillForm
            // Create a new document.
            WordDocument       document1 = new WordDocument(st, FormatType.Doc);
            IWSection          sec       = document1.LastSection;
            WTextFormField     textFF;
            WDropDownFormField dropFF;

            //Access the text field
            textFF = sec.Body.FormFields[0] as WTextFormField;

            //Fill value for the textfield
            textFF.TextRange.Text = "John";

            //Access the form field with feild name
            textFF = sec.Body.FormFields["BirthDayField"] as WTextFormField;
            textFF.TextRange.Text = "5.13.1980";

            textFF = sec.Body.FormFields[2] as WTextFormField;
            textFF.TextRange.Text = "221b Baker Street";

            textFF = sec.Body.FormFields[3] as WTextFormField;
            textFF.TextRange.Text = "(206)555-3412";

            textFF = sec.Body.FormFields[4] as WTextFormField;
            textFF.TextRange.Text = "*****@*****.**";

            dropFF = sec.Body.FormFields[5] as WDropDownFormField;

            //Set the value
            dropFF.DropDownSelectedIndex = 1;

            textFF = sec.Body.FormFields[6] as WTextFormField;
            textFF.TextRange.Text = "Michigan University";

            dropFF = sec.Body.FormFields[7] as WDropDownFormField;
            dropFF.DropDownSelectedIndex = 1;

            dropFF = sec.Body.FormFields[8] as WDropDownFormField;
            dropFF.DropDownSelectedIndex = 2;

            //Allow only to fill the form.
            document1.ProtectionType = ProtectionType.AllowOnlyFormFields;
            #endregion FillForm

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

                return(pdfDoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save));
            }
            #endregion Document save option
            return(View());
        }
Beispiel #30
0
        void OnButtonClicked(object sender, EventArgs e)
        {
            Assembly assembly = typeof(App).GetTypeInfo().Assembly;
            // Creating a new document.
            // Creating a new document.
            WordDocument document = new WordDocument();
            //Adding a new section to the document.
            WSection section = document.AddSection() as WSection;

            //Set Margin of the section
            section.PageSetup.Margins.All = 72;
            //Set page size of the section
            section.PageSetup.PageSize = new Syncfusion.Drawing.SizeF(612, 792);

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

            style.CharacterFormat.FontName      = "Calibri";
            style.CharacterFormat.FontSize      = 11f;
            style.ParagraphFormat.BeforeSpacing = 0;
            style.ParagraphFormat.AfterSpacing  = 8;
            style.ParagraphFormat.LineSpacing   = 13.8f;

            style = document.AddParagraphStyle("Heading 1") as WParagraphStyle;
            style.ApplyBaseStyle("Normal");
            style.CharacterFormat.FontName      = "Calibri Light";
            style.CharacterFormat.FontSize      = 16f;
            style.CharacterFormat.TextColor     = Syncfusion.Drawing.Color.FromArgb(46, 116, 181);
            style.ParagraphFormat.BeforeSpacing = 12;
            style.ParagraphFormat.AfterSpacing  = 0;
            style.ParagraphFormat.Keep          = true;
            style.ParagraphFormat.KeepFollow    = true;
            style.ParagraphFormat.OutlineLevel  = OutlineLevel.Level1;
            IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph();

            Stream   imageStream = assembly.GetManifestResourceStream("SampleBrowser.Samples.DocIO.Templates.AdventureCycle.jpg");
            WPicture picture     = paragraph.AppendPicture(imageStream) as WPicture;

            picture.TextWrappingStyle  = TextWrappingStyle.InFrontOfText;
            picture.VerticalOrigin     = VerticalOrigin.Margin;
            picture.VerticalPosition   = -24;
            picture.HorizontalOrigin   = HorizontalOrigin.Column;
            picture.HorizontalPosition = 263.5f;
            picture.WidthScale         = 20;
            picture.HeightScale        = 15;

            paragraph.ApplyStyle("Normal");
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left;
            WTextRange textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange;

            textRange.CharacterFormat.FontSize  = 12f;
            textRange.CharacterFormat.FontName  = "Calibri";
            textRange.CharacterFormat.TextColor = Syncfusion.Drawing.Color.Red;

            //Appends paragraph.
            paragraph = section.AddParagraph();
            paragraph.ApplyStyle("Heading 1");
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange;
            textRange.CharacterFormat.FontSize = 18f;
            textRange.CharacterFormat.FontName = "Calibri";


            //Appends paragraph.
            paragraph = section.AddParagraph();
            paragraph.ParagraphFormat.FirstLineIndent = 36;
            paragraph.BreakCharacterFormat.FontSize   = 12f;
            textRange = paragraph.AppendText("Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Bothell, Washington with 290 employees, several regional sales teams are located throughout their market base.") as WTextRange;
            textRange.CharacterFormat.FontSize = 12f;

            paragraph = section.AddParagraph();
            paragraph.ParagraphFormat.FirstLineIndent = 36;
            paragraph.BreakCharacterFormat.FontSize   = 12f;
            textRange = paragraph.AppendText("In 2000, Adventure Works Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the Adventure Works Cycles product line. These subcomponents are shipped to the Bothell location for final product assembly. In 2001, Importadores Neptuno, became the sole manufacturer and distributor of the touring bicycle product group.") as WTextRange;
            textRange.CharacterFormat.FontSize = 12f;

            paragraph = section.AddParagraph();
            paragraph.ApplyStyle("Heading 1");
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left;
            textRange = paragraph.AppendText("Product Overview") as WTextRange;
            textRange.CharacterFormat.FontSize = 16f;
            textRange.CharacterFormat.FontName = "Calibri";


            //Appends table.
            IWTable table = section.AddTable();

            table.ResetCells(3, 2);
            table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.None;
            table.TableFormat.IsAutoResized      = true;

            //Appends paragraph.
            paragraph = table[0, 0].AddParagraph();
            paragraph.ParagraphFormat.AfterSpacing  = 0;
            paragraph.BreakCharacterFormat.FontSize = 12f;
            imageStream = assembly.GetManifestResourceStream("SampleBrowser.Samples.DocIO.Templates.Mountain-200.jpg");
            //Appends picture to the paragraph.
            picture = paragraph.AppendPicture(imageStream) as WPicture;
            picture.TextWrappingStyle  = TextWrappingStyle.TopAndBottom;
            picture.VerticalOrigin     = VerticalOrigin.Paragraph;
            picture.VerticalPosition   = 0;
            picture.HorizontalOrigin   = HorizontalOrigin.Column;
            picture.HorizontalPosition = -5.15f;
            picture.WidthScale         = 79;
            picture.HeightScale        = 79;

            //Appends paragraph.
            paragraph = table[0, 1].AddParagraph();
            paragraph.ApplyStyle("Heading 1");
            paragraph.ParagraphFormat.AfterSpacing = 0;
            paragraph.ParagraphFormat.LineSpacing  = 12f;
            paragraph.AppendText("Mountain-200");
            //Appends paragraph.
            paragraph = table[0, 1].AddParagraph();
            paragraph.ParagraphFormat.AfterSpacing  = 0;
            paragraph.ParagraphFormat.LineSpacing   = 12f;
            paragraph.BreakCharacterFormat.FontSize = 12f;
            paragraph.BreakCharacterFormat.FontName = "Times New Roman";

            textRange = paragraph.AppendText("Product No: BK-M68B-38\r") as WTextRange;
            textRange.CharacterFormat.FontSize = 12f;
            textRange.CharacterFormat.FontName = "Times New Roman";
            textRange = paragraph.AppendText("Size: 38\r") as WTextRange;
            textRange.CharacterFormat.FontSize = 12f;
            textRange.CharacterFormat.FontName = "Times New Roman";
            textRange = paragraph.AppendText("Weight: 25\r") as WTextRange;
            textRange.CharacterFormat.FontSize = 12f;
            textRange.CharacterFormat.FontName = "Times New Roman";
            textRange = paragraph.AppendText("Price: $2,294.99\r") as WTextRange;
            textRange.CharacterFormat.FontSize = 12f;
            textRange.CharacterFormat.FontName = "Times New Roman";

            //Appends paragraph.
            paragraph = table[0, 1].AddParagraph();
            paragraph.ParagraphFormat.AfterSpacing  = 0;
            paragraph.ParagraphFormat.LineSpacing   = 12f;
            paragraph.BreakCharacterFormat.FontSize = 12f;

            //Appends paragraph.
            paragraph = table[1, 0].AddParagraph();
            paragraph.ApplyStyle("Heading 1");
            paragraph.ParagraphFormat.AfterSpacing = 0;
            paragraph.ParagraphFormat.LineSpacing  = 12f;
            paragraph.AppendText("Mountain-300 ");
            //Appends paragraph.
            paragraph = table[1, 0].AddParagraph();
            paragraph.ParagraphFormat.AfterSpacing  = 0;
            paragraph.ParagraphFormat.LineSpacing   = 12f;
            paragraph.BreakCharacterFormat.FontSize = 12f;
            paragraph.BreakCharacterFormat.FontName = "Times New Roman";
            textRange = paragraph.AppendText("Product No: BK-M47B-38\r") as WTextRange;
            textRange.CharacterFormat.FontSize = 12f;
            textRange.CharacterFormat.FontName = "Times New Roman";
            textRange = paragraph.AppendText("Size: 35\r") as WTextRange;
            textRange.CharacterFormat.FontSize = 12f;
            textRange.CharacterFormat.FontName = "Times New Roman";
            textRange = paragraph.AppendText("Weight: 22\r") as WTextRange;
            textRange.CharacterFormat.FontSize = 12f;
            textRange.CharacterFormat.FontName = "Times New Roman";
            textRange = paragraph.AppendText("Price: $1,079.99\r") as WTextRange;
            textRange.CharacterFormat.FontSize = 12f;
            textRange.CharacterFormat.FontName = "Times New Roman";

            //Appends paragraph.
            paragraph = table[1, 0].AddParagraph();
            paragraph.ParagraphFormat.AfterSpacing  = 0;
            paragraph.ParagraphFormat.LineSpacing   = 12f;
            paragraph.BreakCharacterFormat.FontSize = 12f;

            //Appends paragraph.
            paragraph = table[1, 1].AddParagraph();
            paragraph.ApplyStyle("Heading 1");
            paragraph.ParagraphFormat.LineSpacing = 12f;
            imageStream = assembly.GetManifestResourceStream("SampleBrowser.Samples.DocIO.Templates.Mountain-300.jpg");
            //Appends picture to the paragraph.
            picture = paragraph.AppendPicture(imageStream) as WPicture;
            picture.TextWrappingStyle  = TextWrappingStyle.TopAndBottom;
            picture.VerticalOrigin     = VerticalOrigin.Paragraph;
            picture.VerticalPosition   = 8.2f;
            picture.HorizontalOrigin   = HorizontalOrigin.Column;
            picture.HorizontalPosition = -14.95f;
            picture.WidthScale         = 75;
            picture.HeightScale        = 75;

            //Appends paragraph.
            paragraph = table[2, 0].AddParagraph();
            paragraph.ApplyStyle("Heading 1");
            paragraph.ParagraphFormat.LineSpacing = 12f;
            imageStream = assembly.GetManifestResourceStream("SampleBrowser.Samples.DocIO.Templates.Road-550-W.jpg");
            //Appends picture to the paragraph.
            picture = paragraph.AppendPicture(imageStream) as WPicture;
            picture.TextWrappingStyle  = TextWrappingStyle.TopAndBottom;
            picture.VerticalOrigin     = VerticalOrigin.Paragraph;
            picture.VerticalPosition   = 0;
            picture.HorizontalOrigin   = HorizontalOrigin.Column;
            picture.HorizontalPosition = -4.9f;
            picture.WidthScale         = 92;
            picture.HeightScale        = 92;

            //Appends paragraph.
            paragraph = table[2, 1].AddParagraph();
            paragraph.ApplyStyle("Heading 1");
            paragraph.ParagraphFormat.AfterSpacing = 0;
            paragraph.ParagraphFormat.LineSpacing  = 12f;
            paragraph.AppendText("Road-150 ");
            //Appends paragraph.
            paragraph = table[2, 1].AddParagraph();
            paragraph.ParagraphFormat.AfterSpacing  = 0;
            paragraph.ParagraphFormat.LineSpacing   = 12f;
            paragraph.BreakCharacterFormat.FontSize = 12f;
            paragraph.BreakCharacterFormat.FontName = "Times New Roman";
            textRange = paragraph.AppendText("Product No: BK-R93R-44\r") as WTextRange;
            textRange.CharacterFormat.FontSize = 12f;
            textRange.CharacterFormat.FontName = "Times New Roman";
            textRange = paragraph.AppendText("Size: 44\r") as WTextRange;
            textRange.CharacterFormat.FontSize = 12f;
            textRange.CharacterFormat.FontName = "Times New Roman";
            textRange = paragraph.AppendText("Weight: 14\r") as WTextRange;
            textRange.CharacterFormat.FontSize = 12f;
            textRange.CharacterFormat.FontName = "Times New Roman";
            textRange = paragraph.AppendText("Price: $3,578.27\r") as WTextRange;
            textRange.CharacterFormat.FontSize = 12f;
            textRange.CharacterFormat.FontName = "Times New Roman";
            //Appends paragraph.
            paragraph = table[2, 1].AddParagraph();
            paragraph.ApplyStyle("Heading 1");
            paragraph.ParagraphFormat.LineSpacing = 12f;

            //Appends paragraph.
            section.AddParagraph();
            MemoryStream stream = new MemoryStream();

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

            if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows)
            {
                Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("GettingStarted.docx", "application/msword", stream);
            }
            else
            {
                Xamarin.Forms.DependencyService.Get <ISave>().Save("GettingStarted.docx", "application/msword", stream);
            }
        }