Пример #1
0
        private void Fill(DocX doc)
        {
            doc
            .InsertParagraph()
            .Heading(HeadingType.Heading1)
            .Append("Laboratoire des assistants - Rapport des comptes");

            doc.InsertSection();
            doc
            .InsertParagraph()
            .Heading(HeadingType.Heading2)
            .Append("Information générales");
            FillGlobalInfos(doc);

            doc.InsertSection();
            doc
            .InsertParagraph()
            .Heading(HeadingType.Heading2)
            .Append(string.Format("Dettes des assistants (au {0})", to.ToString("dd-MM-yyyy")));
            FillUsersInfos(doc);

            doc.InsertSection();
            doc
            .InsertParagraph()
            .Heading(HeadingType.Heading2)
            .Append("Accomptes");
            FillAccounts(doc);

            doc.InsertSection();
            doc
            .InsertParagraph()
            .Heading(HeadingType.Heading2)
            .Append("Détails d'achats");
            FillPurchases(doc);
        }
Пример #2
0
        private void GenerateDocumentContent(gpTemplateNodeWebDO[] gptns, DocX document, long parentId, int level)
        {
            foreach (var item in gptns.Where(x => x.gtnPid == parentId).OrderBy(x => x.sort))
            {
                //段落
                var p = document.InsertParagraph();

                p.Append(item.gtnName)
                .Font(new Xceed.Words.NET.Font("Arial"))
                .FontSize(25 / (level + (level - 1) * 0.1))
                .Color(Color.Black)
                .Bold()
                .KeepWithNextParagraph();

                if (level == 1)
                {
                    p.Heading(HeadingType.Heading1);
                    document.InsertSection();
                }
                else if (level == 2)
                {
                    p.Heading(HeadingType.Heading2);
                }
                else if (level == 3)
                {
                    p.Heading(HeadingType.Heading3);
                }

                this.GenerateDocumentContent(gptns, document, item.gtnId, level + 1);
            }
        }
Пример #3
0
        private void Fill(DocX doc)
        {
            doc.InsertParagraph().Heading(HeadingType.Heading1).Append(user.login);

            doc.InsertSection();
            doc.InsertParagraph().Heading(HeadingType.Heading2).Append("Information generales");
            FillUserInfos(doc);

            doc.InsertSection();
            doc.InsertParagraph().Heading(HeadingType.Heading2).Append("Accomptes");
            FillAccounts(doc);

            doc.InsertSection();
            doc.InsertParagraph().Heading(HeadingType.Heading2).Append("Achats");
            FillPurchases(doc);
        }
Пример #4
0
        private static void ExportObjectInDoc(FHXObject obj, DocX doc, int level = 0)
        {
            doc.InsertSection();
            Paragraph p = doc.InsertParagraph(obj.Name).Heading((HeadingType)level).Bold().UnderlineStyle(UnderlineStyle.singleLine);

            p.Alignment = Alignment.left;

            if (obj.Parameters.Count > 0)
            {
                Table t = doc.InsertTable(obj.Parameters.Count, 2);

                int i = 0;
                foreach (FHXParameter par in obj.Parameters)
                {
                    ExportParameterInDoc(par, t, i);
                    i++;
                }
            }


            foreach (FHXObject child in obj.Children)
            {
                ExportObjectInDoc(child, doc, level + 1);
            }
        }
Пример #5
0
        /// <summary>
        /// Create a document and insert Sections into it.
        /// </summary>
        public static void InsertSections()
        {
            Console.WriteLine("\tInsertSections()");

            // Create a document.
            using (DocX document = DocX.Create(SectionSample.SectionSampleOutputDirectory + @"InsertSections.docx"))
            {
                document.PageLayout.Orientation = Orientation.Portrait;
                // Add a title
                document.InsertParagraph("Inserting sections").FontSize(15d).SpacingAfter(50d).Alignment = Alignment.center;

                // Add 2 paragraphs
                document.InsertParagraph("This is the first paragraph.");
                document.InsertParagraph("This is the second paragraph.");
                // Add a paragraph and a section break.
                document.InsertSection();
                // Add a new paragraph
                document.InsertParagraph("This is the third paragraph, in a new section.");
                // Add a paragraph and a page break.
                document.InsertSectionPageBreak();
                document.PageLayout.Orientation = Orientation.Landscape;
                document.InsertParagraph("This is the fourth paragraph, in a new section.");
                document.InsertSectionPageBreak();
                //    document.PageLayout.Orientation = Orientation.Portrait;
                var sections = document.GetSections();

                // Add a paragraph to display the result of sections.
                var p = document.InsertParagraph("This document contains ").Append(sections.Count.ToString()).Append(" Sections.\n");
                p.SpacingBefore(40d);
                // Display the paragraphs count per section from this document.
                for (int i = 0; i < sections.Count; ++i)
                {
                    var section            = sections[i];
                    var paragraphs         = section.SectionParagraphs;
                    var nonEmptyParagraphs = paragraphs.Where(x => !string.IsNullOrEmpty(x.Text));
                    p.Append("Section ").Append((i + 1).ToString()).Append(" has ").Append(nonEmptyParagraphs.Count().ToString()).Append(" non-empty paragraphs.\n");
                }

                document.Save();
                Console.WriteLine("\tCreated: InsertSections.docx\n");
            }
        }
