Пример #1
0
        private void _CreateDocx(string file, IEnumerable <BlogDemoorDetailData> details, string footerText, int skip = 0, OXmlDocOptions options = OXmlDocOptions.None)
        {
            //details = details.zAction(detail => Trace.WriteLine($"title \"{detail.Title}\" url \"{detail.SourceUrl}\""));
            _options = options;

            IEnumerable <HtmlPage> htmlPages = ToHtmlPages(details, skip);

            htmlPages = htmlPages.zAction(htmlPage => Trace.WriteLine($"page {htmlPage.Index} date {htmlPage.Date:dd-MM} title \"{htmlPage.Title}\" url \"{htmlPage.SourceUrl}\""));

            _exportDirectory = zPath.Combine(zPath.GetDirectoryName(file), "files");
            if ((options & OXmlDocOptions.ExportHtml) == OXmlDocOptions.ExportHtml)
            {
                htmlPages = htmlPages.zAction(htmlPage => ExportHtml(htmlPage));
            }

            //IEnumerable<OXmlElement> oxmlElements = ToOXmlElements(htmlPages, footerText);
            //IEnumerable<IEnumerable<OXmlElement>> pages = htmlPages.Select(page => PageToOXmlElements(page, (options & OXmlDocOptions.ExportOXmlPage) == OXmlDocOptions.ExportOXmlPage));
            //IEnumerable<OXmlPage> pages = htmlPages.Select(htmlPage => new OXmlPage { HtmlPage = htmlPage, OXmlElements = PageToOXmlElements(htmlPage, (options & OXmlDocOptions.ExportOXmlPage) == OXmlDocOptions.ExportOXmlPage) });
            //IEnumerable<OXmlElement> oxmlElements = ToOXmlElements(pages, footerText);
            IEnumerable <OXmlElement> oxmlElements = ToOXmlElements(htmlPages, footerText);

            if ((options & OXmlDocOptions.ExportOXmlDoc) == OXmlDocOptions.ExportOXmlDoc)
            {
                ExportOXml(zPath.GetFileNameWithoutExtension(file), oxmlElements);
            }

            OXmlDoc.Create(file, oxmlElements);
        }
Пример #2
0
        //public static void HtmlPagesToDocx(string file, string imageDirectory, IEnumerable<BlogDemoorDetailData> pages, string footerText = null)
        //{
        //    OXmlDoc.Create(file, HtmlPagesToOXmlElements(pages.Select(page => DetailDataToHtmlPage(page)), imageDirectory, footerText));
        //}

        public static void HtmlPagesToDocx(string file, string imageDirectory, IEnumerable <HtmlPage> pages, string footerText = null)
        {
            //HtmlToOXmlElements_v2 htmlToOXmlElements = HtmlToOXmlElements_v2.Create(BlogDemoor_v4.GetConfigElement().zXPathElement("HtmlToDocx"), imageDirectory);
            HtmlToOXmlElements_v2 htmlToOXmlElements = CreateHtmlToOXmlElements(BlogDemoor_v4.GetConfigElement(), imageDirectory);

            OXmlDoc.Create(file, HtmlPagesToOXmlElements(htmlToOXmlElements, pages, footerText));
        }
Пример #3
0
        public static void Test_BlogDemoorToDocx(string file, IEnumerable <int> detailIds, string footerText, string parameters = null)
        {
            BlogDemoor_v4 dataManager = WebData.CreateDataManager_v4(parameters);

            //IEnumerable<BlogDemoorDetailData> pages = ReadDetails(dataManager, detailIds);
            //pages = pages.zAction(page => Trace.WriteLine($"title \"{page.Title}\" url \"{page.SourceUrl}\""));
            //IEnumerable<HtmlPage> htmlPages = pages.Select(page => DetailDataToHtmlPage(page));
            //string imageDirectory = dataManager.DetailDataManager.WebLoadImageManager.WebImageCacheManager.UrlCache.CacheDirectory;
            //HtmlToOXmlElements_v2 htmlToOXmlElements = HtmlToOXmlElements_v2.Create(dataManager.ConfigElement.zXPathElement("HtmlToDocx"), imageDirectory);
            OXmlDoc.Create(file, HtmlPagesToOXmlElements(CreateHtmlToOXmlElements(dataManager), GetHtmlPages(dataManager, detailIds), footerText));
        }
