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

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

            style = m_document.AddParagraphStyle("Style_Low") as WParagraphStyle;
            style.CharacterFormat.FontName = "Times New Roman";
            style.CharacterFormat.FontSize = 16f;
            style.CharacterFormat.Bold     = true;

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

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

            style = m_document.AddParagraphStyle("Normal2") as WParagraphStyle;
            style.CharacterFormat.FontName      = "Calibri";
            style.CharacterFormat.FontSize      = 11f;
            style.ParagraphFormat.BeforeSpacing = 0;
            style.ParagraphFormat.AfterSpacing  = 8;
            style.ParagraphFormat.LineSpacing   = 13.8f;

            style = m_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;
        }
        public MemoryStream CreateWord(List <Lokaal> lokalen)
        {
            //Creating a new document
            WordDocument document = new WordDocument();
            //Adding a new section to the document
            WSection section = document.AddSection() as WSection;

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

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

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

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

            paragraph.ApplyStyle("Normal");
            paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
            WTextRange textRange = paragraph.AppendText("Overzicht") as WTextRange;

            textRange.CharacterFormat.FontName  = "Calibri";
            textRange.CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(46, 116, 181);

            //Appends paragraph
            paragraph = section.AddParagraph();
            paragraph.ApplyStyle("Heading 1");
            paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
            textRange = paragraph.AppendText("Inventaris Lokalen") as WTextRange;
            textRange.CharacterFormat.FontSize = 20f;
            textRange.CharacterFormat.FontName = "Calibri";

            //Eerste cel van tabel
            IWTable table = section.AddTable();

            table.ResetCells(lokalen.Count(), 3);
            WTableCell firstCell = table.Rows[0].Cells[0];

            firstCell.Width = 100;
            paragraph       = firstCell.AddParagraph();
            paragraph.ApplyStyle("Normal");
            textRange = paragraph.AppendText("Lokaal") as WTextRange;
            textRange.CharacterFormat.Bold = true;

            //Tweede cel van tabel
            WTableCell secondCell = table.Rows[0].Cells[1];

            secondCell.Width = 180;
            paragraph        = secondCell.AddParagraph();
            paragraph.ApplyStyle("Normal");
            textRange = paragraph.AppendText("Details") as WTextRange;
            textRange.CharacterFormat.Bold = true;

            //Derde cel van tabel
            WTableCell thirdCell = table.Rows[0].Cells[2];

            thirdCell.Width = 170;
            paragraph       = thirdCell.AddParagraph();
            paragraph.ApplyStyle("Normal");
            textRange = paragraph.AppendText("Voorwerpen") as WTextRange;
            textRange.CharacterFormat.Bold = true;

            for (int i = 1; i < lokalen.Count(); i++)
            {
                //Lokaal
                firstCell       = table.Rows[i].Cells[0];
                firstCell.Width = 100;
                paragraph       = firstCell.AddParagraph();
                textRange       = paragraph.AppendText("Lokaal " + lokalen[i].lokaalNr) as WTextRange;
                textRange.CharacterFormat.FontSize = 14f;

                //Details per lokaal
                secondCell       = table.Rows[i].Cells[1];
                secondCell.Width = 180;
                paragraph        = secondCell.AddParagraph();
                textRange        = paragraph.AppendText("Nummer : " + lokalen[i].lokaalNr + "\n" +
                                                        "Verantwoordelijke : " + lokalen[i].lokaalVerantwoordelijke + "\n" +
                                                        "Actief/Inactief : " + (lokalen[i].isActief ? "Actief" : "Inactief")) as WTextRange;
                textRange.CharacterFormat.FontSize = 13f;

                //Voorwerpen per lokaal
                for (int j = 0; j < lokalen[i].Voorwerpen.Count(); j++)
                {
                    thirdCell       = table.Rows[i].Cells[2];
                    thirdCell.Width = 170;
                    paragraph       = thirdCell.AddParagraph();
                    textRange       = paragraph.AppendText("- " + lokalen[i].Voorwerpen[j].aantal + " x " + lokalen[i].Voorwerpen[j].voorwerpNaam + "\n" +
                                                           (lokalen[i].Voorwerpen[j].defect ? "defect" : "niet defect")) as WTextRange;
                    textRange.CharacterFormat.FontSize = 13f;
                }
            }

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

            document.Save(stream, FormatType.Docx);
            //Closes the Word document
            document.Close();
            stream.Position = 0;

            return(stream);
        }
        void OnButtonClicked(object sender, EventArgs e)
        {
            WordDocument     document = new WordDocument();
            IWParagraphStyle style    = null;
            // Adding a new section to the document.
            WSection section = document.AddSection() as WSection;

            //Set Margin of the section
            section.PageSetup.Margins.All = 72;
            IWParagraph par   = document.LastSection.AddParagraph();
            WTextRange  range = par.AppendText("Using CustomStyles") as WTextRange;

            range.CharacterFormat.TextBackgroundColor = Syncfusion.Drawing.Color.Red;
            range.CharacterFormat.TextColor           = Syncfusion.Drawing.Color.White;
            range.CharacterFormat.FontSize            = 18f;
            document.LastParagraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;

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

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

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

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

            IWParagraph paragraph = null;

            for (int i = 1; i < document.Styles.Count; i++)
            {
                //Skip to apply the document default styles and also paragraph style.
                if (document.Styles[i].Name == "Normal" || document.Styles[i].Name == "Default Paragraph Font" || document.Styles[i].StyleType != StyleType.ParagraphStyle)
                {
                    continue;
                }
                // Getting styles from Document.
                style = (IWParagraphStyle)document.Styles[i];
                // Adding a new paragraph
                section.AddParagraph();
                paragraph = section.AddParagraph();
                // Applying styles to the current paragraph.
                paragraph.ApplyStyle(style.Name);
                // Writing Text with the current style and formatting.
                paragraph.AppendText("Northwind Database with [" + style.Name + "] Style");
                // Adding a new paragraph
                section.AddParagraph();
                paragraph = section.AddParagraph();
                // Applying another style to the current paragraph.
                paragraph.ApplyStyle("MyStyle_Normal");
                // Writing text with current style.
                paragraph.AppendText("The Northwind sample database (Northwind.mdb) is included with all versions of Access. It provides data you can experiment with and database objects that demonstrate features you might want to implement in your own databases. Using Northwind, you can become familiar with how a relational database is structured and how the database objects work together to help you enter, store, manipulate, and print your data.");
            }
            #region Saving Document
            MemoryStream stream = new MemoryStream();
            document.Save(stream, FormatType.Word2013);
            document.Close();
            if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows)
            {
                Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("WordDocument_CustomStyles.docx", "application/msword", stream);
            }
            else
            {
                Xamarin.Forms.DependencyService.Get <ISave>().Save("WordDocument_CustomStyles.docx", "application/msword", stream);
            }
            #endregion
        }
Esempio n. 5
0
        public ActionResult ExportFile(int id)
        {
            try
            {
                //string editor = "";
                //editor = "<table><th>1</th><th>2</th></table>";
                //// Create a unique file name
                //string fileName = Guid.NewGuid() + ".docx";
                //// Convert HTML text to byte array
                //byte[] byteArray = Encoding.UTF8.GetBytes(editor.Contains("<html>") ? editor : "<html>" + editor + "</html>");
                //// Generate Word document from the HTML
                //MemoryStream stream = new MemoryStream(byteArray);
                //Document document = new Document(stream);
                //// Create memory stream for the Word file
                //var outputStream = new MemoryStream();
                //document.Save(outputStream, SaveFormat.Docx);
                //outputStream.Position = 0;
                //// Return generated Word file
                //return File(outputStream, System.Net.Mime.MediaTypeNames.Application.Rtf, fileName);

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

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

                // Creating a new document.
                WordDocument document = new WordDocument();
                //Adding a new section to the document.
                WSection section = document.AddSection() as WSection;
                //Set Margin of the section
                section.PageSetup.Margins.All = 50;
                //Set page size of the section
                //section.PageSetup.PageSize = new Syncfusion.Drawing.SizeF(612, 792);

                //Create Paragraph styles
                WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle;
                style.CharacterFormat.FontName      = "Calibri";
                style.CharacterFormat.FontSize      = 11f;
                style.ParagraphFormat.BeforeSpacing = 0;
                style.ParagraphFormat.AfterSpacing  = 8;
                style.ParagraphFormat.LineSpacing   = 13.8f;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                //Appends paragraph.
                section.AddParagraph();

                //Saves the Word document to  MemoryStream
                MemoryStream stream = new MemoryStream();
                document.Save(stream, FormatType.Docx);
                stream.Position = 0;
                string fileName = Guid.NewGuid() + ".docx";
                //Download Word document in the browser
                return(File(stream, "application/msword", fileName));
            }
            catch (Exception exp)
            {
                TempData["alertMessage"] = "Произошла ошибка при создании файла. Возможно не хватает информации об отправлении.";
                return(RedirectToAction("Index"));
            }
        }