Пример #6
0
    public void CreateNewDocByDocx(string resumsPath, string ResumContent)
    {
        DocxToText1 docTT = new DocxToText1();

        try
        {
            string fileName = resumsPath;
            using (DocX document = DocX.Create(fileName))
            {
                Novacode.Paragraph remainingpara = document.InsertParagraph();
                remainingpara.Append(ResumContent);
                Novacode.Formatting para_formatting = new Novacode.Formatting();
                para_formatting.Bold = false;
                para_formatting.Size = 9;
                document.InsertSection();
                document.SaveAs(fileName);
            }
        }
        catch (Exception ex)
        {
        }
    }
Пример #7
0
        private static void HeadersAndFooters()
        {
            Console.WriteLine("\tHeadersAndFooters()");

            // Create a new document.
            using (DocX document = DocX.Create(@"docs\HeadersAndFooters.docx"))
            {
                // Add Headers and Footers to this document.
                document.AddHeaders();
                document.AddFooters();

                // Force the first page to have a different Header and Footer.
                document.DifferentFirstPage = true;

                // Force odd & even pages to have different Headers and Footers.
                document.DifferentOddAndEvenPages = true;

                // Get the first, odd and even Headers for this document.
                Header header_first = document.Headers.first;
                Header header_odd   = document.Headers.odd;
                Header header_even  = document.Headers.even;

                // Get the first, odd and even Footer for this document.
                Footer footer_first = document.Footers.first;
                Footer footer_odd   = document.Footers.odd;
                Footer footer_even  = document.Footers.even;

                // Insert a Paragraph into the first Header.
                Paragraph p0 = header_first.InsertParagraph();
                p0.Append("Hello First Header.").Bold();

                // Insert a Paragraph into the odd Header.
                Paragraph p1 = header_odd.InsertParagraph();
                p1.Append("Hello Odd Header.").Bold();

                // Insert a Paragraph into the even Header.
                Paragraph p2 = header_even.InsertParagraph();
                p2.Append("Hello Even Header.").Bold();

                // Insert a Paragraph into the first Footer.
                Paragraph p3 = footer_first.InsertParagraph();
                p3.Append("Hello First Footer.").Bold();

                // Insert a Paragraph into the odd Footer.
                Paragraph p4 = footer_odd.InsertParagraph();
                p4.Append("Hello Odd Footer.").Bold();

                // Insert a Paragraph into the even Header.
                Paragraph p5 = footer_even.InsertParagraph();
                p5.Append("Hello Even Footer.").Bold();

                // Insert a Paragraph into the document.
                Paragraph p6 = document.InsertParagraph();
                p6.AppendLine("Hello First page.");

                // Create a second page to show that the first page has its own header and footer.
                p6.InsertPageBreakAfterSelf();

                // Insert a Paragraph after the page break.
                Paragraph p7 = document.InsertParagraph();
                p7.AppendLine("Hello Second page.");

                // Create a third page to show that even and odd pages have different headers and footers.
                p7.InsertPageBreakAfterSelf();

                // Insert a Paragraph after the page break.
                Paragraph p8 = document.InsertParagraph();
                p8.AppendLine("Hello Third page.");

                //Insert a next page break, which is a section break combined with a page break
                document.InsertSectionPageBreak();

                //Insert a paragraph after the "Next" page break
                Paragraph p9 = document.InsertParagraph();
                p9.Append("Next page section break.");

                //Insert a continuous section break
                document.InsertSection();

                //Create a paragraph in the new section
                var p10 = document.InsertParagraph();
                p10.Append("Continuous section paragraph.");

                // Save all changes to this document.
                document.Save();

                Console.WriteLine("\tCreated: docs\\HeadersAndFooters.docx\n");
            }// Release this document from memory.
        }