Пример #4
0
        //public static void Test_HtmlToDocx_v1(string file, string imageDirectory, string oxmlHeaderFile = null, string title = null)
        //{
        //    IEnumerable<OXmlElement> elements = new OXmlElement[0];
        //    if (oxmlHeaderFile != null)
        //        elements = zmongo.BsonRead<OXmlElement>(oxmlHeaderFile);
        //    if (title != null)
        //        elements = elements.Union(GetTitle(title));
        //    OXmlDoc.Create(file + ".docx", elements.Union(HtmlToOXmlElements_v2.ToOXmlXElements(HtmlDocReader.ReadFile(file), imageDirectory)));
        //}

        //public static void Test_HtmlPagesToDocx(string file, string imageDirectory, string title, string date, string footerText = null)
        //{
        //    HtmlPage htmlPage = new HtmlPage { Title = title, Date = date, HtmlNodes = HtmlDocReader.ReadFile(file) };
        //    HtmlPagesToDocx(file + ".docx", imageDirectory, new HtmlPage[] { htmlPage, htmlPage, htmlPage }, footerText);
        //}

        public static void Test_BlogDemoorToDocx(string file, string footerText, int limit = 0, int skip = 0, string parameters = null)
        {
            BlogDemoor_v4 dataManager = WebData.CreateDataManager_v4(parameters);

            //IEnumerable<BlogDemoorDetailData> pages = dataManager.HeaderDetailManager.LoadDetails(startPage, maxPage, reloadHeaderPage, reloadDetail, loadImageFromWeb, loadImageToData, refreshImage, refreshDocumentStore);
            //pages = pages.Reverse();
            //if (limit != 0)
            //    pages = pages.Take(limit);
            //pages = pages.zAction(page => Trace.WriteLine($"title \"{page.Title}\" url \"{page.SourceUrl}\""));
            //IEnumerable<HtmlPage> htmlPages = pages.Select(page => DetailDataToHtmlPage(page));
            //string imageDirectory = dataManager.DetailDataManager.WebLoadImageManager.WebImageCacheManager.UrlCache.CacheDirectory;
            //HtmlToOXmlElements_v2 htmlToOXmlElements = HtmlToOXmlElements_v2.Create(dataManager.ConfigElement.zXPathElement("HtmlToDocx"), imageDirectory);
            OXmlDoc.Create(file, HtmlPagesToOXmlElements(CreateHtmlToOXmlElements(dataManager), GetHtmlPages(dataManager, limit, skip), footerText));
        }
Пример #5
0
        public static void Test_HtmlToDocx(string file, string imageDirectory, string title = null, string footerText = null)
        {
            IEnumerable <OXmlElement> elements =
                GetDocDefaults().Union(
                    GetStyles()).Union(
                    GetDocSection()).Union(
                    GetHeaderFooter(footerText));

            if (title != null)
            {
                elements = elements.Union(GetTitle(title));
            }
            //HtmlToOXmlElements_v2 htmlToOXmlElements = HtmlToOXmlElements_v2.Create(BlogDemoor_v4.GetConfigElement().zXPathElement("HtmlToDocx"), imageDirectory);
            HtmlToOXmlElements_v2 htmlToOXmlElements = CreateHtmlToOXmlElements(BlogDemoor_v4.GetConfigElement(), imageDirectory);

            //elements = elements.Union(HtmlToOXmlElements_v2.ToOXmlXElements(HtmlDocReader.ReadFile(file), imageDirectory));
            elements = elements.Union(htmlToOXmlElements.ToOXmlXElements(HtmlDocReader.ReadFile(file)));
            OXmlDoc.Create(file + ".docx", elements);
        }
Пример #6
0
 public static void OXmlToDocx(string file)
 {
     OXmlDoc.Create(file + ".docx", zMongo.BsonRead <OXmlElement>(file));
 }