コード例 #1
0
ファイル: Nosi.cs プロジェクト: ArihantBapna/WordDocMaker
        public static async Task GetSubNosi(string s)
        {
            IHtmlDocument doc = await Scraper.ScrapeWebsite(s, -1);

            IEnumerable <IElement> header  = doc.All.Where(x => x.ClassName == "entry-title");
            IEnumerable <IElement> content = doc.All.Where(x => x.ClassName == "entry-content");

            IElement h    = header.First();
            string   head = h.TextContent;

            head = head.Replace("\u00A0", " ");

            IElement c      = content.First();
            IElement gChild = c.FirstElementChild;
            var      cChild = gChild.Children;

            IElement src     = cChild.First();
            string   hrefSrc = src.GetAttribute("href");
            string   source  = src.TextContent;

            string completeContent = gChild.TextContent;

            completeContent = completeContent.Replace("\u00A0", " ");


            IEnumerable <IElement> dateList = doc.All.Where(x => x.ClassName == "entry-date");
            IElement date = dateList.First();

            string   dnt = date.TextContent;
            DateTime dt  = Convert.ToDateTime(date.GetAttribute("datetime"));

            Nosi obj = new Nosi();

            obj.Head       = head;
            obj.Content    = completeContent;
            obj.Publish    = dt;
            obj.Date       = dnt;
            obj.SourceLink = hrefSrc;
            obj.Source     = source;
            Console.WriteLine(completeContent);
            Scraper.NosiList.Add(obj);
        }
コード例 #2
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);
        }