Пример #8
0
        protected void Unnamed_Click(object sender, EventArgs e)
        {
            const int    yeH = 266;
            const int    yeW = 472;
            const double eventPhotoScalePercentage = 0.7;   // /100

            using (var _db = new Kronika106.Models.Kronika106DBContext())
            {
                contentList = (from EventComments comment in _db.Forum
                               //(comment.EventId.ToLower() == trueEvetId && ((forumType == ForumType.Event && comment.IsEvent) || (forumType == ForumType.EventPhotoGallery && comment.IsPhoto && comment.ThumbPath.Contains(photoName))))
                               orderby comment.ID ascending
                               select new PageContent {
                    ID = comment.ID, CreatedUTC = comment.CreatedUTC, EventId = comment.EventId, RootID = comment.RootID, ThumbPath = comment.ThumbPath, ScoutNickName = comment.ApplicationUser.ScoutNickName, NickName = comment.ApplicationUser.NickName, Comment = comment.Comment, IsVideo = comment.IsVideo, IsEvent = comment.IsEvent, IsPhoto = comment.IsPhoto, UserID = comment.ApplicationUser.Id, UserName = comment.ApplicationUser.UserName                                    /*, VideoPosition= comment.VideoPosition */
                }).ToList();
            }
            if (contentList == null || contentList.Count == 0)
            {
                return;
            }

            string now = DateTime.Now.ToString("yyyyMMddHHmmss");

            string pthAppData   = Server.MapPath("..\\App_Data");
            string pthAllPhotos = Server.MapPath("..\\AllPhotos");

            DirectoryInfo dAllPhotosInfo = new DirectoryInfo(pthAllPhotos);
            List <string> lstDocFiles    = new List <string>();

            foreach (var dYear in dAllPhotosInfo.GetDirectories())
            {
                //rok
                //DateTime.Now.ToString("yyyyMMddHHmmss")
                string fileName     = $"kronika106_{dYear.Name}_{now}.docx";
                string fileFullPath = System.IO.Path.Combine(pthAppData, fileName);
                doc = DocX.Create(fileFullPath);
                doc.InsertSection();
                doc.InsertParagraph(dYear.Name, false, formatYear).Heading(HeadingType.Heading1).SpacingAfter(25d).Alignment = Alignment.center;
                var yImage      = doc.AddImage(Path.Combine(dYear.FullName, GlobalConstants.fnRokFotka));
                var pYImageYear = doc.InsertParagraph();
                pYImageYear.AppendPicture(yImage.CreatePicture(yeH, yeW)).SpacingAfter(20d).Alignment = Alignment.center;


                var yPopisPath = Path.Combine(dYear.FullName, GlobalConstants.fnRokPopis);
                if (System.IO.File.Exists(yPopisPath))
                {
                    doc.InsertParagraph(System.IO.File.ReadAllText(yPopisPath), false, formatText).SpacingAfter(20d).Alignment = Alignment.both;
                }
                doc.InsertSectionPageBreak();

                //toto rozdelit na zanostatny paragraf pre obrazok a pre text
                foreach (var dAkcia in dYear.GetDirectories())
                {
                    doc.InsertParagraph(dAkcia.Name, false, formatAkcia).Heading(HeadingType.Heading2).SpacingAfter(15d).Alignment = Alignment.center;
                    string eventImagePath = Path.Combine(dAkcia.FullName, GlobalConstants.fnAkciaFotka);
                    if (File.Exists(eventImagePath))
                    {
                        var pImageEvent = doc.InsertParagraph();
                        var yImageEvent = doc.AddImage(eventImagePath);
                        pImageEvent.AppendPicture(yImageEvent.CreatePicture(yeH, yeW)).SpacingAfter(15d).Alignment = Alignment.center;
                    }

                    string eventDescriptionPath = Path.Combine(dAkcia.FullName, GlobalConstants.fnAkciaPopis);
                    if (File.Exists(eventDescriptionPath))
                    {
                        doc.InsertParagraph(File.ReadAllText(eventDescriptionPath), false, formatText).SpacingAfter(15d).Alignment = Alignment.both;
                    }

                    string dbEventId = dAkcia.FullName.Replace(pthAllPhotos, "").TrimStart('\\').Replace("\\", "/");
                    commentTree(dbEventId, null, ref doc, ForumType.Event);

                    //precitat fotky:
                    foreach (var ePhoto in dAkcia.GetFiles("*.jpg"))
                    {
                        //vynechame uvodny obrazok
                        if (ePhoto.Name.Equals(GlobalConstants.fnAkciaFotka))
                        {
                            continue;
                        }
                        var pPhotoEvent = doc.InsertParagraph();
                        var yPhotoEvent = doc.AddImage(ePhoto.FullName);
                        var pct         = yPhotoEvent.CreatePicture();
                        pct.Width  = (int)Math.Round(pct.Width * eventPhotoScalePercentage, 0);
                        pct.Height = (int)Math.Round(pct.Height * eventPhotoScalePercentage, 0);

                        pPhotoEvent.AppendPicture(pct).SpacingAfter(5d).SpacingBefore(8d).Alignment = Alignment.center;

                        //tu najst podla nazvu akcie a fotky komnetare  a doplmnit -usera

                        commentTree(dbEventId, ePhoto.Name, ref doc, ForumType.EventPhotoGallery);
                    }
                    doc.InsertSectionPageBreak();
                }
                doc.Save();
                lstDocFiles.Add(fileFullPath);
            }
            string zipFileName = Path.Combine(pthAppData, $"Kronika2Word_{now}.zip");

            createZipFile(zipFileName, lstDocFiles);

            //mama zip zmazeme
            foreach (var file in lstDocFiles)
            {
                System.IO.File.Delete(file);
            }

            //upload na klienta
            FileInfo fInfo = new FileInfo(zipFileName);

            Response.Clear();
            Response.ClearHeaders();
            Response.ClearContent();
            Response.AddHeader("Content-Disposition", "attachment; filename=" + fInfo.Name);
            Response.AddHeader("Content-Length", fInfo.Length.ToString());
            Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
            Response.Flush();
            Response.TransmitFile(fInfo.FullName);
            Response.End();

            foreach (var file in lstDocFiles)
            {
                System.IO.File.Delete(file);
            }
        }