Esempio n. 6
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            ErrorMessage.InnerText = "";
            if (hdnGroup.Value == "Word")
            {
                CheckFileStatus FileStatus = new CheckFileStatus();
                string          path       = string.Format("{0}\\..\\Data\\AdventureWorks\\AdventureWorks_Person_Contact.csv", Request.PhysicalPath.ToLower().Split(new string[] { "\\c# hive samples" }, StringSplitOptions.None));
                ErrorMessage.InnerText = FileStatus.CheckFile(path);
                if (ErrorMessage.InnerText == "")
                {
                    try
                    {
                        //Create a new document
                        WordDocument document = new WordDocument();

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

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

                        //Set Margin of the section
                        section.PageSetup.Margins.All = 72;

                        //Set page size of the section
                        section.PageSetup.PageSize = new SizeF(800, 792);

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

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

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

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

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

                        con.Open();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        con.Open();

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

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

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

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

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

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

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

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

                        //closing the workwook
                        workbook.Close();

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


                        //Closing the hive connection
                        con.Close();
                    }
                    catch (HqlConnectionException)
                    {
                        ErrorMessage.InnerText = "Could not establish a connection to the HiveServer. Please run HiveServer2 from the Syncfusion service manager dashboard.";
                    }
                }
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            WordDocument doc = new WordDocument();

            doc.EnsureMinimal();

            WParagraph para = doc.LastParagraph;

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

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

            if (!this.CheckBox7.Checked)
            {
                para.AppendText("Select TOC and press F9 to update the Table of Contents").CharacterFormat.HighlightColor = Color.Yellow;
            }

            para = doc.LastSection.AddParagraph() as WParagraph;
            string title = this.TextBox1.Text + "\n";

            para.AppendText(title);
            para.ApplyStyle(BuiltinStyle.Heading4);

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

            para.ApplyStyle(BuiltinStyle.Heading4);
            //Apply built-in paragraph formatting
            WSection section = doc.LastSection;

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

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

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

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

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

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

                section.AddParagraph();
                newPara = section.AddParagraph() as WParagraph;
                text    = newPara.AppendText("Paragraph2") as WTextRange;
                newPara.ApplyStyle(BuiltinStyle.Heading3);
                newPara = section.AddParagraph() as WParagraph;
                newPara.AppendText("This is the heading3 of built in style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph.");
                #endregion
            }
            else
            {
                #region Custom styles
                //Custom styles.
                WParagraphStyle pStyle1 = (WParagraphStyle)doc.AddParagraphStyle("MyStyle1");
                WParagraphStyle pStyle2 = (WParagraphStyle)doc.AddParagraphStyle("MyStyle2");
                WParagraphStyle pStyle3 = (WParagraphStyle)doc.AddParagraphStyle("MyStyle3");

                //Set the Heading Styles to false in order to define custom levels to TOC.
                toc.UseHeadingStyles = false;

                //Set the TOC level style which determines; based on which the TOC should be created.
                toc.SetTOCLevelStyle(1, "MyStyle1");
                toc.SetTOCLevelStyle(2, "MyStyle2");
                toc.SetTOCLevelStyle(3, "MyStyle3");
                section = doc.AddSection() as WSection;

                pStyle1.CharacterFormat.FontName = "Cambria";
                pStyle1.CharacterFormat.FontSize = 30f;

                para = section.AddParagraph() as WParagraph;

                WTextRange text = para.AppendText("Document with Custom Styles") as WTextRange;
                para.ApplyStyle("MyStyle1");
                para = doc.LastSection.AddParagraph() as WParagraph;
                para.AppendText("This is the heading1 of built in style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can only insert TOC field in a word document. It can not refresh or create TOC field. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC.");

                pStyle2.CharacterFormat.FontName = "Cambria";
                pStyle2.CharacterFormat.FontSize = 20f;

                doc.LastSection.AddParagraph();

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

                pStyle3.CharacterFormat.FontName = "Cambria";
                pStyle3.CharacterFormat.FontSize = 14f;

                doc.LastSection.AddParagraph();

                para = doc.LastSection.AddParagraph() as WParagraph;
                text = para.AppendText("Section2") as WTextRange;
                para.ApplyStyle("MyStyle3");
                para = doc.LastSection.AddParagraph() as WParagraph;
                para.AppendText("This is the heading2 of built in style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");
                #endregion
            }
            if (Convert.ToInt32(this.DropDownList2.Text) < Convert.ToInt32(this.DropDownList1.Text))
            {
                Response.Write("Not a valid heading level range. UpperHeadingLevel must be greater than LowerHeadingLevel");
            }
            else
            {
                toc.IncludePageNumbers    = this.CheckBox2.Checked;
                toc.RightAlignPageNumbers = this.CheckBox3.Checked;
                toc.UseHyperlinks         = this.CheckBox4.Checked;
                toc.LowerHeadingLevel     = Convert.ToInt32(this.DropDownList1.Text);
                toc.UpperHeadingLevel     = Convert.ToInt32(this.DropDownList2.Text);

                //Used to set levels for a word or paragraph through OutLine Levels
                //Right click text. Select Paragraph option. Set OutlineLevel. Update TOC toc see the text added in TOC.
                toc.UseOutlineLevels = this.CheckBox5.Checked;

                //Used to set levels for a word or paragraph through Table Entry Fields
                //Select the text that should be marked as Table of contents.
                //Press ALT+SHIFT+O. A dialog box will appear with options to enter the text, select the table identifier and level.
                //Choose the table identifier and level for the test and click �Mark�. Update TOC toc see the text added in TOC.
                //Sets the Table Identifier if necessary.
                //toc.TableID = "B";
                toc.UseTableEntryFields = this.CheckBox6.Checked;
                //Updates the table of contents.
                if (this.CheckBox7.Checked)
                {
                    doc.UpdateTableOfContents();
                }

                if (rdButtonDoc.Checked)
                {
                    //Save as .doc format
                    doc.Save("Sample.doc", FormatType.Doc, Response, HttpContentDisposition.Attachment);
                }
                //Save as .docx format
                else if (rdButtonDocx.Checked)
                {
                    try
                    {
                        doc.Save("Sample.docx", FormatType.Docx, Response, HttpContentDisposition.Attachment);
                    }
                    catch (Win32Exception ex)
                    {
                        Response.Write("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                        Console.WriteLine(ex.ToString());
                    }
                }
                //Save as WordML(.xml) format
                if (rdButtonWordML.Checked)
                {
                    try
                    {
                        doc.Save("Sample.xml", FormatType.WordML, Response, HttpContentDisposition.Attachment);
                    }
                    catch (Win32Exception ex)
                    {
                        Response.Write("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                        Console.WriteLine(ex.ToString());
                    }
                }
                //Save as .pdf format
                else if (rdButtonPdf.Checked)
                {
                    try
                    {
                        DocToPDFConverter converter = new DocToPDFConverter();
                        PdfDocument       pdfDoc    = converter.ConvertToPDF(doc);

                        pdfDoc.Save("Sample.pdf", Response, HttpReadType.Save);
                    }
                    catch (Win32Exception ex)
                    {
                        Response.Write("PDF Viewer is not installed in this system");
                        Console.WriteLine(ex.ToString());
                    }
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Create a simple Word document
        /// </summary>
        /// <returns>Return the created Word document as stream</returns>
        public MemoryStream CreateWordDocument(string documentType)
        {
            //Creating a new document
            WordDocument document = new WordDocument();
            //Adding a new section to the document
            WSection section = document.AddSection() as WSection;

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

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

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

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

            string     basePath    = _hostingEnvironment.WebRootPath + @"/images/DocIO/";
            FileStream imageStream = new FileStream(basePath + @"AdventureCycle.jpg", FileMode.Open, FileAccess.Read);
            WPicture   picture     = paragraph.AppendPicture(imageStream) as WPicture;

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

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

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

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

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

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

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

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

            //Appends paragraph
            paragraph = table[0, 0].AddParagraph();
            paragraph.ParagraphFormat.AfterSpacing  = 0;
            paragraph.BreakCharacterFormat.FontSize = 12f;
            //Appends picture to the paragraph
            imageStream = new FileStream(basePath + @"Mountain-200.jpg", FileMode.Open, FileAccess.Read);
            picture     = paragraph.AppendPicture(imageStream) as WPicture;
            picture.TextWrappingStyle  = TextWrappingStyle.TopAndBottom;
            picture.VerticalOrigin     = VerticalOrigin.Paragraph;
            picture.VerticalPosition   = 4.5f;
            picture.HorizontalOrigin   = HorizontalOrigin.Column;
            picture.HorizontalPosition = -2.15f;
            picture.WidthScale         = 79;
            picture.HeightScale        = 79;

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

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

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

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

            //Appends paragraph
            paragraph = table[1, 1].AddParagraph();
            paragraph.ApplyStyle("Heading 1");
            paragraph.ParagraphFormat.LineSpacing = 12f;
            //Appends picture to the paragraph
            imageStream = new FileStream(basePath + @"Mountain-300.jpg", FileMode.Open, FileAccess.Read);
            picture     = paragraph.AppendPicture(imageStream) as WPicture;
            picture.TextWrappingStyle  = TextWrappingStyle.TopAndBottom;
            picture.VerticalOrigin     = VerticalOrigin.Paragraph;
            picture.VerticalPosition   = 8.2f;
            picture.HorizontalOrigin   = HorizontalOrigin.Column;
            picture.HorizontalPosition = -14.95f;
            picture.WidthScale         = 75;
            picture.HeightScale        = 75;

            //Appends paragraph
            paragraph = table[2, 0].AddParagraph();
            paragraph.ApplyStyle("Heading 1");
            paragraph.ParagraphFormat.LineSpacing = 12f;
            //Appends picture to the paragraph
            imageStream = new FileStream(basePath + @"Road-550-W.jpg", FileMode.Open, FileAccess.Read);
            picture     = paragraph.AppendPicture(imageStream) as WPicture;
            picture.TextWrappingStyle  = TextWrappingStyle.TopAndBottom;
            picture.VerticalOrigin     = VerticalOrigin.Paragraph;
            picture.VerticalPosition   = 3.75f;
            picture.HorizontalOrigin   = HorizontalOrigin.Column;
            picture.HorizontalPosition = -5f;
            picture.WidthScale         = 92;
            picture.HeightScale        = 92;

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

            FormatType formatType = FormatType.Docx;

            //Save as .doc format
            if (documentType == "WordDoc")
            {
                formatType = FormatType.Doc;
            }
            //Save as .xml format
            else if (documentType == "WordML")
            {
                formatType = FormatType.WordML;
            }
            //Save the document as a stream and retrun the stream
            using (MemoryStream stream = new MemoryStream())
            {
                //Save the created Word document to MemoryStream
                document.Save(stream, formatType);
                document.Close();
                stream.Position = 0;
                return(stream);
            }
        }
Esempio n. 9
0
        public ActionResult ExportDefault(string SaveOption)
        {
            if (SaveOption == null)
            {
                ErrorMessage = "";
                return(View());
            }
            else if (SaveOption == "Excel 2013" || SaveOption == "Excel 2010" || SaveOption == "Excel 2007" || SaveOption == "Excel 2003" || SaveOption == "CSV")
            {
                ErrorMessage = "";
                string          path      = new System.IO.DirectoryInfo(Request.PhysicalPath + "..\\..\\..\\..\\..\\..\\..\\Data\\AdventureWorks\\AdventureWorks_Person_Contact.csv").FullName;
                CheckFileStatus CheckFile = new CheckFileStatus();
                ErrorMessage = CheckFile.CheckFile(path);
                if (ErrorMessage == "")
                {
                    try
                    {
                        //Instantiate the spreadsheet creation engine.
                        ExcelEngine excelEngine = new ExcelEngine();

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

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

                        //The first worksheet object in the worksheets collection is accessed.
                        IWorksheet worksheet = workbook.Worksheets[0];
                        var        result    = CustomersData.list();
                        ErrorMessage = null;

                        //Adding header text for worksheet
                        worksheet[1, 1].Text = "Contact Id";
                        worksheet[1, 2].Text = "Full Name";
                        worksheet[1, 3].Text = "Age";
                        worksheet[1, 4].Text = "Phone Number";
                        worksheet[1, 5].Text = "Email Id";
                        worksheet[1, 6].Text = "Modified Date";

                        int i = 1;
                        //Reading each row from the fetched result
                        foreach (PersonDetail records in result)
                        {
                            //Reading each data from the row
                            //Assigning each data to the worksheet based on index
                            worksheet[i + 1, 1].Text = records.ContactId;
                            worksheet[i + 1, 2].Text = records.FullName;
                            worksheet[i + 1, 3].Text = records.Age;
                            worksheet[i + 1, 4].Text = records.PhoneNumber;
                            worksheet[i + 1, 5].Text = records.EmailId;
                            worksheet[i + 1, 6].Text = records.ModifiedDate;
                            i++;
                        }
                        //Assigning Header text with cell color
                        worksheet.Range["A1:F1"].CellStyle.Color      = System.Drawing.Color.FromArgb(51, 153, 51);
                        worksheet.Range["A1:F1"].CellStyle.Font.Color = Syncfusion.XlsIO.ExcelKnownColors.White;
                        worksheet.Range["A1:F1"].CellStyle.Font.Bold  = true;
                        worksheet.UsedRange.AutofitColumns();
                        #endregion

                        //Save as .xls format
                        if (SaveOption == "Excel 2003")
                        {
                            return(excelEngine.SaveAsActionResult(workbook, "Sample.xls", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel97));
                        }
                        //Save as .xlsx format
                        else if (SaveOption == "Excel 2007")
                        {
                            workbook.Version = ExcelVersion.Excel2007;
                            return(excelEngine.SaveAsActionResult(workbook, "Sample.xlsx", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel2007));
                        }
                        //Save as .xlsx format
                        else if (SaveOption == "Excel 2010")
                        {
                            workbook.Version = ExcelVersion.Excel2010;
                            return(excelEngine.SaveAsActionResult(workbook, "Sample.xlsx", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel2010));
                        }
                        //Save as .xlsx format
                        else if (SaveOption == "Excel 2013")
                        {
                            workbook.Version = ExcelVersion.Excel2013;
                            return(excelEngine.SaveAsActionResult(workbook, "Sample.xlsx", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel2013));
                        }
                        //Save as .csv format
                        else if (SaveOption == "CSV")
                        {
                            return(excelEngine.SaveAsActionResult(workbook, "Sample.csv", ",", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.CSV));
                        }
                        //Close the workbook
                        workbook.Close();

                        //Close the excelengine
                        excelEngine.Dispose();
                    }
                    catch (HqlConnectionException)
                    {
                        ErrorMessage = "Could not establish a connection to the HiveServer. Please run HiveServer2 from the Syncfusion service manager dashboard.";
                    }
                }

                return(View());
            }
            else
            {
                ErrorMessage = "";
                string          path      = new System.IO.DirectoryInfo(Request.PhysicalPath + "..\\..\\..\\..\\..\\..\\..\\Data\\AdventureWorks\\AdventureWorks_Person_Contact.csv").FullName;
                CheckFileStatus CheckFile = new CheckFileStatus();
                ErrorMessage = CheckFile.CheckFile(path);
                //A new document is created.
                if (ErrorMessage == "")
                {
                    try
                    {
                        WordDocument document = new WordDocument();

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

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

                        //Set Margin of the section
                        section.PageSetup.Margins.All = 72;

                        //Set page size of the section
                        section.PageSetup.PageSize = new SizeF(800, 792);

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

                        //Reading the data from the table
                        var result = CustomersData.list();
                        doctable.AddRow(true, false);

                        //creating new cell
                        WTableCell cell = new WTableCell(document);

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

                        //Adding header text for the table
                        cell.AddParagraph().AppendText("Customer Id").ApplyCharacterFormat(charFormat);
                        cell.Width = 75;
                        cell.CellFormat.BackColor = System.Drawing.Color.FromArgb(51, 153, 51);
                        //Adding cell to rows
                        doctable.Rows[0].Cells.Add(cell);
                        cell = new WTableCell(document);
                        cell.AddParagraph().AppendText("Full Name").ApplyCharacterFormat(charFormat);
                        cell.Width = 90;
                        cell.CellFormat.BackColor = System.Drawing.Color.FromArgb(51, 153, 51);
                        doctable.Rows[0].Cells.Add(cell);
                        cell = new WTableCell(document);
                        cell.AddParagraph().AppendText("Age").ApplyCharacterFormat(charFormat);
                        cell.Width = 75;
                        cell.CellFormat.BackColor = System.Drawing.Color.FromArgb(51, 153, 51);
                        doctable.Rows[0].Cells.Add(cell);
                        cell = new WTableCell(document);
                        cell.AddParagraph().AppendText("Phone Number").ApplyCharacterFormat(charFormat);
                        cell.Width = 90;
                        cell.CellFormat.BackColor = System.Drawing.Color.FromArgb(51, 153, 51);
                        doctable.Rows[0].Cells.Add(cell);
                        cell = new WTableCell(document);
                        cell.AddParagraph().AppendText("Email Id").ApplyCharacterFormat(charFormat);
                        cell.Width = 180;
                        cell.CellFormat.BackColor = System.Drawing.Color.FromArgb(51, 153, 51);
                        doctable.Rows[0].Cells.Add(cell);
                        cell = new WTableCell(document);
                        cell.AddParagraph().AppendText("Modified Date").ApplyCharacterFormat(charFormat);
                        cell.Width = 125;
                        cell.CellFormat.BackColor = System.Drawing.Color.FromArgb(51, 153, 51);
                        doctable.Rows[0].Cells.Add(cell);

                        int i = 1;
                        //Reading each row from the fetched result
                        foreach (PersonDetail records in result)
                        {
                            doctable.AddRow(true, false);

                            //Assigning fetched result to the cell
                            cell = new WTableCell(document);
                            cell.AddParagraph().AppendText(records.ContactId.ToString());
                            cell.Width = 75;
                            doctable.Rows[i].Cells.Add(cell);
                            cell = new WTableCell(document);
                            cell.AddParagraph().AppendText(records.FullName.ToString());
                            cell.Width = 90;
                            doctable.Rows[i].Cells.Add(cell);
                            cell = new WTableCell(document);
                            cell.AddParagraph().AppendText(records.Age.ToString());
                            cell.Width = 75;
                            doctable.Rows[i].Cells.Add(cell);
                            cell = new WTableCell(document);
                            cell.AddParagraph().AppendText(records.PhoneNumber.ToString());
                            cell.Width = 90;
                            doctable.Rows[i].Cells.Add(cell);
                            cell = new WTableCell(document);
                            cell.AddParagraph().AppendText(records.EmailId.ToString());
                            cell.Width = 180;
                            doctable.Rows[i].Cells.Add(cell);
                            cell = new WTableCell(document);
                            cell.AddParagraph().AppendText(records.ModifiedDate.ToString());
                            cell.Width = 125;
                            doctable.Rows[i].Cells.Add(cell);

                            i++;
                        }
                        //Adding table to the section
                        section.Tables.Add(doctable);

                        #region saveOption
                        //Save as .doc Word 97-2003 format
                        if (SaveOption == "Word 97-2003")
                        {
                            return(document.ExportAsActionResult("Sample.doc", FormatType.Doc, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment));
                        }
                        //Save as .docx Word 2007 format
                        else if (SaveOption == "Word 2007")
                        {
                            return(document.ExportAsActionResult("Sample.docx", FormatType.Word2007, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment));
                        }
                        //Save as .docx Word 2010 format
                        else if (SaveOption == "Word 2010")
                        {
                            return(document.ExportAsActionResult("Sample.docx", FormatType.Word2010, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment));
                        }
                        //Save as .docx Word 2013 format
                        else if (SaveOption == "Word 2013")
                        {
                            return(document.ExportAsActionResult("Sample.docx", FormatType.Word2013, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment));
                        }

                        #endregion saveOption
                    }

                    catch (HqlConnectionException)
                    {
                        ErrorMessage = "Could not establish a connection to the HiveServer. Please run HiveServer2 from the Syncfusion service manager dashboard.";
                    }
                }
                return(View());
            }
        }
Esempio n. 10
0
        public ActionResult Word(int id, int type, byte[] image, bool pdf = false)
        {
            var    dba = new ApplicationDbContext();
            int    idCustomer;
            string idConsultant;

            global::Interview.Interview interview = null;
            Campaign campaign = null;

            byte[] byteArrayImg;
            if (type == 1 || type == 2)
            {
                idCustomer   = db.Interviews.Where(i => i.IdCampaign == id).Include(i => i.Campaign.Customer).Select(i => i.Campaign.Customer.IdCustomer).FirstOrDefault();
                idConsultant = db.Interviews.Where(i => i.IdCampaign == id).Select(u => u.Id).FirstOrDefault();
                var idFirm = db.Users.Where(u => u.Id == idConsultant).Select(u => u.IdFirm).FirstOrDefault();
                byteArrayImg = ImageController.GetImage("Firms", idFirm.ToString(), true);
            }
            else
            {
                idCustomer   = db.Interviews.Where(i => i.IdInterview == id).Include(i => i.Campaign.Customer).Select(i => i.Campaign.Customer.IdCustomer).FirstOrDefault();
                idConsultant = db.Interviews.Where(i => i.IdInterview == id).Select(u => u.Id).FirstOrDefault();
                byteArrayImg = ImageController.GetImage("Users", idConsultant, true);
            }

            var    byteArrayCust = ImageController.GetImage("Customers", idCustomer.ToString(), true);
            Stream streamCust    = new MemoryStream(byteArrayCust);
            Stream streamImg     = new MemoryStream(byteArrayImg);

            WordDocument document = new WordDocument();
            IWSection    section  = document.AddSection();

            section.PageSetup.DifferentFirstPage = true;
            section.PageSetup.InsertPageNumbers(false, PageNumberAlignment.Center);
            section.PageSetup.Margins.Left  = 50;
            section.PageSetup.Margins.Right = 50;

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

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

            // Styles
            const string font = "Segoe UI";

            Style styleTitle = (WParagraphStyle)document.AddParagraphStyle("Title");

            styleTitle.CharacterFormat.FontName  = font;
            styleTitle.CharacterFormat.FontSize  = 25;
            styleTitle.CharacterFormat.TextColor = Color.FromArgb(31, 73, 125);

            Style stylePNode = (WParagraphStyle)document.AddParagraphStyle("PNode");

            stylePNode.CharacterFormat.FontName  = font;
            stylePNode.CharacterFormat.TextColor = Color.FromArgb(238, 131, 0);
            stylePNode.CharacterFormat.FontSize  = 20;

            Style styleNode = (WParagraphStyle)document.AddParagraphStyle("Node");

            styleNode.CharacterFormat.FontName  = font;
            styleNode.CharacterFormat.TextColor = Color.FromArgb(195, 23, 0);
            styleNode.CharacterFormat.FontSize  = 17;

            Style styleQuestion = (WParagraphStyle)document.AddParagraphStyle("Question");

            styleQuestion.CharacterFormat.FontName = font;
            styleQuestion.CharacterFormat.Bold     = true;
            styleQuestion.CharacterFormat.FontSize = 11;

            Style styleAnswer = (WParagraphStyle)document.AddParagraphStyle("Answer");

            styleAnswer.CharacterFormat.FontName  = font;
            styleAnswer.CharacterFormat.FontSize  = 11;
            styleAnswer.CharacterFormat.TextColor = Color.FromArgb(31, 73, 125);

            Style styleList = (WParagraphStyle)document.AddParagraphStyle("List");

            styleList.CharacterFormat.FontName       = font;
            styleList.CharacterFormat.TextColor      = Color.FromArgb(51, 132, 204);
            styleList.CharacterFormat.FontSize       = 11;
            styleList.CharacterFormat.UnderlineStyle = UnderlineStyle.Single;

            Style styleComment = (WParagraphStyle)document.AddParagraphStyle("Comment");

            styleComment.CharacterFormat.FontName = font;
            styleComment.CharacterFormat.Italic   = true;
            styleComment.CharacterFormat.FontSize = 11;

            var format = new RowFormat();

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

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

            // Inserting logo image to the table cells.
            headerPar = table[0, 0].AddParagraph() as WParagraph;
            headerPar.AppendPicture(Image.FromStream(streamImg));
            (headerPar.Items[0] as WPicture).Width  = 50;
            (headerPar.Items[0] as WPicture).Height = 50;
            headerPar.AppendText(Environment.NewLine);
            var userName = db.Users.Find(idConsultant).FullName;

            switch (type)
            {
            case 1:
            case 2:
                textRange = headerPar.AppendText("Manager: " + userName);
                textRange.CharacterFormat.FontName = font;
                headerPar.AppendText(Environment.NewLine);
                textRange = headerPar.AppendText("Type : Campaign");
                textRange.CharacterFormat.FontName = font;
                break;

            case 3:
            case 4:
                textRange = headerPar.AppendText("Consultant: " + userName);
                textRange.CharacterFormat.FontName = font;
                headerPar.AppendText(Environment.NewLine);
                textRange = headerPar.AppendText("Type: Interview");
                textRange.CharacterFormat.FontName = font;
                break;
            }

            headerPar.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;

            var customerName = db.Customers.Find(idCustomer).Name;
            var industryName =
                db.Customers.Where(c => c.IdCustomer == idCustomer)
                .Include(c => c.Industry)
                .Select(c => c.Industry.Name).FirstOrDefault();

            // Inserting text to the table second cell.
            headerPar = table[0, 1].AddParagraph() as WParagraph;

            headerPar.AppendPicture(Image.FromStream(streamCust));
            ((WPicture)headerPar.Items[0]).Width  = 50;
            ((WPicture)headerPar.Items[0]).Height = 50;
            headerPar.AppendText(Environment.NewLine);
            headerPar.AppendText("Customer: " + customerName);
            headerPar.AppendText(Environment.NewLine);
            headerPar.AppendText("Industry: " + industryName);
            headerPar.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Right;

            section           = document.AddSection();
            section.BreakCode = SectionBreakCode.NoBreak;
            IWParagraph paragraph = section.AddParagraph();

            //TableOfContent toc = paragraph.AppendTOC(1, 3);
            //toc.UseHeadingStyles = false;
            //toc.SetTOCLevelStyle(1, "Title");
            //toc.SetTOCLevelStyle(2, "PNode");
            //toc.SetTOCLevelStyle(3, "Node");

            if (type == 1 || type == 2)
            {
                campaign = db.Campaigns.Find(id);
                var idQuestionnaire   = db.Interviews.Where(i => i.Campaign.IdCampaign == id).Include(i => i.Campaign).Select(i => i.Campaign.IdQuestionnaire).FirstOrDefault();
                var questions         = db.Questions.Where(q => q.IdQuestionnaire == idQuestionnaire);
                var questionnairename = db.Questionnaires.Find(idQuestionnaire).Name;
                var interviewees      =
                    db.CandidateCampaigns.Include(cc => cc.Candidate).Include(x => x.Group)
                    .Where(cc => cc.IdCampaign == campaign.IdCampaign)
                    .Select(x => x.Candidate);
                var consultants =
                    db.Campaigns.Where(c => c.IdCampaign == campaign.IdCampaign)
                    .Include(c => c.ApplicationUsers)
                    .Select(c => c.ApplicationUsers);
                string start = "";

                if (campaign.StartDate != null)
                {
                    start = campaign.StartDate.Value.ToShortDateString();
                }

                var end = "";

                if (campaign.EndDate != null)
                {
                    end = campaign.EndDate.Value.ToShortDateString();
                }

                paragraph.AppendText(Environment.NewLine + Environment.NewLine + Environment.NewLine);
                textRange = paragraph.AppendText("Campaign: " + campaign.Name);
                paragraph.ApplyStyle("Title");
                paragraph.AppendText(Environment.NewLine + Environment.NewLine);
                paragraph = section.AddParagraph();
                textRange = paragraph.AppendText("Start: " + start + " -> Expected End: " + end);
                textRange.CharacterFormat.FontName            = font;
                paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
                paragraph.AppendText(Environment.NewLine + Environment.NewLine);
                textRange = paragraph.AppendText("Questionnaire: " + questionnairename);
                textRange.CharacterFormat.FontName = font;
                paragraph.AppendText(Environment.NewLine + Environment.NewLine);
                textRange = paragraph.AppendText("Description: " + campaign.Description);
                textRange.CharacterFormat.FontName = font;
                paragraph.AppendText(Environment.NewLine + Environment.NewLine);

                if (type == 2 && !string.IsNullOrEmpty(campaign.Comment))
                {
                    textRange = paragraph.AppendText("Comment: " + campaign.Comment);
                    textRange.CharacterFormat.FontName = font;
                }

                paragraph.AppendText(Environment.NewLine + Environment.NewLine);

                paragraph = section.AddParagraph();
                paragraph.AppendText("Consultants: ");
                paragraph.ApplyStyle("List");

                foreach (var consultant in consultants)
                {
                    paragraph = section.AddParagraph();
                    textRange = paragraph.AppendText(consultant.FullName);
                    textRange.CharacterFormat.FontName = font;
                    paragraph.ListFormat.ApplyDefBulletStyle();
                }
                var dbg = new ApplicationDbContext();
                if (type == 2)
                {
                    paragraph = section.AddParagraph();
                    paragraph.AppendText("Interviewees: ");
                    paragraph.ApplyStyle("List");

                    foreach (var interviewee in interviewees)
                    {
                        paragraph = section.AddParagraph();
                        var group     = dbg.CandidateCampaigns.Where(cc => cc.IdCandidate == interviewee.IdCandidate).Select(cc => cc.Group).FirstOrDefault();
                        var groupname = "";
                        if (group != null)
                        {
                            groupname = group.Name;
                        }
                        textRange = paragraph.AppendText(interviewee.FullNameAndFunction + " - " + groupname);
                        textRange.CharacterFormat.FontName = font;
                        paragraph.ListFormat.ApplyDefBulletStyle();
                    }
                }

                // Nodes
                var fullnodes = db.Nodes.Where(x => x.IdQuestionnaire == idQuestionnaire).ToList();

                if (fullnodes.Any())
                {
                    var root = fullnodes.FirstOrDefault(r => r.IsRoot);
                    if (root != null)
                    {
                        var nodes  = fullnodes.Where(n => !n.IsRoot && n.IdParentNode != root.IdNode).ToList();
                        var pnodes = fullnodes.FindAll(p => p.IdParentNode == root.IdNode).ToList();

                        foreach (var pnode in pnodes)
                        {
                            section   = document.AddSection();
                            paragraph = section.AddParagraph();
                            paragraph.AppendText(Environment.NewLine);
                            paragraph.AppendText(pnode.Name);
                            paragraph.ApplyStyle("PNode");

                            if (db.Questions.Any(x => x.IdNode == pnode.IdNode))
                            {
                                foreach (var question in questions.Where(q => q.IdNode == pnode.IdNode))
                                {
                                    paragraph = section.AddParagraph();
                                    paragraph.AppendText(question.Description);
                                    paragraph.ApplyStyle("Question");
                                    paragraph.AppendText(Environment.NewLine);

                                    if (!question.IsRelevant)
                                    {
                                        textRange.CharacterFormat.TextColor = Color.DimGray;
                                    }

                                    section.AddParagraph().AppendText(Environment.NewLine);
                                    var dbi = new ApplicationDbContext();

                                    foreach (var answer in dba.Answers.Where(a => a.IdQuestion == question.IdQuestion && a.Interview.IdCampaign == campaign.IdCampaign && !a.Interview.Deleted))
                                    {
                                        var intervname = dbi.Interviews.Find(answer.IdInterview).Name;
                                        paragraph = section.AddParagraph();
                                        paragraph.AppendText("Answer from Interview " + intervname + ":");
                                        paragraph.ApplyStyle("Answer");

                                        if (answer != null && answer.IntervieweeAnswer != null)
                                        {
                                            if (question.AnswerType == AnswerType.Integer)
                                            {
                                                textRange = paragraph.AppendText(answer.IntervieweeAnswer + " / 5");
                                            }
                                            else
                                            {
                                                textRange = paragraph.AppendText(answer.IntervieweeAnswer);
                                            }
                                            textRange.CharacterFormat.FontName = font;
                                            textRange.CharacterFormat.Bold     = true;
                                            paragraph.AppendText(Environment.NewLine);
                                        }
                                        else
                                        {
                                            paragraph = section.AddParagraph();
                                            textRange = paragraph.AppendText("No answer yet");
                                            textRange.CharacterFormat.FontName  = font;
                                            textRange.CharacterFormat.TextColor = Color.DarkGray;
                                            paragraph.AppendText(Environment.NewLine);
                                        }

                                        if (type == 2 && !string.IsNullOrEmpty(answer.ConsultantComment))
                                        {
                                            if (answer.Comment != null)
                                            {
                                                paragraph = section.AddParagraph();
                                                paragraph.AppendText("Comment: " + answer.Comment);
                                                paragraph.ApplyStyle("Comment");
                                                paragraph.AppendText(Environment.NewLine);
                                            }
                                            paragraph = section.AddParagraph();
                                            paragraph.AppendText("Consultant's comment: " + answer.ConsultantComment);
                                            paragraph.ApplyStyle("Comment");
                                            paragraph.AppendText(Environment.NewLine);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                foreach (var node in nodes.Where(n => n.IdParentNode == pnode.IdNode))
                                {
                                    paragraph = section.AddParagraph();
                                    paragraph.AppendText(Environment.NewLine);
                                    paragraph.AppendText(" > " + node.Name);
                                    paragraph.ApplyStyle("Node");
                                    paragraph.AppendText(Environment.NewLine);

                                    foreach (var question in questions.Where(q => q.IdNode == node.IdNode))
                                    {
                                        paragraph = section.AddParagraph();
                                        paragraph.AppendText(question.Description);
                                        paragraph.ApplyStyle("Question");
                                        paragraph.AppendText(Environment.NewLine);

                                        if (!question.IsRelevant)
                                        {
                                            textRange.CharacterFormat.TextColor = Color.DimGray;
                                        }
                                        var dbi = new ApplicationDbContext();

                                        foreach (var answer in dba.Answers.Where(a => a.IdQuestion == question.IdQuestion && a.Interview.IdCampaign == campaign.IdCampaign && !a.Interview.Deleted))
                                        {
                                            var intervname = dbi.Interviews.Find(answer.IdInterview).Name;
                                            paragraph = section.AddParagraph();
                                            paragraph.AppendText("Answer from Interview " + intervname + ":");
                                            paragraph.ApplyStyle("Answer");

                                            if (answer.IntervieweeAnswer != null)
                                            {
                                                paragraph = section.AddParagraph();
                                                if (question.AnswerType == AnswerType.Integer)
                                                {
                                                    textRange = paragraph.AppendText(answer.IntervieweeAnswer + " / 5");
                                                }
                                                else
                                                {
                                                    textRange = paragraph.AppendText(answer.IntervieweeAnswer);
                                                }
                                                textRange.CharacterFormat.FontName = font;
                                                textRange.CharacterFormat.Bold     = true;
                                                paragraph.AppendText(Environment.NewLine);
                                            }
                                            else
                                            {
                                                paragraph = section.AddParagraph();
                                                textRange = paragraph.AppendText("No answer yet");
                                                textRange.CharacterFormat.FontName  = font;
                                                textRange.CharacterFormat.TextColor = Color.DarkGray;
                                                paragraph.AppendText(Environment.NewLine);
                                            }

                                            if (type == 2 && !string.IsNullOrEmpty(answer.ConsultantComment))
                                            {
                                                if (answer.Comment != null)
                                                {
                                                    paragraph = section.AddParagraph();
                                                    paragraph.AppendText("Comment: " + answer.Comment);
                                                    paragraph.ApplyStyle("Comment");
                                                    paragraph.AppendText(Environment.NewLine);
                                                }
                                                paragraph = section.AddParagraph();
                                                paragraph.AppendText("Consultant's comment: " + answer.ConsultantComment);
                                                paragraph.ApplyStyle("Comment");
                                                paragraph.AppendText(Environment.NewLine);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else if (type == 3 || type == 4)
            {
                interview = db.Interviews.Find(id);
                var idInterviewee   = db.Interviewees.Where(i => i.IdInterview == id).Select(i => i.IdCandidate).FirstOrDefault();
                var idQuestionnaire = db.Interviews.Where(i => i.IdInterview == id).Include(i => i.Campaign).Select(i => i.Campaign.IdQuestionnaire).FirstOrDefault();
                var questions       = db.Questions.Where(q => q.IdQuestionnaire == idQuestionnaire);
                var interviewees    =
                    db.Interviewees.Include(cc => cc.Candidate)
                    .Where(cc => cc.IdInterview == interview.IdInterview)
                    .Select(x => x.Candidate);
                var consultant = interview.ApplicationUsers;

                paragraph.AppendText(Environment.NewLine + Environment.NewLine + Environment.NewLine);
                paragraph.AppendText("Interview: " + interview.Name);
                paragraph.ApplyStyle("Title");
                paragraph.AppendText(Environment.NewLine + Environment.NewLine);
                paragraph = section.AddParagraph();
                textRange = paragraph.AppendText("Date: " + interview.Date.ToShortDateString() + Environment.NewLine);
                textRange.CharacterFormat.FontName = font;
                paragraph.AppendText(Environment.NewLine + Environment.NewLine);

                textRange = paragraph.AppendText("Description: " + interview.Description);
                textRange.CharacterFormat.FontName = font;
                paragraph.AppendText(Environment.NewLine + Environment.NewLine);

                if (type == 4 && interview.Comment != null)
                {
                    textRange = paragraph.AppendText("Comment: " + interview.Comment + Environment.NewLine);
                    textRange.CharacterFormat.FontName = font;
                }

                paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
                paragraph.AppendText(Environment.NewLine + Environment.NewLine);

                paragraph = section.AddParagraph();
                paragraph.AppendText("Consultants: ");
                paragraph.ApplyStyle("List");

                paragraph = section.AddParagraph();
                textRange = paragraph.AppendText(consultant.FullName);
                textRange.CharacterFormat.FontName = font;
                paragraph.ListFormat.ApplyDefBulletStyle();

                paragraph = section.AddParagraph();
                paragraph.AppendText("Interviewee(s): ");
                paragraph.ApplyStyle("List");

                var dbc = new ApplicationDbContext();

                foreach (var i in interviewees)
                {
                    paragraph = section.AddParagraph();
                    var group =
                        dbc.CandidateCampaigns.Where(
                            cc => cc.IdCandidate == i.IdCandidate && cc.IdCampaign == interview.IdCampaign).Select(cc => cc.Group).FirstOrDefault();
                    var groupname = "";
                    if (group != null)
                    {
                        groupname = group.Name;
                    }
                    textRange = paragraph.AppendText(i.FullNameAndFunction + " - " + groupname);
                    textRange.CharacterFormat.FontName = font;
                    textRange.CharacterFormat.Bold     = false;
                    paragraph.ListFormat.ApplyDefBulletStyle();
                }

                var fullnodes = db.Nodes.Where(x => x.IdQuestionnaire == idQuestionnaire).ToList();

                if (fullnodes.Any())
                {
                    var root = fullnodes.FirstOrDefault(r => r.IsRoot);
                    if (root != null)
                    {
                        var nodes  = fullnodes.Where(n => !n.IsRoot && n.IdParentNode != root.IdNode).ToList();
                        var pnodes = fullnodes.FindAll(p => p.IdParentNode == root.IdNode).ToList();

                        foreach (var pnode in pnodes)
                        {
                            var score = db.CustomScores.FirstOrDefault(c => c.IdNode == pnode.IdNode && c.IdInterview == interview.IdInterview);
                            var val   = 0;

                            if (score != null)
                            {
                                val = score.Value != null ? score.Value : 0;
                            }
                            section   = document.AddSection();
                            paragraph = section.AddParagraph();
                            paragraph.AppendText(Environment.NewLine);
                            paragraph.AppendText(pnode.Name + "     " + val + " / 5");
                            paragraph.ApplyStyle("PNode");

                            if (db.Questions.Any(x => x.IdNode == pnode.IdNode))
                            {
                                foreach (var question in questions.Where(q => q.IdNode == pnode.IdNode))
                                {
                                    var answer = dba.Answers.FirstOrDefault(a => a.IdQuestion == question.IdQuestion && a.IdInterview == id);

                                    paragraph = section.AddParagraph();
                                    paragraph.AppendText(question.Description);
                                    paragraph.ApplyStyle("Question");
                                    paragraph.AppendText(Environment.NewLine);
                                    if (answer != null && answer.IntervieweeAnswer != null)
                                    {
                                        paragraph = section.AddParagraph();
                                        paragraph.AppendText("Answer:");
                                        paragraph.ApplyStyle("Answer");
                                        paragraph = section.AddParagraph();

                                        if (question.AnswerType == AnswerType.Integer)
                                        {
                                            paragraph.AppendText(answer.IntervieweeAnswer + " / 5");
                                        }
                                        else
                                        {
                                            paragraph.AppendText(answer.IntervieweeAnswer);
                                        }
                                        textRange.CharacterFormat.FontName = font;
                                        textRange.CharacterFormat.Bold     = true;
                                        paragraph.AppendText(Environment.NewLine);

                                        if (type == 4 && !string.IsNullOrEmpty(answer.ConsultantComment))
                                        {
                                            if (answer.Comment != null)
                                            {
                                                paragraph = section.AddParagraph();
                                                paragraph.AppendText("Comment: " + answer.Comment);
                                                paragraph.ApplyStyle("Comment");
                                                paragraph.AppendText(Environment.NewLine);
                                            }
                                            paragraph = section.AddParagraph();
                                            paragraph.AppendText("Consultant's comment: " + answer.ConsultantComment);
                                            paragraph.ApplyStyle("Comment");
                                            paragraph.AppendText(Environment.NewLine);
                                        }
                                    }
                                    else
                                    {
                                        paragraph = section.AddParagraph();
                                        textRange = paragraph.AppendText("No answer yet");
                                        textRange.CharacterFormat.FontName  = font;
                                        textRange.CharacterFormat.TextColor = Color.DarkGray;
                                        paragraph.AppendText(Environment.NewLine);
                                    }
                                }
                            }
                            else
                            {
                                foreach (var node in nodes.Where(n => n.IdParentNode == pnode.IdNode))
                                {
                                    paragraph = section.AddParagraph();
                                    paragraph.AppendText(Environment.NewLine);
                                    paragraph.AppendText(" > " + node.Name + "     " + val + " / 5");
                                    paragraph.ApplyStyle("Node");
                                    paragraph.AppendText(Environment.NewLine);

                                    foreach (var question in questions.Where(q => q.IdNode == node.IdNode))
                                    {
                                        var answer = dba.Answers.FirstOrDefault(a => a.IdQuestion == question.IdQuestion && a.IdInterview == id);

                                        paragraph = section.AddParagraph();
                                        paragraph.AppendText(question.Description);
                                        paragraph.ApplyStyle("Question");
                                        paragraph.AppendText(Environment.NewLine);

                                        if (answer != null && answer.IntervieweeAnswer != null)
                                        {
                                            paragraph = section.AddParagraph();
                                            paragraph.AppendText("Answer:");
                                            paragraph.ApplyStyle("Answer");
                                            paragraph = section.AddParagraph();
                                            if (question.AnswerType == AnswerType.Integer)
                                            {
                                                paragraph.AppendText(answer.IntervieweeAnswer + " / 5");
                                            }
                                            else
                                            {
                                                paragraph.AppendText(answer.IntervieweeAnswer);
                                            }
                                            textRange.CharacterFormat.FontName = font;
                                            textRange.CharacterFormat.Bold     = true;
                                            paragraph.AppendText(Environment.NewLine);

                                            if (type == 4 && !string.IsNullOrEmpty(answer.ConsultantComment))
                                            {
                                                if (answer.Comment != null)
                                                {
                                                    paragraph = section.AddParagraph();
                                                    paragraph.AppendText("Comment: " + answer.Comment);
                                                    paragraph.ApplyStyle("Comment");
                                                    paragraph.AppendText(Environment.NewLine);
                                                }

                                                paragraph = section.AddParagraph();
                                                paragraph.AppendText("Consultant's comment: " + answer.ConsultantComment);
                                                paragraph.ApplyStyle("Comment");
                                                paragraph.AppendText(Environment.NewLine);
                                            }
                                        }
                                        else
                                        {
                                            paragraph = section.AddParagraph();
                                            textRange = paragraph.AppendText("No answer yet");
                                            textRange.CharacterFormat.FontName  = font;
                                            textRange.CharacterFormat.TextColor = Color.DarkGray;
                                            paragraph.AppendText(Environment.NewLine);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            switch (type)
            {
            case 1:
                if (!pdf)
                {
                    return(document.ExportAsActionResult(DateTime.Now.ToShortDateString() + "_" + campaign.Name + "_Customer.docx", FormatType.Word2013, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment));
                }
                else
                {
                    var converted = ConvertToPDF(document);
                    return(converted.ExportAsActionResult(DateTime.Now.ToShortDateString() + "_" + campaign.Name + "_Customer.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save));
                }

            case 2:
                if (!pdf)
                {
                    return(document.ExportAsActionResult(DateTime.Now.ToShortDateString() + "_" + campaign.Name + "_Firm.docx", FormatType.Word2013, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment));
                }
                else
                {
                    var converted = ConvertToPDF(document);
                    return(converted.ExportAsActionResult(DateTime.Now.ToShortDateString() + "_" + campaign.Name + "_Firm.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save));
                }

            case 3:
                if (!pdf)
                {
                    return(document.ExportAsActionResult(DateTime.Now.ToShortDateString() + "_" + interview.Name + "_Customer.docx", FormatType.Word2013, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment));
                }
                else
                {
                    var converted = ConvertToPDF(document);
                    return(converted.ExportAsActionResult(DateTime.Now.ToShortDateString() + "_" + interview.Name + "_Customer.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save));
                }

            case 4:
                if (!pdf)
                {
                    return(document.ExportAsActionResult(DateTime.Now.ToShortDateString() + "_" + interview.Name + "_Firm.docx", FormatType.Word2013, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment));
                }
                else
                {
                    var converted = ConvertToPDF(document);
                    return(converted.ExportAsActionResult(DateTime.Now.ToShortDateString() + "_" + interview.Name + "_Firm.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save));
                }
            }

            return(document.ExportAsActionResult("Report.docx", FormatType.Word2013, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment));
        }
Esempio n. 11
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            ErrorMessage.InnerText = "";
            if (hdnGroup.Value == "Word")
            {
                string path = string.Format("{0}\\..\\Data\\AdventureWorks\\AdventureWorks_Person_Contact.csv", Request.PhysicalPath.ToLower().Split(new string[] { "\\c# hbase samples" }, StringSplitOptions.None));
                try
                {
                    //Create a new document
                    WordDocument document = new WordDocument();

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

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

                    //Set Margin of the section
                    section.PageSetup.Margins.All = 72;

                    //Set page size of the section
                    section.PageSetup.PageSize = new SizeF(800, 792);

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

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

                    #region creating connection
                    HBaseConnection con = new HBaseConnection("localhost", 10003);
                    con.Open();

                    #endregion creating connection

                    #region parsing csv input file

                    csv csvObj = new csv();
                    object[,] cells;
                    cells = null;

                    cells = csvObj.Table(path, false, ',');

                    #endregion parsing csv input file

                    #region creating table
                    String        tableName      = "AdventureWorks_Person_Contact";
                    List <string> columnFamilies = new List <string>();
                    columnFamilies.Add("info");
                    columnFamilies.Add("contact");
                    columnFamilies.Add("others");
                    if (!HBaseOperation.IsTableExists(tableName, con))
                    {
                        if (columnFamilies.Count > 0)
                        {
                            HBaseOperation.CreateTable(tableName, columnFamilies, con);
                        }
                        else
                        {
                            throw new HBaseException("ERROR: Table must have at least one column family");
                        }
                    }
                    # endregion

                    #region Inserting Values
                    string[] column = new string[] { "CONTACTID", "FULLNAME", "AGE", "EMAILID", "PHONE", "MODIFIEDDATE" };
                    Dictionary <string, IList <HMutation> > rowCollection = new Dictionary <string, IList <HMutation> >();
                    string rowKey;
                    for (int i = 0; i < cells.GetLength(0); i++)
                    {
                        List <HMutation> mutations = new List <HMutation>();
                        rowKey = cells[i, 0].ToString();
                        for (int j = 1; j < column.Length; j++)
                        {
                            HMutation mutation = new HMutation();
                            mutation.ColumnFamily = j < 3 ? "info" : j < 5 ? "contact" : "others";
                            mutation.ColumnName   = column[j];
                            mutation.Value        = cells[i, j].ToString();
                            mutations.Add(mutation);
                        }
                        rowCollection[rowKey] = mutations;
                    }
                    HBaseOperation.InsertRows(tableName, rowCollection, con);
                    #endregion Inserting Values

                    #region scan values

                    HBaseOperation.FetchSize = 100;
                    HBaseResultSet table = HBaseOperation.ScanTable(tableName, con);

                    //Adding headertext for the table
                    doctable.AddRow(true, false);
                    //Creating new cell
                    WTableCell cell = new WTableCell(document);
                    cell.AddParagraph().AppendText("ContactId").ApplyCharacterFormat(charFormat);
                    cell.Width = 100;
                    //Adding cell to the row
                    doctable.Rows[0].Cells.Add(cell);
                    cell = new WTableCell(document);
                    cell.AddParagraph().AppendText("contact:EmailId").ApplyCharacterFormat(charFormat);
                    cell.Width = 200;
                    doctable.Rows[0].Cells.Add(cell);
                    cell = new WTableCell(document);
                    cell.AddParagraph().AppendText("contact:PhoneNo").ApplyCharacterFormat(charFormat);
                    cell.Width = 150;
                    doctable.Rows[0].Cells.Add(cell);
                    cell = new WTableCell(document);
                    cell.AddParagraph().AppendText("info:Age").ApplyCharacterFormat(charFormat);
                    cell.Width = 100;
                    doctable.Rows[0].Cells.Add(cell);
                    cell = new WTableCell(document);
                    cell.AddParagraph().AppendText("info:FullName").ApplyCharacterFormat(charFormat);
                    cell.Width = 150;
                    doctable.Rows[0].Cells.Add(cell);
                    cell = new WTableCell(document);
                    cell.AddParagraph().AppendText("others:ModifiedDate").ApplyCharacterFormat(charFormat);
                    cell.Width = 200;
                    doctable.Rows[0].Cells.Add(cell);


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

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

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

                            //Adding each data to the cell
                            cell.AddParagraph().AppendText(fields.ToString());
                            if (j != 1 && j != 2 && j != 4 && j != 5)
                            {
                                cell.Width = 100;
                            }
                            else if (j == 2 || j == 4)
                            {
                                cell.Width = 150;
                            }
                            else
                            {
                                cell.Width = 200;
                            }

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

                    #region close connection
                    //Closing the hive connection
                    con.Close();
                    #endregion close connection
                }
Esempio n. 12
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            // Creating a new document.
            WordDocument document = new WordDocument();
            //Adding a new section to the document.
            WSection section = document.AddSection() as WSection;

            //Set Margin of the section
            section.PageSetup.Margins.All = 72;
            //Set page size of the section
            section.PageSetup.PageSize = new Syncfusion.Drawing.SizeF(612, 792);
            //Create Paragraph styles
            WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle;

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

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

            // Gets the image stream.

            /*
             * IWPicture picture = paragraph.AppendPicture(new Bitmap("AdventureCycle.jpg")) as WPicture;
             *
             * picture.TextWrappingStyle = TextWrappingStyle.InFrontOfText;
             * picture.VerticalOrigin = VerticalOrigin.Margin;
             * picture.VerticalPosition = -45;
             * picture.HorizontalOrigin = HorizontalOrigin.Column;
             * picture.HorizontalPosition = 263.5f;
             * picture.WidthScale = 20;
             * picture.HeightScale = 15;
             */


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

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

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

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

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

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

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

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

            /*
             * picture = paragraph.AppendPicture(new Bitmap("Mountain-200.jpg")) as WPicture;
             * picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom;
             * picture.VerticalOrigin = VerticalOrigin.Paragraph;
             * picture.VerticalPosition = 4.5f;
             * picture.HorizontalOrigin = HorizontalOrigin.Column;
             * picture.HorizontalPosition = -2.15f;
             * picture.WidthScale = 79;
             * picture.HeightScale = 79;
             */


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

            textRange = paragraph.AppendText("Product No: BK-M68B-38\r") as WTextRange;
            textRange.CharacterFormat.FontSize = 12f;
            textRange.CharacterFormat.FontName = "Times New Roman";
            textRange = paragraph.AppendText("Size: 38\r") as WTextRange;
            textRange.CharacterFormat.FontSize = 12f;
            textRange.CharacterFormat.FontName = "Times New Roman";
            textRange = paragraph.AppendText("Weight: 25\r") as WTextRange;
            textRange.CharacterFormat.FontSize = 12f;
            textRange.CharacterFormat.FontName = "Times New Roman";
            textRange = paragraph.AppendText("Price: $2,294.99\r") as WTextRange;
            textRange.CharacterFormat.FontSize = 12f;
            textRange.CharacterFormat.FontName = "Times New Roman";
            //Appends paragraph.
            paragraph = table[0, 1].AddParagraph();
            paragraph.ParagraphFormat.AfterSpacing  = 0;
            paragraph.ParagraphFormat.LineSpacing   = 12f;
            paragraph.BreakCharacterFormat.FontSize = 12f;

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

            //Appends paragraph.
            paragraph = table[1, 1].AddParagraph();
            paragraph.ApplyStyle("Heading 1");
            paragraph.ParagraphFormat.LineSpacing = 12f;
            //Appends picture to the paragraph.

            /*
             * picture = paragraph.AppendPicture(new Bitmap("Mountain-300.jpg")) as WPicture;
             * picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom;
             * picture.VerticalOrigin = VerticalOrigin.Paragraph;
             * picture.VerticalPosition = 8.2f;
             * picture.HorizontalOrigin = HorizontalOrigin.Column;
             * picture.HorizontalPosition = -14.95f;
             * picture.WidthScale = 75;
             * picture.HeightScale = 75;
             */


            //Appends paragraph.
            paragraph = table[2, 0].AddParagraph();
            paragraph.ApplyStyle("Heading 1");
            paragraph.ParagraphFormat.LineSpacing = 12f;
            //Appends picture to the paragraph.


            /*
             * picture = paragraph.AppendPicture(new Bitmap("Road-550-W.jpg")) as WPicture;
             * picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom;
             * picture.VerticalOrigin = VerticalOrigin.Paragraph;
             * picture.VerticalPosition = 3.75f;
             * picture.HorizontalOrigin = HorizontalOrigin.Column;
             * picture.HorizontalPosition = -5f;
             * picture.WidthScale = 92;
             * picture.HeightScale = 92;
             */



            //Appends paragraph.
            paragraph = table[2, 1].AddParagraph();
            paragraph.ApplyStyle("Heading 1");
            paragraph.ParagraphFormat.AfterSpacing = 0;
            paragraph.ParagraphFormat.LineSpacing  = 12f;
            paragraph.AppendText("Road-150 ");

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

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

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

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

            // запись в файл
            using (FileStream fstream = new FileStream($"{path}\\Sample.docx", FileMode.OpenOrCreate))
            {
                document.Save(fstream, 0);
            }
        }
Esempio n. 13
0
        static void Main(string[] args)
        {
            using (WordDocument document = new WordDocument())
            {
                document.EnsureMinimal();
                document.LastSection.PageSetup.Margins.All = 72;
                WParagraph para = document.LastParagraph;
                para.AppendText("Essential DocIO - Table of Contents");
                para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
                para.ApplyStyle(BuiltinStyle.Heading4);
                para = document.LastSection.AddParagraph() as WParagraph;
                para = document.LastSection.AddParagraph() as WParagraph;
                //Insert TOC field in the Word document.
                TableOfContent toc = para.AppendTOC(1, 3);
                //Sets the heading levels 1 to 3, to include in TOC.
                toc.LowerHeadingLevel = 1;
                toc.UpperHeadingLevel = 3;
                //Adds content to the Word document with built-in heading styles.
                WSection   section = document.LastSection;
                WParagraph newPara = section.AddParagraph() as WParagraph;
                newPara.AppendBreak(BreakType.PageBreak);
                AddHeading(section, BuiltinStyle.Heading1, "Document with built-in heading styles", "This is the built-in heading 1 style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can insert TOC field in a word document. It can refresh or update TOC field by using UpdateTableOfContents method. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC.");
                AddHeading(section, BuiltinStyle.Heading2, "Section 1", "This is the built-in heading 2 style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");
                AddHeading(section, BuiltinStyle.Heading3, "Paragraph 1", "This is the built-in heading 3 style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text.");
                AddHeading(section, BuiltinStyle.Heading3, "Paragraph 2", "This is the built-in heading 3 style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph.");
                //Adds a new section to the Word document.
                section = document.AddSection() as WSection;
                section.PageSetup.Margins.All = 72;
                section.BreakCode             = SectionBreakCode.NewPage;
                AddHeading(section, BuiltinStyle.Heading2, "Section 2", "This is the built-in heading 2 style. A document can contain any number of sections. Sections are used to apply same formatting for a group of paragraphs. You can insert sections by inserting section breaks.");
                AddHeading(section, BuiltinStyle.Heading3, "Paragraph 1", "This is the built-in heading 3 style. Each section contains any number of paragraphs. A paragraph is a set of statements that gives a meaning for the text.");
                AddHeading(section, BuiltinStyle.Heading3, "Paragraph 2", "This is the built-in heading 3 style. This demonstrates the paragraphs at the same level and style as that of the previous one. A paragraph can have any number formatting. This can be attained by formatting each text range in the paragraph.");

                //Access the TOC 1 style and update its formatting.
                IWParagraphStyle toc1style = document.AddParagraphStyle("TOC 1");
                toc1style.CharacterFormat.FontName     = "Calibri";
                toc1style.CharacterFormat.FontSize     = 14;
                toc1style.CharacterFormat.Bold         = true;
                toc1style.CharacterFormat.Italic       = true;
                toc1style.ParagraphFormat.AfterSpacing = 8;

                //Access the TOC 2 style and update its formatting.
                IWParagraphStyle toc2style = document.AddParagraphStyle("TOC 2");
                toc2style.CharacterFormat.FontName     = "Calibri";
                toc2style.CharacterFormat.FontSize     = 12;
                toc2style.ParagraphFormat.AfterSpacing = 5;
                toc2style.CharacterFormat.Bold         = true;
                toc2style.ParagraphFormat.LeftIndent   = 11;

                //Access the TOC 3 style and update its formatting.
                IWParagraphStyle toc3style = document.AddParagraphStyle("TOC 3");;
                toc3style.CharacterFormat.FontName     = "Calibri";
                toc3style.CharacterFormat.FontSize     = 12;
                toc3style.ParagraphFormat.AfterSpacing = 3;
                toc3style.CharacterFormat.Italic       = true;
                toc3style.ParagraphFormat.LeftIndent   = 22;

                //Updates the table of contents.
                document.UpdateTableOfContents();
                //Saves the file in the given path
                Stream docStream = File.Create(Path.GetFullPath(@"../../../TocEntryStyle.docx"));
                document.Save(docStream, FormatType.Docx);
                docStream.Dispose();
            }
        }
        void OnButtonClicked(object sender, EventArgs e)
        {
            WordDocument document = new WordDocument();
            IWParagraphStyle style = null;
            // Adding a new section to the document.
            WSection section = document.AddSection() as WSection;
            //Set Margin of the section
            section.PageSetup.Margins.All = 72;
            IWParagraph par = document.LastSection.AddParagraph();
            WTextRange range = par.AppendText("Using CustomStyles") as WTextRange;
            range.CharacterFormat.TextBackgroundColor = Syncfusion.Drawing.Color.Red;
            range.CharacterFormat.TextColor = Syncfusion.Drawing.Color.White;
            range.CharacterFormat.FontSize = 18f;
            document.LastParagraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;

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

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

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

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

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

            //Creating a new document
            WordDocument document = new WordDocument();
            //Adding a new section to the document
            WSection section = document.AddSection() as WSection;

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

            await Nosi.GetNosiScraped();

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

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

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

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

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

            //Appends paragraph
            section.AddParagraph();

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

            document.Save(stream, FormatType.Docx);

            //Save the stream as a file in the device and invoke it for viewing
            await Xamarin.Forms.DependencyService.Get <ISave>().SaveAndView("Nosi.docx", "application/msword", stream);
        }
Esempio n. 16
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                WordDocument doc = new WordDocument();
                doc.EnsureMinimal();

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

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

                if (!this.checkBox6.Checked)
                {
                    para.AppendText("Select TOC and press F9 to update the Table of Contents").CharacterFormat.HighlightColor = Color.Yellow;
                }

                para = doc.LastSection.AddParagraph() as WParagraph;
                string title = this.textBox1.Text + "\n";
                para.AppendText(title);
                para.ApplyStyle(BuiltinStyle.Heading4);

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

                para.ApplyStyle(BuiltinStyle.Heading4);
                //Apply built-in paragraph formatting
                WSection section = doc.LastSection;
                // Set Margin of the document
                section.PageSetup.Margins.All = 72;
                if (radioButton1.Checked)
                {
                    #region Default Styles
                    WParagraph newPara = section.AddParagraph() as WParagraph;
                    newPara = section.AddParagraph() as WParagraph;
                    newPara.AppendBreak(BreakType.PageBreak);
                    WTextRange text = newPara.AppendText("Document with Default styles") as WTextRange;
                    newPara.ApplyStyle(BuiltinStyle.Heading1);
                    newPara = section.AddParagraph() as WParagraph;
                    newPara.AppendText("This is the heading1 of built in style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can only insert TOC field in a word document. It can not refresh or create TOC field. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC.");

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

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

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

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

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

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

                    #endregion
                }
                else
                {
                    #region Custom styles

                    //Custom styles.
                    WParagraphStyle pStyle1 = (WParagraphStyle)doc.AddParagraphStyle("MyStyle1");
                    WParagraphStyle pStyle2 = (WParagraphStyle)doc.AddParagraphStyle("MyStyle2");
                    WParagraphStyle pStyle3 = (WParagraphStyle)doc.AddParagraphStyle("MyStyle3");

                    //Set the Heading Styles to false in order to define custom levels to TOC.
                    toc.UseHeadingStyles = false;

                    //Set the TOC level style which determines; based on which the TOC should be created.
                    toc.SetTOCLevelStyle(1, "MyStyle1");
                    toc.SetTOCLevelStyle(2, "MyStyle2");
                    toc.SetTOCLevelStyle(3, "MyStyle3");
                    section = doc.AddSection() as WSection;

                    pStyle1.CharacterFormat.FontName = "Cambria";
                    pStyle1.CharacterFormat.FontSize = 30f;

                    para = section.AddParagraph() as WParagraph;

                    WTextRange text = para.AppendText("Document with Custom Styles") as WTextRange;
                    para.ApplyStyle("MyStyle1");
                    para = doc.LastSection.AddParagraph() as WParagraph;
                    para.AppendText("This is the heading1 of built in style. This sample demonstrates the TOC insertion in a word document. Note that DocIO can only insert TOC field in a word document. It can not refresh or create TOC field. MS Word refreshes the TOC field after insertion. Please update the field or press F9 key to refresh the TOC.");

                    pStyle2.CharacterFormat.FontName = "Cambria";
                    pStyle2.CharacterFormat.FontSize = 20f;

                    doc.LastSection.AddParagraph();

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

                    pStyle3.CharacterFormat.FontName = "Cambria";
                    pStyle3.CharacterFormat.FontSize = 14f;

                    doc.LastSection.AddParagraph();

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

                    #endregion
                }
                if (this.numericUpDown2.Value < this.numericUpDown1.Value)
                {
                    MessageBoxAdv.Show("Not a valid heading level range. UpperHeadingLevel must be greater than LowerHeadingLevel");
                }
                else
                {
                    toc.IncludePageNumbers    = checkBox1.Checked;
                    toc.RightAlignPageNumbers = checkBox2.Checked;
                    toc.UseHyperlinks         = checkBox3.Checked;
                    toc.LowerHeadingLevel     = Convert.ToInt32(this.numericUpDown1.Value);
                    toc.UpperHeadingLevel     = Convert.ToInt32(this.numericUpDown2.Value);
                    //Right click text. Select Paragraph option. Set OutlineLevel. Update TOC toc see the text added in TOC.
                    toc.UseOutlineLevels = this.checkBox4.Checked;
                    //Select the text that should be marked as Table of contents.
                    //Press ALT+SHIFT+O. A dialog box will appear with options to enter the text, select the table identifier and level.
                    //Choose the table identifier and level for the test and click �Mark�. Update TOC toc see the text added in TOC.
                    //Sets the Table Identifier if necessary.
                    //toc.TableID = "B";
                    toc.UseTableEntryFields = this.checkBox5.Checked;
                    //Updates the table of contents.
                    if (this.checkBox6.Checked)
                    {
                        doc.UpdateTableOfContents();
                    }
                    //Save as doc format
                    if (wordDocRadioBtn.Checked)
                    {
                        //Saving the document to disk.
                        doc.Save("Sample.doc");

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

                //A new document is created.
                WordDocument document = new WordDocument();
                //Adding a new section to the document.
                WSection section = document.AddSection() as WSection;
                //Set Margin of the section
                section.PageSetup.Margins.All = 72;
                //Set page size of the section
                section.PageSetup.PageSize = new SizeF(612, 792);
                //Create Paragraph styles
                WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle;
                style.CharacterFormat.FontName      = "Calibri";
                style.CharacterFormat.FontSize      = 11f;
                style.ParagraphFormat.BeforeSpacing = 0;
                style.ParagraphFormat.AfterSpacing  = 8;
                style.ParagraphFormat.LineSpacing   = 13.8f;

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

                WPicture picture = paragraph.AppendPicture(Image.FromFile(dataPath + "AdventureCycle.jpg")) as WPicture;
                picture.TextWrappingStyle  = TextWrappingStyle.InFrontOfText;
                picture.VerticalOrigin     = VerticalOrigin.Margin;
                picture.VerticalPosition   = -45;
                picture.HorizontalOrigin   = HorizontalOrigin.Column;
                picture.HorizontalPosition = 263.5f;
                picture.WidthScale         = 20;
                picture.HeightScale        = 15;

                paragraph.ApplyStyle("Normal");
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left;
                WTextRange textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange;
                textRange.CharacterFormat.FontSize  = 12f;
                textRange.CharacterFormat.FontName  = "Calibri";
                textRange.CharacterFormat.TextColor = Color.Red;

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


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

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

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


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

                //Appends paragraph.
                paragraph = table[0, 0].AddParagraph();
                paragraph.ParagraphFormat.AfterSpacing  = 0;
                paragraph.BreakCharacterFormat.FontSize = 12f;
                //Appends picture to the paragraph.
                picture = paragraph.AppendPicture(Image.FromFile(dataPath + "Mountain-200.jpg")) as WPicture;
                picture.TextWrappingStyle  = TextWrappingStyle.TopAndBottom;
                picture.VerticalOrigin     = VerticalOrigin.Paragraph;
                picture.VerticalPosition   = 4.5f;
                picture.HorizontalOrigin   = HorizontalOrigin.Column;
                picture.HorizontalPosition = -2.15f;
                picture.WidthScale         = 79;
                picture.HeightScale        = 79;

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

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

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

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

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

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

                //Appends paragraph.
                paragraph = table[2, 0].AddParagraph();
                paragraph.ApplyStyle("Heading 1");
                paragraph.ParagraphFormat.LineSpacing = 12f;
                //Appends picture to the paragraph.
                picture = paragraph.AppendPicture(Image.FromFile(dataPath + "Road-550-W.jpg")) as WPicture;
                picture.TextWrappingStyle  = TextWrappingStyle.TopAndBottom;
                picture.VerticalOrigin     = VerticalOrigin.Paragraph;
                picture.VerticalPosition   = 3.75f;
                picture.HorizontalOrigin   = HorizontalOrigin.Column;
                picture.HorizontalPosition = -5f;
                picture.WidthScale         = 92;
                picture.HeightScale        = 92;

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

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

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

                            //Exit
                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBoxAdv.Show("PDF Viewer is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                else
                {
                    // Exit
                    this.Close();
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
Esempio n. 18
0
        public ActionResult DocIOFeatures(string Group1)
        {
            if (Group1 == null)
            {
                return(View());
            }
            string dataPath3 = ResolveApplicationDataPath("", "Content\\Images\\DocIO");
            //A new document is created.
            WordDocument document = new WordDocument();
            //Adding a new section to the document.
            WSection section = document.AddSection() as WSection;

            //Set Margin of the section
            section.PageSetup.Margins.All = 72;
            //Set page size of the section
            section.PageSetup.PageSize = new SizeF(612, 792);
            //Create Paragraph styles
            WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle;

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

            paragraph.ApplyStyle("Heading 1");
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            WTextRange textRange = paragraph.AppendText("Syncfusion Metro Studio") as WTextRange;

            textRange.CharacterFormat.FontSize = 18f;
            textRange.CharacterFormat.FontName = "Calibri";
            //Appends paragraph.
            paragraph = section.AddParagraph();
            paragraph.ParagraphFormat.FirstLineIndent = 36;
            //Appends paragraph.
            paragraph = section.AddParagraph();
            paragraph.ParagraphFormat.FirstLineIndent = 36;
            paragraph.BreakCharacterFormat.FontSize   = 12f;
            textRange = paragraph.AppendText("Syncfusion Metro Studio is a collection of over 1700 Metro-style icon templates that can be easily customized to create thousands of unique Metro icons. Metro is a design language so it can be applied to any platform or technology. At Syncfusion we have used these icons in everything from PowerPoint presentations to applications written in all .NET platforms including WPF, Silverlight, Windows Phone, Windows Forms, ASP.NET, and ASP.NET MVC.") as WTextRange;
            textRange.CharacterFormat.FontSize = 12f;
            #region Insert Table.
            //Appends table.
            IWTable table = section.AddTable();
            table.ResetCells(3, 2);
            table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.None;
            table.TableFormat.IsAutoResized      = true;
            //Appends paragraph.
            paragraph = table[0, 0].AddParagraph();
            paragraph.ParagraphFormat.AfterSpacing  = 0;
            paragraph.BreakCharacterFormat.FontSize = 12f;
            //Appends picture to the paragraph.
            WPicture picture = paragraph.AppendPicture(Image.FromFile(System.IO.Path.Combine(dataPath3, "MetroStudio1.png"))) as WPicture;
            picture.TextWrappingStyle  = TextWrappingStyle.TopAndBottom;
            picture.VerticalOrigin     = VerticalOrigin.Paragraph;
            picture.VerticalPosition   = 0;
            picture.HorizontalOrigin   = HorizontalOrigin.Column;
            picture.HorizontalPosition = -5.15f;
            picture.WidthScale         = 79;
            picture.HeightScale        = 79;
            //Appends paragraph.
            paragraph = table[0, 1].AddParagraph();
            paragraph.ApplyStyle("Heading 1");
            paragraph.ParagraphFormat.AfterSpacing = 0;
            paragraph.ParagraphFormat.LineSpacing  = 12f;
            paragraph.AppendText("Developer-friendly icon editor ");
            //Appends paragraph.
            paragraph = table[0, 1].AddParagraph();
            paragraph.ParagraphFormat.AfterSpacing  = 0;
            paragraph.ParagraphFormat.LineSpacing   = 12f;
            paragraph.BreakCharacterFormat.FontSize = 12f;
            paragraph.BreakCharacterFormat.FontName = "Times New Roman";
            textRange = paragraph.AppendText("Metro Studio includes a powerful icon editor that lets you quickly find and customize all the icons that you need in only a few minutes. ") as WTextRange;
            textRange.CharacterFormat.FontSize = 12f;
            textRange.CharacterFormat.FontName = "Times New Roman";
            //Appends paragraph.
            paragraph = table[0, 1].AddParagraph();
            paragraph.ParagraphFormat.AfterSpacing  = 0;
            paragraph.ParagraphFormat.LineSpacing   = 12f;
            paragraph.BreakCharacterFormat.FontSize = 12f;
            //Appends paragraph.
            paragraph = table[1, 0].AddParagraph();
            paragraph.ApplyStyle("Heading 1");
            paragraph.ParagraphFormat.AfterSpacing = 0;
            paragraph.ParagraphFormat.LineSpacing  = 12f;
            paragraph.AppendText("Convert fonts to icons ");
            //Appends paragraph.
            paragraph = table[1, 0].AddParagraph();
            paragraph.ParagraphFormat.AfterSpacing  = 0;
            paragraph.ParagraphFormat.LineSpacing   = 12f;
            paragraph.BreakCharacterFormat.FontSize = 12f;
            paragraph.BreakCharacterFormat.FontName = "Times New Roman";
            textRange = paragraph.AppendText("Easily customize thousands of font characters as icons and export them to the desired formats. ") as WTextRange;
            textRange.CharacterFormat.FontSize = 12f;
            textRange.CharacterFormat.FontName = "Times New Roman";
            //Appends paragraph.
            paragraph = table[1, 0].AddParagraph();
            paragraph.ParagraphFormat.AfterSpacing  = 0;
            paragraph.ParagraphFormat.LineSpacing   = 12f;
            paragraph.BreakCharacterFormat.FontSize = 12f;
            //Appends paragraph.
            paragraph = table[1, 1].AddParagraph();
            paragraph.ApplyStyle("Heading 1");
            paragraph.ParagraphFormat.LineSpacing = 12f;
            //Appends picture to the paragraph.
            picture = paragraph.AppendPicture(Image.FromFile(System.IO.Path.Combine(dataPath3, "MetroStudio2.png"))) as WPicture;
            picture.TextWrappingStyle  = TextWrappingStyle.TopAndBottom;
            picture.VerticalOrigin     = VerticalOrigin.Paragraph;
            picture.VerticalPosition   = 8.2f;
            picture.HorizontalOrigin   = HorizontalOrigin.Column;
            picture.HorizontalPosition = -14.95f;
            picture.WidthScale         = 75;
            picture.HeightScale        = 75;
            //Appends paragraph.
            paragraph = table[2, 0].AddParagraph();
            paragraph.ApplyStyle("Heading 1");
            paragraph.ParagraphFormat.LineSpacing = 12f;
            //Appends picture to the paragraph.
            picture = paragraph.AppendPicture(Image.FromFile(System.IO.Path.Combine(dataPath3, "MetroStudio3.png"))) as WPicture;
            picture.TextWrappingStyle  = TextWrappingStyle.TopAndBottom;
            picture.VerticalOrigin     = VerticalOrigin.Paragraph;
            picture.VerticalPosition   = 0;
            picture.HorizontalOrigin   = HorizontalOrigin.Column;
            picture.HorizontalPosition = -4.9f;
            picture.WidthScale         = 92;
            picture.HeightScale        = 92;
            //Appends paragraph.
            paragraph = table[2, 1].AddParagraph();
            paragraph.ApplyStyle("Heading 1");
            paragraph.ParagraphFormat.AfterSpacing = 0;
            paragraph.ParagraphFormat.LineSpacing  = 12f;
            paragraph.AppendText("Organize icons as projects ");
            //Appends paragraph.
            paragraph = table[2, 1].AddParagraph();
            paragraph.ParagraphFormat.AfterSpacing  = 0;
            paragraph.ParagraphFormat.LineSpacing   = 12f;
            paragraph.BreakCharacterFormat.FontSize = 12f;
            paragraph.BreakCharacterFormat.FontName = "Times New Roman";
            textRange = paragraph.AppendText("Organize icons into projects that can be serialized for modification at a later time. Multiple icons in a project can be exported with a single click. ") as WTextRange;
            textRange.CharacterFormat.FontSize = 12f;
            textRange.CharacterFormat.FontName = "Times New Roman";
            //Appends paragraph.
            paragraph = table[2, 1].AddParagraph();
            paragraph.ApplyStyle("Heading 1");
            paragraph.ParagraphFormat.LineSpacing = 12f;
            #endregion
            //Appends paragraph.
            section.AddParagraph();
            #region saveOption
            if (Group1 == "Word97To2003")
            {
                //Save as .doc Word 97-2003 format
                return(document.ExportAsActionResult("Sample.doc", FormatType.Doc, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment));
            }
            //Save as .docx Word 2007 format
            else if (Group1 == "Word2007")
            {
                return(document.ExportAsActionResult("Sample.docx", FormatType.Word2007, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment));
            }
            //Save as .docx Word 2010 format
            else if (Group1 == "Word2010")
            {
                return(document.ExportAsActionResult("Sample.docx", FormatType.Word2010, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment));
            }
            //Save as .docx Word 2013 format
            else if (Group1 == "Word2013")
            {
                return(document.ExportAsActionResult("Sample.docx", FormatType.Word2013, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment));
            }
            #endregion saveOption
            return(View());
        }
Esempio n. 19
0
        public MemoryStream CreateWord()
        {
            //Creating a new document
            WordDocument document = new WordDocument();
            //Adding a new section to the document
            WSection section = document.AddSection() as WSection;

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

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

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

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

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

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

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

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

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

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

            document.Save(stream, FormatType.Docx);
            //Closes the Word document
            document.Close();
            stream.Position = 0;

            return(stream);
        }
Esempio n. 20
0
        public ActionResult Styles(string Group1, string Group2)
        {
            if (Group1 == null)
            {
                return(View());
            }
            WordDocument document = null;

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

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

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

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

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

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

                #region TOA Heading Style
                //TOA Heading
                para = section.AddParagraph() as WParagraph;
                para.ParagraphFormat.AfterSpacing = 10;
                para.AppendText("\nThis para is written with style TOA Heading").CharacterFormat.UnderlineStyle = UnderlineStyle.Double;
                para = section.AddParagraph() as WParagraph;
                para.ApplyStyle(BuiltinStyle.ToaHeading);
                para.AppendText("Google Chrome\n");
                para.AppendText("Mozilla Firefox\n");
                para.AppendText("Internet Explorer");
                #endregion
                section.BreakCode = SectionBreakCode.NewColumn;

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

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

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

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

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

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

                #region Document Map Style
                //Docuemnt Map
                para = section.AddParagraph() as WParagraph;
                para.AppendText("This para is written with style DocumentMap\n").CharacterFormat.UnderlineStyle = UnderlineStyle.Double;
                para = section.AddParagraph() as WParagraph;
                para.ApplyStyle(BuiltinStyle.DocumentMap);
                para.AppendText("Google Chrome\n").CharacterFormat.TextColor   = Syncfusion.Drawing.Color.White;
                para.AppendText("Mozilla Firefox\n").CharacterFormat.TextColor = Syncfusion.Drawing.Color.White;
                para.AppendText("Internet Explorer").CharacterFormat.TextColor = Syncfusion.Drawing.Color.White;
                #endregion

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

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

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

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

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

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

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

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

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

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

            #region Custom Style
            else
            {
                document = new WordDocument();
                IWParagraphStyle style = null;
                // Adding a new section to the document.
                WSection section = document.AddSection() as WSection;
                //Set Margin of the section
                section.PageSetup.Margins.All = 72;
                IWParagraph par   = document.LastSection.AddParagraph();
                WTextRange  range = par.AppendText("Using CustomStyles") as WTextRange;
                range.CharacterFormat.TextBackgroundColor = Syncfusion.Drawing.Color.Red;
                range.CharacterFormat.TextColor           = Syncfusion.Drawing.Color.White;
                range.CharacterFormat.FontSize            = 18f;
                document.LastParagraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;  // Create Paragraph styles
                style = document.AddParagraphStyle("MyStyle_Normal");
                style.CharacterFormat.FontName            = "Bitstream Vera Serif";
                style.CharacterFormat.FontSize            = 10f;
                style.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify;
                style.CharacterFormat.TextColor           = Syncfusion.Drawing.Color.FromArgb(0, 21, 84);

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

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

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

                IWParagraph paragraph = null;
                for (int i = 0; i < document.Styles.Count; i++)
                {
                    //Skip to apply the document default styles and also paragraph style.
                    if (document.Styles[i].Name == "Normal" || document.Styles[i].Name == "Default Paragraph Font" ||
                        document.Styles[i].StyleType != StyleType.ParagraphStyle)
                    {
                        continue;
                    }
                    // Getting styles from Document.
                    style = (IWParagraphStyle)document.Styles[i];
                    // Adding a new paragraph
                    section.AddParagraph();
                    paragraph = section.AddParagraph();
                    // Applying styles to the current paragraph.
                    paragraph.ApplyStyle(style.Name);
                    // Writing Text with the current style and formatting.
                    paragraph.AppendText("Northwind Database with [" + style.Name + "] Style");
                    // Adding a new paragraph
                    section.AddParagraph();
                    paragraph = section.AddParagraph();
                    // Applying another style to the current paragraph.
                    paragraph.ApplyStyle("MyStyle_Normal");
                    // Writing text with current style.
                    paragraph.AppendText("The Northwind sample database (Northwind.mdb) is included with all versions of Access. It provides data you can experiment with and database objects that demonstrate features you might want to implement in your own databases. Using Northwind, you can become familiar with how a relational database is structured and how the database objects work together to help you enter, store, manipulate, and print your data.");
                }
            }
            #endregion Custom Style

            FormatType type        = FormatType.Docx;
            string     filename    = "Sample.docx";
            string     contenttype = "application/vnd.ms-word.document.12";
            #region Document SaveOption
            //Save as .doc format
            if (Group2 == "WordDoc")
            {
                type        = FormatType.Doc;
                filename    = "Sample.doc";
                contenttype = "application/msword";
            }
            //Save as .xml format
            else if (Group2 == "WordML")
            {
                type        = FormatType.WordML;
                filename    = "Sample.xml";
                contenttype = "application/msword";
            }
            #endregion Document SaveOption
            MemoryStream ms = new MemoryStream();
            document.Save(ms, type);
            document.Close();
            ms.Position = 0;
            return(File(ms, contenttype, filename));
        }
Esempio n. 21
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);
            }
        }
Esempio n. 22
0
        public ActionResult HelloWorld(string Group1)
        {
            if (Group1 == null)
            {
                return(View());
            }

            dataPath3 = ResolveApplicationDataPath("", "Images\\DocIO");
            // Creating a new document.
            WordDocument document = new WordDocument();
            //Adding a new section to the document.
            WSection section = document.AddSection() as WSection;

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

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

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

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

            WPicture picture = paragraph.AppendPicture(Image.FromFile(System.IO.Path.Combine(dataPath3, "AdventureCycle.jpg"))) as WPicture;

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

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

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

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

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

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

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

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

            //Appends paragraph.
            paragraph = table[0, 0].AddParagraph();
            paragraph.ParagraphFormat.AfterSpacing  = 0;
            paragraph.BreakCharacterFormat.FontSize = 12f;
            //Appends picture to the paragraph.
            picture = paragraph.AppendPicture(Image.FromFile(System.IO.Path.Combine(dataPath3, "Mountain-200.jpg"))) as WPicture;
            picture.TextWrappingStyle  = TextWrappingStyle.TopAndBottom;
            picture.VerticalOrigin     = VerticalOrigin.Paragraph;
            picture.VerticalPosition   = 4.5f;
            picture.HorizontalOrigin   = HorizontalOrigin.Column;
            picture.HorizontalPosition = -2.15f;
            picture.WidthScale         = 79;
            picture.HeightScale        = 79;

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

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

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

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

            //Appends paragraph.
            paragraph = table[1, 1].AddParagraph();
            paragraph.ApplyStyle("Heading 1");
            paragraph.ParagraphFormat.LineSpacing = 12f;
            //Appends picture to the paragraph.
            picture = paragraph.AppendPicture(Image.FromFile(System.IO.Path.Combine(dataPath3, "Mountain-300.jpg"))) as WPicture;
            picture.TextWrappingStyle  = TextWrappingStyle.TopAndBottom;
            picture.VerticalOrigin     = VerticalOrigin.Paragraph;
            picture.VerticalPosition   = 8.2f;
            picture.HorizontalOrigin   = HorizontalOrigin.Column;
            picture.HorizontalPosition = -14.95f;
            picture.WidthScale         = 75;
            picture.HeightScale        = 75;

            //Appends paragraph.
            paragraph = table[2, 0].AddParagraph();
            paragraph.ApplyStyle("Heading 1");
            paragraph.ParagraphFormat.LineSpacing = 12f;
            //Appends picture to the paragraph.
            picture = paragraph.AppendPicture(Image.FromFile(System.IO.Path.Combine(dataPath3, "Road-550-W.jpg"))) as WPicture;
            picture.TextWrappingStyle  = TextWrappingStyle.TopAndBottom;
            picture.VerticalOrigin     = VerticalOrigin.Paragraph;
            picture.VerticalPosition   = 3.75f;
            picture.HorizontalOrigin   = HorizontalOrigin.Column;
            picture.HorizontalPosition = -5f;
            picture.WidthScale         = 92;
            picture.HeightScale        = 92;

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

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

                return(pdfDoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save));
            }
            #endregion saveOption

            return(View());
        }
Esempio n. 23
0
        //Exporting data to word
        public void ExportToWord()
        {
            //A new document is created.
            WordDocument document = new WordDocument();

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

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

            //Set Margin of the section
            section.PageSetup.Margins.All = 72;

            //Set page size of the section
            section.PageSetup.PageSize = new SizeF(800, 792);

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

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

            WCharacterFormat charFormat = new WCharacterFormat(document);

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

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

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

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

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

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

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

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

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

                //Message box confirmation to view the created document.
                if (MessageBox.Show("Do you want to view the MS Word document?", "Document has been created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                {
                    //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
                    System.Diagnostics.Process.Start("Sample.doc");
                    //Exit
                    this.Close();
                }
            }
            //Save as word 2007 format
            else if (rdbWord2007.IsChecked.Value)
            {
                //Saving the document as .docx
                document.Save("Sample.docx", FormatType.Word2007);
                //Message box confirmation to view the created document.
                if (MessageBox.Show("Do you want to view the MS Word document?", "Document has been created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                {
                    try
                    {
                        //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
                        System.Diagnostics.Process.Start("Sample.docx");
                        //Exit
                        this.Close();
                    }
                    catch (Win32Exception ex)
                    {
                        MessageBox.Show("Word 2007 is not installed in this system");
                        Console.WriteLine(ex.ToString());
                    }
                }
            }
            //Save as word 2010  format
            else if (rdbWord2010.IsChecked.Value)
            {
                //Saving the document as .docx
                document.Save("Sample.docx", FormatType.Word2010);
                //Message box confirmation to view the created document.
                if (MessageBox.Show("Do you want to view the MS Word document?", "Document has been created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                {
                    try
                    {
                        //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
                        System.Diagnostics.Process.Start("Sample.docx");
                        //Exit
                        this.Close();
                    }
                    catch (Win32Exception ex)
                    {
                        MessageBox.Show("Word 2010 is not installed in this system");
                        Console.WriteLine(ex.ToString());
                    }
                }
            }
            //Save as word 2013  format
            else if (rdbWord2013.IsChecked.Value)
            {
                //Saving the document as .docx
                document.Save("Sample.docx", FormatType.Word2013);
                //Message box confirmation to view the created document.
                if (MessageBox.Show("Do you want to view the MS Word document?", "Document has been created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                {
                    try
                    {
                        //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
                        System.Diagnostics.Process.Start("Sample.docx");
                        //Exit
                        this.Close();
                    }
                    catch (Win32Exception ex)
                    {
                        MessageBox.Show("Word 2013 is not installed in this system");
                        Console.WriteLine(ex.ToString());
                    }
                }
            }
            else
            {
                // Exit
                this.Close();
            }
        }
        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);
        }