示例#1
0
        public void AddSectionHeaderFooter()
        {
            using (var doc = new DocX())
            {
                doc.Create();

                doc.AddHeaders();
                doc.AddFooters();

                doc.DefaultHeader.AddParagraph().Append("Header 1");
                doc.DefaultFooter.AddParagraph().Append("Footer 1");

                doc.InsertSectionPageBreak();

                doc.AddHeaders();
                doc.AddFooters();

                doc.DefaultHeader.AddParagraph().Append("Header 2");
                doc.DefaultFooter.AddParagraph().Append("Footer 2");

                doc.InsertSectionPageBreak();

                doc.AddHeaders();
                doc.AddFooters();

                doc.DefaultHeader.AddParagraph().Append("Header 3");
                doc.DefaultFooter.AddParagraph().Append("Footer 3");

                Validate(doc);

                doc.Close();
            }
        }
示例#2
0
        /// <summary>
        /// Ajoutez trois types différents d'en-têtes et de pieds de page à un document.
        /// </summary>
        public static void HeadersFooters(DocX document, string title)
        {
            // Insert a Paragraph in the first page of the document.
            var p1 = document.InsertParagraph("This is the ").Append("first").Bold().Append(" page Content.");

            p1.SpacingBefore(70d);
            p1.InsertPageBreakAfterSelf();

            // Insert a Paragraph in the second page of the document.
            var p2 = document.InsertParagraph("This is the ").Append("second").Bold().Append(" page Content.");

            p2.InsertPageBreakAfterSelf();

            // Insert a Paragraph in the third page of the document.
            var p3 = document.InsertParagraph("This is the ").Append("third").Bold().Append(" page Content.");

            p3.InsertPageBreakAfterSelf();

            // Insert a Paragraph in the third page of the document.
            var p4 = document.InsertParagraph("This is the ").Append("fourth").Bold().Append(" page Content.");

            // Add Headers and Footers to the 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;

            // Insert a Paragraph into the first Header.
            document.Headers.First.InsertParagraph("This is the ").Append("first").Bold().Append(" page header");

            // Insert a Paragraph into the first Footer.
            document.Footers.First.InsertParagraph("This is the ").Append("first").Bold().Append(" page footer");

            // Insert a Paragraph into the even Header.
            document.Headers.Even.InsertParagraph("This is an ").Append("even").Bold().Append(" page header");

            // Insert a Paragraph into the even Footer.
            document.Footers.Even.InsertParagraph("This is an ").Append("even").Bold().Append(" page footer");

            // Insert a Paragraph into the odd Header.
            document.Headers.Odd.InsertParagraph("This is an ").Append("odd").Bold().Append(" page header");

            // Insert a Paragraph into the odd Footer.
            document.Footers.Odd.InsertParagraph("This is an ").Append("odd").Bold().Append(" page footer");

            // Add the page number in the first Footer.
            document.Footers.First.InsertParagraph("Page #").AppendPageNumber(PageNumberFormat.normal);

            // Add the page number in the even Footers.
            document.Footers.Even.InsertParagraph("Page #").AppendPageNumber(PageNumberFormat.normal);

            // Add the page number in the odd Footers.
            document.Footers.Odd.InsertParagraph("Page #").AppendPageNumber(PageNumberFormat.normal);

            document.Save();
        }
示例#3
0
        public void AddHeaderAndFooterLandscape()
        {
            using (var doc = new DocX())
            {
                doc.Create();

                doc.Orientation = PageOrientation.Landscape;

                doc.AddHeaders();
                doc.AddFooters();

                doc.DefaultHeader
                .AddParagraph()
                .SetAlignment(Align.Right)
                .Append(LoremIpsum);

                doc.DefaultFooter
                .AddParagraph()
                .SetAlignment(Align.Center)
                .Append(LoremIpsum);

                Validate(doc);

                doc.Close();
            }
        }
示例#4
0
        public void InHeader()
        {
            using (var doc = new DocX())
            {
                doc.Create();

                doc.AddHeaders();

                var width  = 0d;
                var height = 0d;

                using (System.Drawing.Image img = System.Drawing.Image.FromStream(GetEmbeddedResourceStream("Peggys_Cove_Nova_Scotia_01.jpg"), useEmbeddedColorManagement: false, validateImageData: false))
                {
                    width  = img.Width;
                    height = img.Height;
                }

                double ratio = height / width;

                var inchWidth  = 2;
                var inchHeight = inchWidth * ratio;

                var drawing = doc.DefaultHeader.AddImage(GetEmbeddedResourceStream("Peggys_Cove_Nova_Scotia_01.jpg"), "image/jpg", Units.InchToEMU(inchWidth), Units.InchToEMU(inchHeight));
                doc.DefaultHeader.AddParagraph().Append(drawing);

                Validate(doc);

                doc.Close();
            }
        }
示例#5
0
        public void TableInHeader()
        {
            using (var doc = new DocX())
            {
                doc.Create();

                doc.AddHeaders();

                var table = doc.DefaultHeader.AddTable(3);

                for (int i = 0; i < 3; i++)
                {
                    var row = table.AddRow();
                    row.SetBorders(Units.HalfPt, BorderValue.Single);

                    if (i == 0)
                    {
                        row.SetShading(ShadingPattern.Clear, "E7E6E6");

                        row.HeaderRow = true;
                    }

                    for (int j = 0; j < 3; j++)
                    {
                        row.Cells[j].Paragraphs[0].Append($"Cell {(j + 1)}");
                    }
                }

                Validate(doc);

                doc.Close();
            }
        }
示例#6
0
 private static void agregarEncabezado(DocX document)
 {
     document.AddHeaders();
     document.Headers.Even.InsertParagraph().Bold().Font("Arial").FontSize(18).InsertText("este es el encabezado EVEN");
     document.Headers.Odd.InsertParagraph().Bold().Font("Arial").FontSize(18).InsertText("este es el encabezado ODD");
     document.Headers.First.InsertParagraph().Bold().Font("Arial").FontSize(18).InsertText("este es el encabezado FIRST");
 }
        public void Gerar(DocX document)
        {
            document.MarginTop    = 0F;
            document.MarginRight  = 0F;
            document.MarginBottom = 0F;
            document.MarginLeft   = 0F;
            document.AddHeaders();
            document.AddFooters();
            var headerDefault = document.Headers.odd;
            var footerDefault = document.Footers.odd;

            Table t = headerDefault.InsertTable(1, 2);

            Logo.Position = 0;
            Image   image   = document.AddImage(Logo);
            Picture picture = image.CreatePicture(100, 100);

            t.Alignment = Alignment.center;
            t.AutoFit   = AutoFit.Contents;
            //for (int i = 0; i <= (int)TableBorderType.InsideV; i++)
            //    t.SetBorder((TableBorderType)i, new Border());

            t.Rows[0].Cells[0].Paragraphs[0].InsertPicture(picture).Alignment = Alignment.center;
            ObterInformacoesCabecalho(t);
            t.Paragraphs.RemoveAll(x => x.Text != null || x.Text != "");
            t.InsertParagraphAfterSelf("").AppendLine();
            document.MarginRight = 15F;
            document.MarginLeft  = 30F;
        }
        public static void OutputDocx(FileStream docxFile)
        {
            ProgressInfo.ShowProgress("开始将处理结果输出至生成文件。", ProgressInfo.Stage.DocxOutputStarted);

            using (DocX outputDocx = DocX.Create(docxFile))
            {
                outputDocx.AddHeaders();
                outputDocx.DifferentFirstPage = true;

                outputDocx.Headers.Odd.InsertParagraph(NameAndVersion + "源代码");
                outputDocx.Sections[0].PageNumberStart = 0;
                outputDocx.Headers.Odd.PageNumbers     = true;
                outputDocx.Headers.Odd.PageNumberParagraph.Alignment = Alignment.right;

                Paragraph firstPage = outputDocx.InsertParagraph("\n" + NameAndVersion + "源代码");
                firstPage.FontSize(FirstPageFontSize);
                firstPage.Alignment = Alignment.center;
                firstPage.InsertPageBreakAfterSelf();

                StringReader codeLines = new StringReader(Parser.ParsedLines.ToString());

                do
                {
                    Paragraph codeLine = outputDocx.InsertParagraph(codeLines.ReadLine());
                    codeLine.FontSize(StandardFontSize);
                } while (codeLines.Peek() != -1);

                outputDocx.Save();
            }

            ProgressInfo.ShowProgress("已将处理结果输出至生成文件。", ProgressInfo.Stage.DocxOutputFinished);
        }
示例#9
0
        private void SetHeaderFooter(DocX docPage)
        {
            docPage.AddHeaders();
            docPage.AddFooters();

            //docPage.DifferentFirstPage = false;
            //docPage.DifferentOddAndEvenPages = false;
            StringBuilder sbLine = new StringBuilder();

            for (int i = 0; i < 82; i++)
            {
                sbLine.Append("_");
            }

            string line = sbLine.ToString();

            docPage.Headers.Even.InsertParagraph(line).Alignment = Alignment.center;
            docPage.Headers.Odd.InsertParagraph(line).Alignment  = Alignment.center;

            docPage.Footers.Even.InsertParagraph(line).Alignment = Alignment.center;
            docPage.Footers.Odd.InsertParagraph(line).Alignment  = Alignment.center;


            Model.Tb_tmp_main footInfo = Cache.LogicCache.TmpMain;
            string            linkWay1 = string.Format("监督电话:{0}", footInfo.LinkWay1);
            string            linkWay2 = string.Format("合同版本号:{0}", footInfo.LinkWay2);
            //string linkWay1 = "监督电话:15712307900";
            //string linkWay2 = "合同版本号:20180101";
            StringBuilder sbEmpty = new StringBuilder();

            for (int i = 0; i < 82 - linkWay1.Length - linkWay2.Length; i++)
            {
                sbEmpty.Append(" ");
            }

            docPage.Footers.Even.InsertParagraph().Append(linkWay1).Append(sbEmpty.ToString()).Append(linkWay2).Alignment = Alignment.center;
            docPage.Footers.Odd.InsertParagraph().Append(linkWay1).Append(sbEmpty.ToString()).Append(linkWay2).Alignment  = Alignment.center;

            Paragraph footerEven = docPage.Footers.Even.InsertParagraph("第");

            footerEven.AppendPageNumber(PageNumberFormat.normal);
            footerEven.Append("页,共");
            footerEven.AppendPageCount(PageNumberFormat.normal);
            footerEven.Append("页").Alignment = Alignment.center;


            Paragraph footerOdd = docPage.Footers.Odd.InsertParagraph("第");

            footerOdd.AppendPageNumber(PageNumberFormat.normal);
            footerOdd.Append("页,共");
            footerOdd.AppendPageCount(PageNumberFormat.normal);
            footerOdd.Append("页").Alignment = Alignment.center;
        }
        public string getReport(int candidateId, string candidateName, string templateName, IList <Question> questions)
        {
            string fileName = $"{Path.GetTempPath()}\\Candidate {candidateId}.docx";

            using (DocX document = DocX.Create(fileName))
            {
                document.SetDefaultFont(new Font("Arial"));

                // Generate the Headers/Footers for this document
                document.AddHeaders();
                document.AddFooters();
                // Insert a Paragraph in the Headers/Footers
                string  headerImagePath = "./Images/Header.jpg";
                Image   headerImage     = document.AddImage(headerImagePath);
                Picture headerPicture   = headerImage.CreatePicture();

                string  FooterImagePath = "./Images/Footer.jpg";
                Image   footerImage     = document.AddImage(FooterImagePath);
                Picture footerPicture   = footerImage.CreatePicture();

                document.Headers.Even.InsertParagraph(candidateName);
                document.Headers.Even.InsertParagraph(templateName);
                var p = document.Headers.Even.InsertParagraph();
                p.AppendPicture(headerPicture);
                p.Alignment = Alignment.right;
                document.Headers.Odd.InsertParagraph(candidateName);
                document.Headers.Odd.InsertParagraph(templateName);
                p = document.Headers.Odd.InsertParagraph();
                p.AppendPicture(headerPicture);
                p.Alignment = Alignment.right;

                p = document.Footers.Even.InsertParagraph();
                footerPicture.Width  = footerPicture.Width * .7f;
                footerPicture.Height = footerPicture.Height * .7f;
                p.AppendPicture(footerPicture);
                document.Footers.Even.InsertParagraph("1 university ave, 3rd floor, toronto, ontario  canada m5j 2p1,  416.599.0000  paralucent.com");
                p = document.Footers.Odd.InsertParagraph();
                p.AppendPicture(footerPicture);
                p.Alignment = Alignment.center;
                document.Footers.Odd.InsertParagraph("1 university ave, 3rd floor, toronto, ontario  canada m5j 2p1,  416.599.0000  paralucent.com");

                foreach (var q in questions)
                {
                    document.InsertParagraph($"{q.Index}. {q.Title}").Bold();
                    document.InsertParagraph(q.Content);
                    document.InsertParagraph();
                }

                // Save the document.
                document.Save();
            }
            return(fileName);
        }
示例#11
0
        /// <summary>
        /// Edits the header and footer of the Word file at the specified path
        /// </summary>
        /// <param name="filePath">Complete file path</param>
        public void UpdateHeaderFooter(string filePath, string headerText, string footerText)
        {
            DocX document = DocX.Load(filePath);

            document.AddHeaders();
            document.Headers.odd.InsertParagraph(headerText);

            document.AddFooters();
            document.Footers.odd.InsertParagraph(footerText);

            document.Save();
        }
示例#12
0
        public void AddHeader()
        {
            using (var doc = new DocX())
            {
                doc.Create();

                doc.AddHeaders();
                doc.DefaultHeader.AddParagraph().Append("Header Paragraph");

                Validate(doc);

                doc.Close();
            }
        }
示例#13
0
        public void HeaderAndFooterStyle()
        {
            using (var doc = new DocX())
            {
                doc.Create();
                doc.Styles.DocumentStyle("Normal").Size = 8;

                doc.AddHeaders();
                doc.AddFooters();

                doc.DefaultHeader.AddParagraph().Append("Header Paragraph");
                doc.DefaultFooter.AddParagraph().Append("Footer Paragraph");

                Validate(doc);

                doc.Close();
            }
        }
示例#14
0
        private void implementarHeader(DocX doc)
        {
            string headerDes   = "Identificación de los recursos valiosos";
            string headerFecha = DateTime.Now.ToShortDateString();

            // Aplicamos la descripción al Header
            doc.AddHeaders();
            Header    header_default = doc.Headers.odd;
            Paragraph p1             = header_default.InsertParagraph();

            p1.Append(headerDes);
            p1.Alignment = Alignment.right;

            // Aplicamos la fecha al Header
            Paragraph p2 = header_default.InsertParagraph();

            p2.Append(headerFecha);
            p2.Alignment = Alignment.right;
        }
        private void CreateHeaderAndFooter(DocX doc)
        {
            var    pngPath     = Path.Combine(_hostingEnvironment.WebRootPath, "nccsoftlogo.png");
            string titleHeader = "NCCPLUS VIET NAM JSC";

            doc.AddHeaders();
            Header h = doc.Headers.Odd;

            Xceed.Document.NET.Image   image = doc.AddImage(pngPath);
            Xceed.Document.NET.Picture p     = image.CreatePicture(29, 72);

            h.InsertParagraph(titleHeader).Alignment       = Alignment.left;
            h.InsertParagraph().AppendPicture(p).Alignment = Alignment.right;
            h.InsertParagraph();

            doc.AddFooters();
            Footer footer = doc.Footers.Odd;

            footer.InsertParagraph().Append("Page ").AppendPageNumber(PageNumberFormat.normal).Append(" of  ").AppendPageCount(PageNumberFormat.normal).Alignment = Alignment.center;
        }
示例#16
0
        public void AddHeaders()
        {
            using (var doc = new DocX())
            {
                doc.Create();

                doc.AddHeaders();
                doc.DifferentFirstPage = true;
                doc.EvenAndOddHeaders  = true;

                doc.DefaultHeader
                .AddParagraph()
                .Append("Default (Odd) Header");

                doc.EvenHeader
                .AddParagraph()
                .Append("Even Header");

                doc.FirstHeader
                .AddParagraph()
                .Append("First Header");

                doc.AddParagraph().Append("Page 1");

                doc.InsertPageBreak();

                doc.AddParagraph().Append("Page 2");

                doc.InsertPageBreak();

                doc.AddParagraph().Append("Page 3");

                doc.InsertPageBreak();

                doc.AddParagraph().Append("Page 4");

                Validate(doc);

                doc.Close();
            }
        }
 internal void addHeaders(DocX document, HeaderFooterOption headerOption, bool firstOption, bool oddEvenOption)
 {
     document.AddHeaders();//会将以前有的页眉给删掉
     if (firstOption)
     {
         document.DifferentFirstPage = true;
         this.headerFooterSetting.firstHeader(document, headerOption);
     }
     else
     {
         document.DifferentFirstPage = false;
     }
     if (oddEvenOption)
     {
         document.DifferentOddAndEvenPages = true;
         this.headerFooterSetting.oddHeader(document, headerOption);
         this.headerFooterSetting.evenHeader(document, headerOption);
     }
     else
     {
         this.headerFooterSetting.pageHeader(document, headerOption);
     }
 }
示例#18
0
        public IActionResult exportrequest2(long id, string userId)
        {
            //var exportexcutiveorderdata = _context.ExecutiveOrders
            //    .Where(m => m.Id == id)
            //   .FirstOrDefault();
            System.Console.WriteLine("1 : " + userId + " : " + id);

            var exportexcutiveorderdata = _context.RequestOrderAnswers
                                          .Include(m => m.RequestOrder)
                                          .Include(m => m.RequestOrderAnswerDetails)
                                          //.Where(m => m.RequestOrder.Draft == 0)
                                          .Where(m => m.Id == id)
                                          .Where(m => m.UserID == userId)
                                          .OrderByDescending(x => x.Id)
                                          .FirstOrDefault();

            var detail = _context.RequestOrderAnswerDetails
                         .Where(m => m.RequestOrderAnswerId == exportexcutiveorderdata.Id)
                         .FirstOrDefault();

            System.Console.WriteLine("1.2 : " + exportexcutiveorderdata.RequestOrder.UserID);
            //ผู้สั่งการ
            var users = _context.Users
                        .Where(m => m.Id == exportexcutiveorderdata.RequestOrder.UserID)
                        .FirstOrDefault();

            System.Console.WriteLine("1.3 : ");

            //ผู้รับข้อสั่งการ
            var username = _context.ApplicationUsers
                           .Where(m => m.Id == userId)
                           .Select(m => m.Name)
                           .FirstOrDefault();

            System.Console.WriteLine("export2 : " + id);

            if (!Directory.Exists(_environment.WebRootPath + "//reportrequestorder//"))         //ถ้ามีไฟล์อยู่แล้ว
            {
                Directory.CreateDirectory(_environment.WebRootPath + "//reportrequestorder//"); //สร้าง Folder reportexecutive ใน wwwroot
            }

            var filePath        = _environment.WebRootPath + "/reportrequestorder/"; // เก็บไฟล์ logo
            var filename        = DateTime.Now.ToString("dd MM yyyy") + ".docx";     // ชื่อไฟล์
            var createfile      = filePath + filename;                               //
            var myImageFullPath = filePath + "logo01.png";

            System.Console.WriteLine("3");
            System.Console.WriteLine("in create");
            using (DocX document = DocX.Create(createfile)) //สร้าง

            {
                document.SetDefaultFont(new Xceed.Document.NET.Font("ThSarabunNew"));
                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;

                // Insert a Paragraph into the first Header.
                document.Footers.First.InsertParagraph("วันที่ออกรายงาน: ").Append(DateTime.Now.ToString("dd MMMM yyyy HH:mm", new CultureInfo("th-TH"))).Append(" น.").Alignment = Alignment.right;
                // Insert a Paragraph into the even Header.
                document.Footers.Even.InsertParagraph("วันที่ออกรายงาน: ").Append(DateTime.Now.ToString("dd MMMM yyyy HH:mm", new CultureInfo("th-TH"))).Append(" น.").Alignment = Alignment.right;
                // Insert a Paragraph into the odd Header.
                document.Footers.Odd.InsertParagraph("วันที่ออกรายงาน: ").Append(DateTime.Now.ToString("dd MMMM yyyy HH:mm", new CultureInfo("th-TH"))).Append(" น.").Alignment = Alignment.right;

                // Add the page number in the first Footer.
                document.Headers.First.InsertParagraph("").AppendPageNumber(PageNumberFormat.normal).Alignment = Alignment.center;
                // Add the page number in the even Footers.
                document.Headers.Even.InsertParagraph("").AppendPageNumber(PageNumberFormat.normal).Alignment = Alignment.center;
                // Add the page number in the odd Footers.
                document.Headers.Odd.InsertParagraph("").AppendPageNumber(PageNumberFormat.normal).Alignment = Alignment.center;
                System.Console.WriteLine("5");


                document.InsertParagraph("รายงานคำร้องขอของหน่วยงานของรัฐ/หน่วยรับตรวจ (รายเรื่อง)").FontSize(16d)
                .SpacingBefore(15d)
                .SpacingAfter(15d)
                .Bold()     //ตัวหนา
                .Alignment = Alignment.center;

                var name = document.InsertParagraph(users.Name);
                name.Alignment = Alignment.center;
                name.SpacingAfter(10d);
                name.FontSize(14d); //ขนาดตัวอักษร
                name.Bold();
                System.Console.WriteLine("7");

                Thread.CurrentThread.CurrentCulture = new CultureInfo("th-TH");
                var Commanded_date = exportexcutiveorderdata.RequestOrder.Commanded_date.Value.ToString("dd MMMM yyyy");
                var CreatedAt      = exportexcutiveorderdata.RequestOrder.CreatedAt.Value.ToString("dd MMMM yyyy");
                var beaware_date   = exportexcutiveorderdata.beaware_date.Value.ToString("dd MMMM yyyy");


                document.InsertParagraph(" วันที่มีคำร้องขอ" + Commanded_date + "วันที่แจ้งคำร้องขอ" + CreatedAt).FontSize(14d)
                .SpacingBefore(15d)
                .SpacingAfter(15d)
                .Alignment = Alignment.center;

                document.InsertParagraph("เรื่อง :" + exportexcutiveorderdata.RequestOrder.Subject).FontSize(14d)
                .SpacingBefore(15d)
                .SpacingAfter(15d)
                .Alignment = Alignment.left;


                document.InsertParagraph("ผู้รับคำร้องขอ  :" + username).FontSize(14d)
                .SpacingBefore(15d)
                .SpacingAfter(15d)

                .Alignment = Alignment.left;

                document.InsertParagraph("รายละเอียด  :").FontSize(14d)
                .SpacingBefore(15d)
                .SpacingAfter(15d)
                .Alignment = Alignment.left;

                document.InsertParagraph("\n\n");

                document.InsertParagraph("การดำเนินการตามคำร้องขอ ").FontSize(16d)
                .SpacingBefore(15d)
                .SpacingAfter(15d)
                .Bold()    //ตัวหนา
                .Alignment = Alignment.center;

                document.InsertParagraph("วันที่มีคำร้องขอ  " + Commanded_date + "  วันที่รับทราบคำร้องขอ  " + beaware_date).FontSize(14d)
                .SpacingBefore(15d)
                .SpacingAfter(15d)
                .Alignment = Alignment.center;


                document.InsertParagraph("รายละเอียด :" + detail.Answerdetail).FontSize(14d)
                .SpacingBefore(15d)
                .SpacingAfter(15d)
                //.Bold() //ตัวหนา
                .Alignment = Alignment.left;

                document.InsertParagraph("ปัญหา/อุปสรรค :" + detail.AnswerProblem).FontSize(14d)
                .SpacingBefore(15d)
                .SpacingAfter(15d)
                //.Bold() //ตัวหนา
                .Alignment = Alignment.left;

                document.InsertParagraph("ข้อเสนอแนะ :" + detail.AnswerCounsel).FontSize(14d)
                .SpacingBefore(15d)
                .SpacingAfter(15d)
                //.Bold() //ตัวหนา
                .Alignment = Alignment.left;

                System.Console.WriteLine("11");
                document.Save(); //save เอกสาร
                Console.WriteLine("\tCreated: InsertHorizontalLine.docx\n");

                System.Console.WriteLine("12");
                return(Ok(new { data = filename }));
            }
        }
示例#19
0
        public IActionResult Getexport3([FromBody] UserViewModel body)
        {
            System.Console.WriteLine("id " + body.Id);
            var userId     = body.Id;
            var random     = RandomString(3);
            var Eexcutive3 = _context.RequestOrderAnswers
                             .Include(m => m.RequestOrder)
                             .Include(m => m.RequestOrderAnswerDetails)
                             .Where(m => m.RequestOrder.Draft == 0)
                             .Where(m => m.UserID == userId).ToList();

            var users = _context.Users
                        .Where(m => m.Id == userId)
                        .FirstOrDefault();

            var appDataPath = _environment.WebRootPath + "//reportrequest//";

            if (!Directory.Exists(appDataPath))
            {
                Directory.CreateDirectory(appDataPath);
            }
            System.Console.WriteLine("export_ : " + userId);
            //if (!Directory.Exists(_environment.WebRootPath + "//reportexecutive//")) //ถ้ามีไฟล์อยู่แล้ว
            //{
            //    Directory.CreateDirectory(_environment.WebRootPath + "//reportexecutive//"); //สร้าง Folder reportexecutive ใน wwwroot
            //}

            var filePath        = _environment.WebRootPath + "/reportrequest/";                                                            // เก็บไฟล์ logo
            var filename        = "ทะเบียนคำร้องขอจากหน่วยงานของรัฐหน่วยรับตรวจ" + DateTime.Now.ToString("dd MM yyyy") + random + ".docx"; // ชื่อไฟล์
            var createfile      = filePath + filename;                                                                                     //
            var myImageFullPath = filePath + "logo01.png";

            System.Console.WriteLine("3");
            System.Console.WriteLine("in create");
            using (DocX document = DocX.Create(createfile)) //สร้าง
            {
                document.SetDefaultFont(new Xceed.Document.NET.Font("ThSarabunNew"));
                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;

                // Insert a Paragraph into the first Header.
                document.Footers.First.InsertParagraph("วันที่ออกรายงาน: ").Append(DateTime.Now.ToString("dd MMMM yyyy HH:mm", new CultureInfo("th-TH"))).Append(" น.").Alignment = Alignment.right;
                // Insert a Paragraph into the even Header.
                document.Footers.Even.InsertParagraph("วันที่ออกรายงาน: ").Append(DateTime.Now.ToString("dd MMMM yyyy HH:mm", new CultureInfo("th-TH"))).Append(" น.").Alignment = Alignment.right;
                // Insert a Paragraph into the odd Header.
                document.Footers.Odd.InsertParagraph("วันที่ออกรายงาน: ").Append(DateTime.Now.ToString("dd MMMM yyyy HH:mm", new CultureInfo("th-TH"))).Append(" น.").Alignment = Alignment.right;

                // Add the page number in the first Footer.
                document.Headers.First.InsertParagraph("").AppendPageNumber(PageNumberFormat.normal).Alignment = Alignment.center;
                // Add the page number in the even Footers.
                document.Headers.Even.InsertParagraph("").AppendPageNumber(PageNumberFormat.normal).Alignment = Alignment.center;
                // Add the page number in the odd Footers.
                document.Headers.Odd.InsertParagraph("").AppendPageNumber(PageNumberFormat.normal).Alignment = Alignment.center;
                System.Console.WriteLine("5");

                // Add a title
                document.InsertParagraph("ทะเบียนคำร้องขอจากหน่วยงานของรัฐ/หน่วยรับตรวจ").FontSize(16d)
                .SpacingBefore(15d)
                .SpacingAfter(15d)
                .Bold()     //ตัวหนา
                .Alignment = Alignment.center;

                var name = document.InsertParagraph(users.Name);
                name.Alignment = Alignment.center;
                name.SpacingAfter(10d);
                name.FontSize(12d); //ขนาดตัวอักษร
                System.Console.WriteLine("7");

                Thread.CurrentThread.CurrentCulture = new CultureInfo("th-TH");
                var Date = DateTime.Now.ToString("dd MMMM yyyy");
                var year = document.InsertParagraph("วันที่เรียกรายงาน" + Date);
                year.Alignment = Alignment.center;
                year.SpacingAfter(10d);

                int dataCount = 0;
                dataCount  = Eexcutive3.Count; //เอาที่ select มาใช้
                dataCount += 1;
                System.Console.WriteLine("Data Count: " + dataCount);
                // Add a table in a document of 1 row and 3 columns.
                var columnWidths = new float[] { 300f, 300f, 300f, 300f, 300f, 300f, 300f };
                var t            = document.InsertTable(dataCount, columnWidths.Length);

                System.Console.WriteLine("8");

                // Set the table's column width and background
                t.SetWidths(columnWidths);
                t.AutoFit = AutoFit.Contents;

                var row = t.Rows.First();

                // Fill in the columns of the first row in the table.
                //for (int i = 0; i < row.Cells.Count; ++i)
                //{
                row.Cells[0].Paragraphs.First().Append("ลำดับที่");
                row.Cells[1].Paragraphs.First().Append("วัน/เดือน/ปี ที่มีคำร้องขอ");
                row.Cells[2].Paragraphs.First().Append("ผู้แจ้ง คำร้องขอ/ หน่วยงาน");
                row.Cells[3].Paragraphs.First().Append("ประเด็น/เรื่อง");
                row.Cells[4].Paragraphs.First().Append("สถานะเรื่อง");
                row.Cells[5].Paragraphs.First().Append("วัน/เดือน/ปี ที่รับทราบคำร้องขอ");
                row.Cells[6].Paragraphs.First().Append("การดำเนินการ");

                // Add rows in the table.
                int j = 0;
                for (int i = 0; i < Eexcutive3.Count; i++)
                {
                    j += 1;
                    //System.Console.WriteLine(i+=1);
                    var username = _context.ApplicationUsers
                                   .Where(m => m.Id == Eexcutive3[i].RequestOrder.UserID)
                                   .Select(m => m.Name)
                                   .FirstOrDefault();
                    System.Console.WriteLine("JJJJJ: " + j);

                    var Commanded_date = Eexcutive3[i].RequestOrder.Commanded_date.Value.ToString("dd MMMM yyyy");
                    var beaware_date   = Eexcutive3[i].beaware_date.Value.ToString("dd MMMM yyyy");

                    t.Rows[j].Cells[0].Paragraphs[0].Append(j.ToString());
                    t.Rows[j].Cells[1].Paragraphs[0].Append(Commanded_date);
                    t.Rows[j].Cells[2].Paragraphs[0].Append(username);
                    t.Rows[j].Cells[3].Paragraphs[0].Append(Eexcutive3[i].RequestOrder.Subject);
                    t.Rows[j].Cells[4].Paragraphs[0].Append(Eexcutive3[i].Status);
                    t.Rows[j].Cells[5].Paragraphs[0].Append(beaware_date.ToString());
                    t.Rows[j].Cells[6].Paragraphs[0].Append("-");
                }

                // Set a blank border for the table's top/bottom borders.
                var blankBorder = new Border(BorderStyle.Tcbs_none, 0, 0, Color.White);
                //t.SetBorder(TableBorderType.Bottom, blankBorder);
                //t.SetBorder(TableBorderType.Top, blankBorder);

                System.Console.WriteLine("11");
                document.Save(); //save เอกสาร
                Console.WriteLine("\tCreated: InsertHorizontalLine.docx\n");

                return(Ok(new { data = filename }));
            }
        }
示例#20
0
        //设置页眉页脚
        //        DocXClass.setHeaderFooter("F:\\example.docx","header","footer");
        public static void setHeaderFooter(string docx, string headerstr, string footerstr)
        {
            if (!File.Exists(docx))
            {
                MessageBox.Show(docx + "文件不存在");
                return;
            }
            DocX document = DocX.Load(docx);

            document.AddHeaders();
            document.AddFooters();
            // Force the first page to have a different Header and Footer.
            document.DifferentFirstPage = false;
            // Force odd & even pages to have different Headers and Footers.
            document.DifferentOddAndEvenPages = false;
            #region 设置第一页、奇偶页眉页脚
            // 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();
            #endregion

            #region 插入新页、节
            // 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.");
            #endregion
            Header header = document.Headers.odd;
            //header.Tables.First().SetBorder(TableBorderType.Bottom, new Border(Novacode.BorderStyle.Tcbs_single, BorderSize.one, 1, Color.Black));
            Paragraph p_header = header.Paragraphs.First();

            p_header.Append(headerstr);//在此处设置格式
            p_header.Alignment = Alignment.center;

            Footer    footer   = document.Footers.odd;
            Paragraph p_footer = footer.Paragraphs.First();
            p_footer.Append(footerstr);
            p_footer.Alignment = Alignment.center;
            //document.Footers.even = footer;
            //document.Footers.odd = footer;

            document.Save();
        }
示例#21
0
        public void CreateTable()
        {
            try
            {
                if (root == null)
                {
                    RefillTree();
                }
                if (root == null)
                {
                    return;
                }

                CurrentRow = 1;

                if (!Directory.Exists(TableSampleOutputDirectory))
                {
                    Directory.CreateDirectory(TableSampleOutputDirectory);
                }
                using (DocX document = DocX.Create(TableSampleOutputDirectory + SavedName))
                {
                    document.AddHeaders();

                    // Get the default Header.
                    Header header = document.Headers.Odd;

                    // Insert a Paragraph into the Header.
                    Paragraph p0 = header.InsertParagraph();
                    p0.Direction = Direction.RightToLeft;
                    p0.Alignment = Alignment.right;
                    // Appemd place holders for PageNumber and PageCount into the Header.
                    // Word will replace these with the correct value for each Page.
                    p0.Append("صفحه (");
                    p0.AppendPageNumber(PageNumberFormat.normal);
                    p0.Append(")");


                    int cntChildren = root.Children.Count;

                    foreach (var child in root.Children)
                    {
                        #region new page
                        var par = document.InsertParagraph(child.Category.Title).FontSize(FirstPargFontSize).SpacingAfter(50d);
                        par.Alignment = Alignment.left;
                        par.Direction = Direction.RightToLeft;

                        var columnWidths = new float[child.Height + 3 >= 4 ? child.Height + 3 : 4]; //root.Height;
                        columnWidths[columnWidths.Length - 4] = ColWidthsSize[0];                   //"عنوان"
                        columnWidths[columnWidths.Length - 3] = ColWidthsSize[1];                   //"داخلی"
                        columnWidths[columnWidths.Length - 2] = ColWidthsSize[2];                   //"مستقیم"
                        columnWidths[columnWidths.Length - 1] = ColWidthsSize[3];                   //"اسامی"

                        var t = document.InsertTable(1, columnWidths.Length);

                        t.SetDirection(Direction.RightToLeft);

                        t.SetWidths(columnWidths);
                        t.Design  = TableDesign.TableNormal;
                        t.AutoFit = AutoFit.Contents;

                        var row = t.Rows.First();

                        foreach (var cell in row.Cells)
                        {
                            cell.FillColor = Color.LightGray;
                        }
                        // Fill in the columns of the first row in the table.
                        row.Cells[0].Paragraphs.First().Append("عنوان").Alignment = Alignment.center;
                        row.Cells[row.Cells.Count - 3].Paragraphs.First().Append("داخلی").Alignment  = Alignment.center;
                        row.Cells[row.Cells.Count - 2].Paragraphs.First().Append("مستقیم").Alignment = Alignment.center;
                        row.Cells[row.Cells.Count - 1].Paragraphs.First().Append("اسامی").Alignment  = Alignment.center;
                        if (row.Cells.Count - 4 > 0)
                        {
                            row.MergeCells(0, row.Cells.Count - 4);
                        }


                        // Add rows in the table.
                        for (int i = 0; i < child.CntTotalRows; i++)
                        {
                            var newRow = t.InsertRow();

                            // Fill in the columns of the new rows.
                            for (int j = 0; j < newRow.Cells.Count; ++j)
                            {
                                var newCell = newRow.Cells[j];
                                //newCell.Paragraphs.First().Append("$EMPTY");
                                newCell.SetDirection(Direction.RightToLeft);
                                newCell.VerticalAlignment = VerticalAlignment.Center;
                            }
                        }


                        // Set a blank border for the table's top/bottom borders.
                        var blankBorder = new Border(Xceed.Words.NET.BorderStyle.Tcbs_single, BorderSize.one, 0, Color.Black);
                        t.SetBorder(TableBorderType.Bottom, blankBorder);
                        t.SetBorder(TableBorderType.Top, blankBorder);
                        t.SetBorder(TableBorderType.Left, blankBorder);
                        t.SetBorder(TableBorderType.Right, blankBorder);
                        t.SetBorder(TableBorderType.InsideH, blankBorder);
                        t.SetBorder(TableBorderType.InsideV, blankBorder);
                        #endregion

                        CurrentRow = 1;
                        FillTableRecursivelyHelper(document, t, child, CurrentRow, 0);
                        if (cntChildren > 1)
                        {
                            document.InsertSectionPageBreak();
                        }

                        cntChildren--;
                    }

                    document.Save();
                }
            }
            catch
            {
            }
        }
示例#22
0
        /// <summary>
        /// Add three different types of headers and footers to a document.
        /// </summary>
        public static void HeadersFooters()
        {
            Console.WriteLine("\tHeadersFooters()");

            // Create a document.
            using (DocX document = DocX.Create(HeaderFooterSample.HeaderFooterSampleOutputDirectory + @"HeadersFooters.docx"))
            {
                // Insert a Paragraph in the first page of the document.
                var p1 = document.InsertParagraph("This is the ").Append("first").Bold().Append(" page Content.");
                p1.SpacingBefore(70d);
                p1.InsertPageBreakAfterSelf();

                // Insert a Paragraph in the second page of the document.
                var p2 = document.InsertParagraph("This is the ").Append("second").Bold().Append(" page Content.");
                p2.InsertPageBreakAfterSelf();

                // Insert a Paragraph in the third page of the document.
                var p3 = document.InsertParagraph("This is the ").Append("third").Bold().Append(" page Content.");
                p3.InsertPageBreakAfterSelf();

                // Insert a Paragraph in the third page of the document.
                var p4 = document.InsertParagraph("This is the ").Append("fourth").Bold().Append(" page Content.");

                // Add Headers and Footers to the 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;

                // Insert a Paragraph into the first Header.
                document.Headers.First.InsertParagraph("This is the ").Append("first").Bold().Append(" page header");

                // Insert a Paragraph into the first Footer.
                document.Footers.First.InsertParagraph("This is the ").Append("first").Bold().Append(" page footer");

                // Insert a Paragraph into the even Header.
                document.Headers.Even.InsertParagraph("This is an ").Append("even").Bold().Append(" page header");

                // Insert a Paragraph into the even Footer.
                document.Footers.Even.InsertParagraph("This is an ").Append("even").Bold().Append(" page footer");

                // Insert a Paragraph into the odd Header.
                document.Headers.Odd.InsertParagraph("This is an ").Append("odd").Bold().Append(" page header");

                // Insert a Paragraph into the odd Footer.
                document.Footers.Odd.InsertParagraph("This is an ").Append("odd").Bold().Append(" page footer");

                // Add the page number in the first Footer.
                document.Footers.First.InsertParagraph("Page #").AppendPageNumber(PageNumberFormat.normal);

                // Add the page number in the even Footers.
                document.Footers.Even.InsertParagraph("Page #").AppendPageNumber(PageNumberFormat.normal);

                // Add the page number in the odd Footers.
                document.Footers.Odd.InsertParagraph("Page #").AppendPageNumber(PageNumberFormat.normal);

                document.Save();
                Console.WriteLine("\tCreated: HeadersFooters.docx\n");
            }
        }
示例#23
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.
        }
示例#24
0
        private void CreateDoc(ValueRange vr)
        {
            weight = 0;
            bool secondPage      = false;
            int  amountContPage1 = 0;
            int  amounrContPage2 = 0;

            for (int i = 0; i < vr.Values.Count; i++)
            {
                weight += double.Parse(vr.Values[i][5].ToString(), CultureInfo.CreateSpecificCulture("uk-UA"));
            }
            string strWeight = weight.ToString("#,#.##", CultureInfo.CreateSpecificCulture("uk-UA"));

            if (vr.Values.Count > 22)
            {
                secondPage      = true;
                amountContPage1 = 22;
                amounrContPage2 = vr.Values.Count - 22;
            }
            else
            {
                amountContPage1 = vr.Values.Count;
            }
            Directory.CreateDirectory(@"" + Properties.Settings.Default["SavingPath"].ToString() + "\\" + linesComboBox.Text + "\\" + vesselsComboBox.Text);
            DocX document = DocX.Create(@"" + Properties.Settings.Default["SavingPath"].ToString() + "\\" + linesComboBox.Text + "\\" + vesselsComboBox.Text + "\\" + senderComboBox.Text + " - Прч. " + errendNumber.Text + " - " + vr.Values.Count.ToString() + " конт. - " + countryСomboBox.Text + ".docx");

            Xceed.Words.NET.Image img;
            if (arena.Checked == true)
            {
                img = document.AddImage(@"logo1.png");
            }
            else
            {
                img = document.AddImage(@"UGLv1.jpg");
            }
            Picture p = img.CreatePicture();

            p.Height = (int)(138 / 3.2);
            p.Width  = (int)(2207 / 3.2);
            document.AddHeaders();
            Header header = document.Headers.Odd;

            header.InsertParagraph(" ", false).InsertPicture(p).FontSize(1);
            document.MarginHeader = 0;
            document.MarginFooter = 0;
            document.MarginTop    = 20;
            document.MarginLeft   = 70;
            document.MarginRight  = 25;

            document.AddFooters();
            Footer footer  = document.Footers.Odd;
            Table  tFooter = footer.InsertTable(2, 4);

            tFooter.Rows[1].Height = 50;
            tFooter.Rows[0].Cells[0].Paragraphs.First().IndentationBefore = -2f;
            tFooter.Rows[0].Cells[0].MarginLeft  = 50;
            tFooter.Rows[0].Cells[3].MarginRight = 10;
            tFooter.Rows[0].Cells[0].Width       = 160;
            tFooter.Rows[0].Cells[1].Width       = 150;
            tFooter.Rows[0].Cells[2].Width       = 150;
            tFooter.Rows[0].Cells[3].Width       = 160;
            tFooter.Rows[0].Cells[0].Paragraphs.First().Append("Экспедитор").Alignment     = Alignment.center;
            tFooter.Rows[0].Cells[1].Paragraphs.First().Append("Судовой агент").Alignment  = Alignment.center;
            tFooter.Rows[0].Cells[2].Paragraphs.First().Append("Линейный агент").Alignment = Alignment.center;
            tFooter.Rows[0].Cells[3].Paragraphs.First().Append("Таможня").Alignment        = Alignment.center;
            tFooter.Rows[1].Cells[0].Paragraphs.First().Append("Экспедитор\n").Alignment   = Alignment.left;
            tFooter.Rows[1].Cells[0].Paragraphs[0].Append("Глоба В. Л.\n").Alignment       = Alignment.left;
            tFooter.Rows[1].Cells[0].Paragraphs[0].Append("Тел.050-341-89-12").Alignment   = Alignment.left;
            tFooter.Rows[1].Cells[0].VerticalAlignment = VerticalAlignment.Bottom;
            foreach (var item in tFooter.Paragraphs)
            {
                item.Font("Times New Roman").FontSize(10).Bold();
            }
            document.MarginFooter = 15;

            Paragraph p1 = document.InsertParagraph();

            p1.Append(proforma[0]);
            if (arena.Checked == true)
            {
                p1.Append(proforma[1]).UnderlineStyle(UnderlineStyle.singleLine)
                .Append(Environment.NewLine).Append(proforma[2]);
            }
            else
            {
                p1.Append(proforma[29]).UnderlineStyle(UnderlineStyle.singleLine)
                .Append(Environment.NewLine).Append(proforma[30]);
            }
            Paragraph p2 = document.InsertParagraph();

            p2.Append(proforma[3] + " ").Append("«" + linesComboBox.Text + "»").UnderlineStyle(UnderlineStyle.singleLine).SpacingAfter(8).Alignment = Alignment.right;

            Paragraph p3   = document.InsertParagraph();
            DateTime  date = DateTime.Now;

            p3.Append(proforma[4] + " " + errendNumber.Text + " от «" + date.Day.ToString("d2") + "» " + months[date.Month - 1] + " " + date.Year + " г." + Environment.NewLine + proforma[5])
            .Append(proforma[6]).UnderlineStyle(UnderlineStyle.singleLine).Append(proforma[7]).SpacingAfter(8).Alignment = Alignment.center;

            Paragraph p4 = document.InsertParagraph();

            p4.Append(proforma[8] + " ").Append(senderNameTextBox.Text.ToUpper() + Environment.NewLine).UnderlineStyle(UnderlineStyle.singleLine)
            .Append(senderAddressTextBox.Text.ToUpper() + Environment.NewLine).UnderlineStyle(UnderlineStyle.singleLine)
            .Append("Код: " + senderCodTextBox.Text).UnderlineStyle(UnderlineStyle.singleLine)
            .SpacingAfter(8);

            Paragraph p5 = document.InsertParagraph();

            p5.Append(proforma[9] + " ").Append(receiverComboBox.Text.ToUpper() + Environment.NewLine).UnderlineStyle(UnderlineStyle.singleLine)
            .Append(receiverAddressTextBox.Text.ToUpper()).UnderlineStyle(UnderlineStyle.singleLine);

            Table t1 = document.AddTable(5, 2);

            Xceed.Words.NET.Border b = new Xceed.Words.NET.Border(Xceed.Words.NET.BorderStyle.Tcbs_none, BorderSize.five, 0, System.Drawing.Color.White);
            t1.SetBorder(TableBorderType.InsideH, b);
            t1.SetBorder(TableBorderType.InsideV, b);
            t1.SetBorder(TableBorderType.Bottom, b);
            t1.SetBorder(TableBorderType.Top, b);
            t1.SetBorder(TableBorderType.Left, b);
            t1.SetBorder(TableBorderType.Right, b);

            t1.Rows[0].Cells[0].Width       = 285;
            t1.Rows[0].Cells[1].MarginRight = 230;
            t1.Rows[1].Cells[0].Paragraphs.First().Append(proforma[10] + " ").Append("«" + vesselsComboBox.Text.ToUpper() + "»").UnderlineStyle(UnderlineStyle.singleLine).SpacingAfter(8);
            t1.Rows[1].Cells[1].Paragraphs.First().Append(proforma[11] + " ").Append(voyageComboBox.Text.ToUpper()).UnderlineStyle(UnderlineStyle.singleLine).Append("  " + proforma[12] + " ").Append(seTextBox.Text.ToUpper()).UnderlineStyle(UnderlineStyle.singleLine).Append("  " + proforma[13] + " ").Append(flagTextBox.Text.ToUpper()).UnderlineStyle(UnderlineStyle.singleLine).SpacingAfter(8);
            t1.Rows[2].Cells[0].Paragraphs.First().Append(proforma[14] + " ").Append(proforma[15]).UnderlineStyle(UnderlineStyle.singleLine).SpacingAfter(8);
            t1.Rows[2].Cells[1].Paragraphs.First().Append(proforma[16] + " ").Append(podComboBox.Text.ToUpper()).UnderlineStyle(UnderlineStyle.singleLine).SpacingAfter(8);
            t1.Rows[3].Cells[0].Paragraphs.First().Append(proforma[17] + " ").Append(potComboBox.Text.ToUpper()).UnderlineStyle(UnderlineStyle.singleLine).SpacingAfter(8);
            t1.Rows[4].Cells[0].Paragraphs.First().Append(proforma[18] + " ").Append(cargoNameСomboBox.Text.ToUpper()).UnderlineStyle(UnderlineStyle.singleLine).SpacingAfter(8);
            t1.Rows[4].Cells[1].Paragraphs.First().Append(proforma[19] + " ").Append(cargoCodComboBox.Text).UnderlineStyle(UnderlineStyle.singleLine);
            document.InsertTable(t1);

            Paragraph p6 = document.InsertParagraph();

            p6.Append(proforma[20] + " ").Append(bookingTextBox.Text.ToUpper()).UnderlineStyle(UnderlineStyle.singleLine);

            Table t2 = document.AddTable(amountContPage1 + 1, 8);

            t2.Rows[0].Cells[0].MarginLeft = 40;
            t2.Rows[0].Cells[0].Paragraphs.First().Append("Номер контейнера").Alignment = Alignment.center;
            t2.Rows[0].Cells[0].Paragraphs.First().IndentationBefore                    = -1f;
            t2.Rows[0].Cells[1].Paragraphs.First().Append("Тип").Alignment              = Alignment.center;
            t2.Rows[0].Cells[2].Paragraphs.First().Append("Кол-во Мест").Alignment      = Alignment.center;
            t2.Rows[0].Cells[3].Paragraphs.First().Append("Вес груза нетто").Alignment  = Alignment.center;
            t2.Rows[0].Cells[4].Paragraphs.First().Append("Вес груза брутто").Alignment = Alignment.center;
            t2.Rows[0].Cells[5].Paragraphs.First().Append("VGM перепро-веренный вес к-ра брутто**").Alignment = Alignment.center;
            t2.Rows[0].Cells[6].Paragraphs.First().Append("Пломбы").Alignment = Alignment.center;
            t2.Rows[0].Cells[6].Width       = 350;
            t2.Rows[0].Cells[7].MarginRight = 10;
            t2.Rows[0].Cells[7].Paragraphs.First().Append("ГТД").Alignment = Alignment.center;
            for (int i = 0; i < amountContPage1; i++)
            {
                t2.Rows[i + 1].Cells[0].Paragraphs.First().Append(vr.Values[i][0].ToString()).Alignment = Alignment.center;
                t2.Rows[i + 1].Cells[1].Paragraphs.First().Append(contSizeComboBox.Text + contTypeComboBox.Text).Alignment = Alignment.center;
                t2.Rows[i + 1].Cells[2].Paragraphs.First().Append(vr.Values[i][13].ToString().ToUpper() == "НАВАЛ" || vr.Values[i][13].ToString().ToUpper() == "" ? "НАВАЛ" : vr.Values[i][13].ToString()).Alignment = Alignment.center;
                t2.Rows[i + 1].Cells[3].Paragraphs.First().Append(vr.Values[i][4].ToString()).Alignment = Alignment.center;
                t2.Rows[i + 1].Cells[4].Paragraphs.First().Append(vr.Values[i][5].ToString()).Alignment = Alignment.center;
                t2.Rows[i + 1].Cells[5].Paragraphs.First().Append(vr.Values[i][6].ToString()).Alignment = Alignment.center;

                if (vr.Values[i].Count == 20)
                {
                    t2.Rows[i + 1].Cells[6].Paragraphs.First().Append(vr.Values[i][19].ToString()).Alignment = Alignment.center;
                }
                else
                {
                    t2.Rows[i + 1].Cells[6].Paragraphs.First().Append("").Alignment = Alignment.center;
                }
                t2.Rows[i + 1].Cells[7].Paragraphs.First().Append(vr.Values[i][2].ToString()).Alignment = Alignment.center;
                if (vr.Values[i][2].ToString() == "")
                {
                    t2.Rows[0].Cells[7].Width = 500;
                }
                else
                {
                    t2.Rows[0].Cells[7].Width = 0;
                }
            }
            foreach (var item in t2.Rows[0].Cells)
            {
                item.VerticalAlignment = VerticalAlignment.Center;
            }
            document.InsertTable(t2);

            Paragraph p7 = document.InsertParagraph();

            p7.Append(proforma[21] + Environment.NewLine + proforma[22]).SpacingAfter(8).Alignment = Alignment.center;

            Paragraph p8 = document.InsertParagraph();

            p8.Append(proforma[23] + " " + vr.Values.Count + "x" + contSizeComboBox.Text + "` контейнер(ов). ").Append("ВЕС " + '\u2013' + " " + strWeight + " кг." + Environment.NewLine).UnderlineStyle(UnderlineStyle.singleLine)
            .Append(proforma[24]).Append(proforma[25]).UnderlineStyle(UnderlineStyle.singleLine).SetLineSpacing(LineSpacingType.Line, 1.7f);

            Paragraph p9 = document.InsertParagraph();

            p9.Append(proforma[26] + " ").Append("ПРР: " + lineInfTextBox.Text.ToUpper() + ", ГРН" + Environment.NewLine).UnderlineStyle(UnderlineStyle.singleLine)
            .Append("                            ");
            if (arena.Checked == true)
            {
                p9.Append(proforma[27]).UnderlineStyle(UnderlineStyle.singleLine);
            }
            else
            {
                p9.Append(proforma[31]).UnderlineStyle(UnderlineStyle.singleLine);
            }

            foreach (var item in document.Paragraphs)
            {
                item.Font("Times New Roman").FontSize(10).Bold();
            }
            document.Paragraphs[2].FontSize(11);

            if (secondPage)
            {
                p9.InsertPageBreakAfterSelf();
                Paragraph p10 = document.InsertParagraph();
                p10.Append(proforma[28] + " " + errendNumber.Text + " от «" + date.Day.ToString("d2") + "» " + months[date.Month - 1] + " " + date.Year + " г." + Environment.NewLine + proforma[5])
                .Append(proforma[6]).UnderlineStyle(UnderlineStyle.singleLine).Append(proforma[7]).SpacingAfter(8).Alignment = Alignment.center;

                Table t3 = document.AddTable(amounrContPage2 + 1, 8);
                t3.Rows[0].Cells[0].MarginLeft = 40;
                t3.Rows[0].Cells[0].Paragraphs.First().Append("Номер контейнера").FontSize(10).Alignment = Alignment.center;
                t3.Rows[0].Cells[0].Paragraphs.First().IndentationBefore = -1f;
                t3.Rows[0].Cells[1].Paragraphs.First().Append("Тип").FontSize(10).Alignment              = Alignment.center;
                t3.Rows[0].Cells[2].Paragraphs.First().Append("Кол-во Мест").FontSize(10).Alignment      = Alignment.center;
                t3.Rows[0].Cells[3].Paragraphs.First().Append("Вес груза нетто").FontSize(10).Alignment  = Alignment.center;
                t3.Rows[0].Cells[4].Paragraphs.First().Append("Вес груза брутто").FontSize(10).Alignment = Alignment.center;
                t3.Rows[0].Cells[5].Paragraphs.First().Append("VGM перепро-веренный вес к-ра брутто**").FontSize(10).Alignment = Alignment.center;
                t3.Rows[0].Cells[6].Paragraphs.First().Append("Пломбы").FontSize(10).Alignment = Alignment.center;
                t3.Rows[0].Cells[6].Width       = 350;
                t3.Rows[0].Cells[7].MarginRight = 10;
                t3.Rows[0].Cells[7].Paragraphs.First().Append("ГТД").FontSize(10).Alignment = Alignment.center;
                for (int i = 0; i < amounrContPage2; i++)
                {
                    t3.Rows[i + 1].Cells[0].Paragraphs.First().Append(vr.Values[i + 22][0].ToString()).FontSize(10).Alignment = Alignment.center;
                    t3.Rows[i + 1].Cells[1].Paragraphs.First().Append(contSizeComboBox.Text + contTypeComboBox.Text).FontSize(10).Alignment = Alignment.center;
                    t3.Rows[i + 1].Cells[2].Paragraphs.First().Append(vr.Values[i + 22][13].ToString().ToUpper() == "НАВАЛ" || vr.Values[i + 22][13].ToString().ToUpper() == "" ? "НАВАЛ" : vr.Values[i + 22][13].ToString()).FontSize(10).Alignment = Alignment.center;
                    t3.Rows[i + 1].Cells[3].Paragraphs.First().Append(vr.Values[i + 22][4].ToString()).FontSize(10).Alignment = Alignment.center;
                    t3.Rows[i + 1].Cells[4].Paragraphs.First().Append(vr.Values[i + 22][5].ToString()).FontSize(10).Alignment = Alignment.center;
                    t3.Rows[i + 1].Cells[5].Paragraphs.First().Append(vr.Values[i + 22][6].ToString()).FontSize(10).Alignment = Alignment.center;
                    if (vr.Values[i].Count == 20)
                    {
                        t3.Rows[i + 1].Cells[6].Paragraphs.First().Append(vr.Values[i + 22][19].ToString()).FontSize(10).Alignment = Alignment.center;
                    }
                    else
                    {
                        t3.Rows[i + 1].Cells[6].Paragraphs.First().Append("").FontSize(10).Alignment = Alignment.center;
                    }
                    t3.Rows[i + 1].Cells[7].Paragraphs.First().Append(vr.Values[i + 22][2].ToString()).FontSize(10).Alignment = Alignment.center;
                    if (vr.Values[i + 22][2].ToString() == "")
                    {
                        t3.Rows[0].Cells[7].Width = 500;
                    }
                    else
                    {
                        t3.Rows[0].Cells[7].Width = 0;
                    }
                }
                foreach (var item in t3.Rows[0].Cells)
                {
                    item.VerticalAlignment = VerticalAlignment.Center;
                }
                document.InsertTable(t3);

                Paragraph p11 = document.InsertParagraph();
                p11.Append(proforma[21] + Environment.NewLine + proforma[22]).SpacingAfter(8).FontSize(10).Alignment = Alignment.center;

                Paragraph p12 = document.InsertParagraph();
                p12.Append(proforma[23] + " " + vr.Values.Count + "x" + contSizeComboBox.Text + "` контейнер(ов)." + " ").FontSize(10).Append("ВЕС " + '\u2013' + " " + strWeight + " кг." + Environment.NewLine).UnderlineStyle(UnderlineStyle.singleLine).FontSize(10)
                .Append(proforma[24]).FontSize(10).Append(proforma[25]).FontSize(10).UnderlineStyle(UnderlineStyle.singleLine).SetLineSpacing(LineSpacingType.Line, 1.7f);

                Paragraph p13 = document.InsertParagraph();
                p13.Append(proforma[26] + " ").FontSize(10).Append("ПРР: " + lineInfTextBox.Text + ", ГРН" + Environment.NewLine).FontSize(10).UnderlineStyle(UnderlineStyle.singleLine)
                .Append("                            ").FontSize(10);

                if (arena.Checked == true)
                {
                    p9.Append(proforma[27]).FontSize(10).UnderlineStyle(UnderlineStyle.singleLine);
                }
                else
                {
                    p9.Append(proforma[31]).FontSize(10).UnderlineStyle(UnderlineStyle.singleLine);
                }

                foreach (var item in document.Paragraphs)
                {
                    item.Font("Times New Roman").Bold();
                }
                secondPage = false;
            }
            try
            {
                document.Save();
                Process.Start(@"" + Properties.Settings.Default["SavingPath"].ToString() + "\\" + linesComboBox.Text + "\\" + vesselsComboBox.Text + "\\" + senderComboBox.Text + " - Прч. " + errendNumber.Text + " - " + vr.Values.Count.ToString() + " конт. - " + countryСomboBox.Text + ".docx");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#25
0
        /// <summary>
        /// Create a document and add headers/footers with tables and pictures, paragraphs and charts.
        /// </summary>
        public static void CompanyReport()
        {
            Console.WriteLine("\tCompanyReport()");

            // Create a new document.
            using (DocX document = DocX.Create(MiscellaneousSample.MiscellaneousSampleOutputDirectory + @"CompanyReport.docx"))
            {
                // Add headers and footers.
                document.AddHeaders();
                document.AddFooters();

                // Define the pages header's picture in a Table. Odd and even pages will have the same headers.
                var oddHeader        = document.Headers.Odd;
                var headerFirstTable = oddHeader.InsertTable(1, 2);
                headerFirstTable.Design  = TableDesign.ColorfulGrid;
                headerFirstTable.AutoFit = AutoFit.Window;
                var upperLeftParagraph = oddHeader.Tables[0].Rows[0].Cells[0].Paragraphs[0];
                var logo = document.AddImage(MiscellaneousSample.MiscellaneousSampleResourcesDirectory + @"Phone.png");
                upperLeftParagraph.AppendPicture(logo.CreatePicture(30, 100));
                upperLeftParagraph.Alignment = Alignment.left;

                // Define the pages header's text in a Table. Odd and even pages will have the same footers.
                var upperRightParagraph = oddHeader.Tables[0].Rows[0].Cells[1].Paragraphs[0];
                upperRightParagraph.Append("Toms Telecom Annual report").Color(Color.White);
                upperRightParagraph.SpacingBefore(5d);
                upperRightParagraph.Alignment = Alignment.right;

                // Define the pages footer's picture in a Table.
                var oddFooter        = document.Footers.Odd;
                var footerFirstTable = oddFooter.InsertTable(1, 2);
                footerFirstTable.Design  = TableDesign.ColorfulGrid;
                footerFirstTable.AutoFit = AutoFit.Window;
                var lowerRightParagraph = oddFooter.Tables[0].Rows[0].Cells[1].Paragraphs[0];
                lowerRightParagraph.AppendPicture(logo.CreatePicture(30, 100));
                lowerRightParagraph.Alignment = Alignment.right;

                // Define the pages footer's text in a Table
                var lowerLeftParagraph = oddFooter.Tables[0].Rows[0].Cells[0].Paragraphs[0];
                lowerLeftParagraph.Append("Toms Telecom 2016").Color(Color.White);
                lowerLeftParagraph.SpacingBefore(5d);

                // Define Data in first page : a Paragraph.
                var paragraph = document.InsertParagraph();
                paragraph.AppendLine("Toms Telecom Annual report\n2016").Bold().FontSize(35).SpacingBefore(150d);
                paragraph.Alignment = Alignment.center;
                paragraph.InsertPageBreakAfterSelf();

                // Define Data in second page : a Bar Chart.
                document.InsertParagraph("").SpacingAfter(150d);
                var barChart    = new BarChart();
                var sales       = CompanyData.CreateSales();
                var salesSeries = new Series("Sales Per Month");
                salesSeries.Color = Color.GreenYellow;
                salesSeries.Bind(sales, "Month", "Sales");
                barChart.AddSeries(salesSeries);
                document.InsertChart(barChart);
                document.InsertParagraph("Sales were 11% greater in 2016 compared to 2015, with the usual drop during spring time.").SpacingBefore(35d).InsertPageBreakAfterSelf();

                // Define Data in third page : a Line Chart.
                document.InsertParagraph("").SpacingAfter(150d);
                var lineChart  = new LineChart();
                var calls      = CompanyData.CreateCallNumber();
                var callSeries = new Series("Call Number Per Month");
                callSeries.Bind(calls, "Month", "Calls");
                lineChart.AddSeries(callSeries);
                document.InsertChart(lineChart);
                document.InsertParagraph("The number of calls received was much lower in 2016 compared to 2015, by 31%. Winter is still the busiest time of year.").SpacingBefore(35d);

                // Save this document to disk.
                document.Save();
                Console.WriteLine("\tCreated: CompanyReport.docx\n");
            }
        }
示例#26
0
        /// <summary>
        /// Initialize Word Report --> Support Method
        /// </summary>
        public static void InitWordSummarySetup()
        {
            try
            {
                string directory = BaseUtilities.GetFolderPath();

                resultSummarydocument = DocX.Create(Reports.testRunResultWordFolder + "\\" + "Summary Report.docx");
                //Resultdocument = DocX.Create(directory + @"Results\WordResults\Testrr.docx");

                resultSummarydocument.AddHeaders();
                Header ResultHeader = resultSummarydocument.Headers.Odd;

                Image   Headerimage = resultSummarydocument.AddImage(Reports.reportheaderimage);
                Picture picture     = Headerimage.CreatePicture();
                picture.Width  = 150;
                picture.Height = 28;
                Paragraph Header = ResultHeader.InsertParagraph();
                Header.Alignment = Alignment.right;
                Header.AppendPicture(picture);

                Paragraph Date    = resultSummarydocument.InsertParagraph();
                String    StrDate = System.DateTime.Today.ToString("dd-MM-yyyy");
                Paragraph date    = Date.Append("Date: " + StrDate).FontSize(8).Font("Calibri").Color(System.Drawing.Color.FromArgb(1, 74, 73, 71));
                date.Alignment = Alignment.left;

                Paragraph title = resultSummarydocument.InsertParagraph().Append(Reports.reportname).FontSize(12).Font("Century Gothic").Color(System.Drawing.Color.FromArgb(1, 91, 168));
                title.Alignment = Alignment.center;
                title.AppendLine();
                Paragraph tcscountpass = resultSummarydocument.InsertParagraph().Append("Total Test(s) Passed: " + Reports.ttltcspass).Color(System.Drawing.Color.FromArgb(52, 168, 83));
                tcscountpass.Alignment = Alignment.left;
                Paragraph tcscountfail = resultSummarydocument.InsertParagraph().Append("Total Test(s) Failed: " + Reports.ttltcsfail).Color(System.Drawing.Color.FromArgb(234, 67, 53));
                tcscountfail.Alignment = Alignment.left;
                tcscountfail.AppendLine();

                String[] Tableheading = { "S.No", "Scenario Name", "Test Status", "For More Details" };
                String[] Tabledata    = { BaseUtilities.scenarioName, BaseUtilities.scenarioStatus };

                Table table = resultSummarydocument.AddTable(1, 4);
                // Specify some properties for this Table.
                table.Alignment = Alignment.left;
                table.AutoFit   = AutoFit.Contents;
                table.Design    = TableDesign.TableGrid;
                table.SetColumnWidth(0, 667.87);
                table.SetColumnWidth(1, 5347.87);
                table.SetColumnWidth(2, 1255.87);
                table.SetColumnWidth(3, 1825.82);

                table.Rows[0].Cells[0].Paragraphs.First().Append(Tableheading[0]).Bold();
                table.Rows[0].Cells[1].Paragraphs.First().Append(Tableheading[1]).Bold();
                table.Rows[0].Cells[2].Paragraphs.First().Append(Tableheading[2]).Bold();
                table.Rows[0].Cells[3].Paragraphs.First().Append(Tableheading[3]).Bold();


                resultSummarydocument.InsertTable(table);

                resultSummarydocument.AddFooters();
                Footer    footer_default = resultSummarydocument.Footers.Odd;
                Paragraph footer         = footer_default.InsertParagraph();
                footer.Append(Reports.reportfooterName);

                resultSummarydocument.Save();
            }
            catch (Exception e)
            {
                Reports.SetupErrorLog(e);
            }
        }
示例#27
0
        /// <summary>
        /// Initialize Word Report --> Support Method
        /// </summary>
        public static void InitSetupWord()
        {
            try
            {
                string directory = BaseUtilities.GetFolderPath();
                SetReportpath();
                resultdocument = DocX.Create(reportpath);
                //Resultdocument = DocX.Create(directory + @"Results\WordResults\Testrr.docx");

                resultdocument.AddHeaders();
                Header ResultHeader = resultdocument.Headers.Odd;

                Image   Headerimage = resultdocument.AddImage(Reports.reportheaderimage);
                Picture picture     = Headerimage.CreatePicture();
                picture.Width  = 150;
                picture.Height = 28;
                Paragraph Header = ResultHeader.InsertParagraph();
                Header.Alignment = Alignment.right;
                Header.AppendPicture(picture);

                Paragraph Date    = resultdocument.InsertParagraph();
                String    StrDate = System.DateTime.Today.ToString("dd-MM-yyyy");
                Paragraph date    = Date.Append("Date: " + StrDate).FontSize(8).Font("Calibri").Color(System.Drawing.Color.FromArgb(1, 74, 73, 71));
                date.Alignment = Alignment.left;



                Paragraph title = resultdocument.InsertParagraph().Append("Test Case Results").FontSize(20).Font("Century Gothic").Color(System.Drawing.Color.FromArgb(1, 91, 168));
                title.Alignment = Alignment.center;
                title.AppendLine();

                String[] Tableheading = { "Feature Name", "ALM TestSet Name", "Scenario Name", "Start Time", "End Time", "Time Taken", "Test Status" };
                String[] Tabledata    = { BaseUtilities.featureFileName, BaseUtilities.testSetName, BaseUtilities.scenarioName, Reports.starttime, Reports.endtime, Reports.timetaken, BaseUtilities.scenarioStatus };

                Table table = resultdocument.AddTable(Tableheading.Length, 2);
                // Specify some properties for this Table.
                table.Alignment = Alignment.center;
                table.AutoFit   = AutoFit.Contents;
                table.Design    = TableDesign.TableGrid;


                for (int row = 0; row < Tableheading.Length; row++)
                {
                    if (Tableheading[row].Trim().ToLower() == "test status")
                    {
                        switch (Tabledata[row].ToLower())
                        {
                        case "pass":

                            table.Rows[row].Cells[0].Paragraphs.First().Append(Tableheading[row]).Bold().Color(System.Drawing.Color.FromArgb(52, 168, 83));
                            table.Rows[row].Cells[1].Paragraphs.First().Append(Tabledata[row]).Color(System.Drawing.Color.FromArgb(52, 168, 83));
                            break;

                        case "fail":
                            table.Rows[row].Cells[0].Paragraphs.First().Append(Tableheading[row]).Bold().Color(System.Drawing.Color.FromArgb(234, 67, 53));
                            table.Rows[row].Cells[1].Paragraphs.First().Append(Tabledata[row]).Color(System.Drawing.Color.FromArgb(234, 67, 53));
                            break;

                        case "skip":
                            table.Rows[row].Cells[0].Paragraphs.First().Append(Tableheading[row]).Bold().Color(System.Drawing.Color.FromArgb(234, 67, 53));
                            table.Rows[row].Cells[1].Paragraphs.First().Append(Tabledata[row]).Color(System.Drawing.Color.FromArgb(234, 67, 53));
                            break;
                        }
                    }
                    else
                    {
                        table.Rows[row].Cells[0].Paragraphs.First().Append(Tableheading[row]).Bold();
                        table.Rows[row].Cells[1].Paragraphs.First().Append(Tabledata[row]);
                    }
                }

                resultdocument.InsertTable(table);
                Paragraph p1 = resultdocument.InsertParagraph();
                p1.AppendLine();
                p1.AppendLine();
                resultdocument.AddFooters();
                Footer    footer_default = resultdocument.Footers.Odd;
                Paragraph footer         = footer_default.InsertParagraph();
                footer.Append(Reports.reportfooterName);

                Paragraph last = resultdocument.InsertParagraph();

                for (int newline = 0; newline <= 36; newline++)
                {
                    last.AppendLine();
                }
                resultdocument.Save();
            }
            catch (Exception e)
            {
                Reports.SetupErrorLog(e);
            }
        }
示例#28
0
        public void AddHeaderPortraitThenLandscape()
        {
            using (var doc = new DocX())
            {
                doc.Create();

                doc.AddHeaders();

                var table = doc.DefaultHeader.AddTable(3);
                table.WidthType = DocumentFormat.OpenXml.Wordprocessing.TableWidthUnitValues.Auto;

                for (int i = 0; i < 3; i++)
                {
                    var row = table.AddRow();
                    row.SetBorders(Units.HalfPt, BorderValue.Single);

                    if (i == 0)
                    {
                        row.SetShading(ShadingPattern.Clear, "E7E6E6");

                        row.HeaderRow = true;
                    }

                    for (int j = 0; j < 3; j++)
                    {
                        row.Cells[j].Paragraphs[0].Append($"Cell {(j + 1)}");
                    }
                }

                doc.InsertSectionPageBreak();
                doc.Orientation = PageOrientation.Landscape;

                // default is to link previous header
                // but if the orientation changes, the table will
                // only be the width of the portrait page

                // in order to have a new width you have to unlink
                // the header to the previous
                doc.AddHeaders();

                // and recreate the header

                table           = doc.DefaultHeader.AddTable(3);
                table.WidthType = DocumentFormat.OpenXml.Wordprocessing.TableWidthUnitValues.Auto;

                for (int i = 0; i < 3; i++)
                {
                    var row = table.AddRow();
                    row.SetBorders(Units.HalfPt, BorderValue.Single);

                    if (i == 0)
                    {
                        row.SetShading(ShadingPattern.Clear, "E7E6E6");

                        row.HeaderRow = true;
                    }

                    for (int j = 0; j < 3; j++)
                    {
                        row.Cells[j].Paragraphs[0].Append($"Cell {(j + 1)}");
                    }
                }

                Validate(doc);

                //doc.SaveAs(System.IO.Path.Combine(TempDirectory, "AddHeaderPortraitThenLandscape.docx"));

                doc.Close();
            }
        }
        public IActionResult PrintReport([FromBody] ExportReportViewModel model)
        {
            var electronicBook = _context.ElectronicBooks
                                 .Include(x => x.User)
                                 .Include(x => x.ElectronicBookFiles)
                                 .Where(x => x.Id == model.electronicBookId)
                                 .FirstOrDefault();

            System.Console.WriteLine("in printtttt");

            if (!Directory.Exists(_environment.WebRootPath + "//Uploads//"))
            {
                Directory.CreateDirectory(_environment.WebRootPath + "//Uploads//"); //สร้าง Folder Upload ใน wwwroot
            }
            var filePath        = _environment.WebRootPath + "/Uploads/";
            var filePath2       = _environment.WebRootPath + "/Signature/";
            var filename        = "สมุดตรวจราชการอิเล็กทรอนิกส์" + DateTime.Now.ToString("dd MM yyyy") + ".docx";
            var createfile      = filePath + filename;
            var myImageFullPath = filePath + "logo01.png";

            System.Console.WriteLine("3");
            System.Console.WriteLine("in create");
            using (DocX document = DocX.Create(createfile))
            {
                Image   image   = document.AddImage(myImageFullPath);
                Picture picture = image.CreatePicture(85, 85);
                var     logo    = document.InsertParagraph();
                logo.AppendPicture(picture).Alignment = Alignment.center;
                document.SetDefaultFont(new Xceed.Document.NET.Font("ThSarabunNew"));

                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;

                // Insert a Paragraph into the first Header.
                document.Footers.First.InsertParagraph("วันที่ออกรายงาน: ").Append(DateTime.Now.ToString("dd MMMM yyyy HH:mm", new CultureInfo("th-TH"))).Append(" น.").Alignment = Alignment.right;
                // Insert a Paragraph into the even Header.
                document.Footers.Even.InsertParagraph("วันที่ออกรายงาน: ").Append(DateTime.Now.ToString("dd MMMM yyyy HH:mm", new CultureInfo("th-TH"))).Append(" น.").Alignment = Alignment.right;
                // Insert a Paragraph into the odd Header.
                document.Footers.Odd.InsertParagraph("วันที่ออกรายงาน: ").Append(DateTime.Now.ToString("dd MMMM yyyy HH:mm", new CultureInfo("th-TH"))).Append(" น.").Alignment = Alignment.right;

                // Add the page number in the first Footer.
                document.Headers.First.InsertParagraph("").AppendPageNumber(PageNumberFormat.normal).Alignment = Alignment.center;
                // Add the page number in the even Footers.
                document.Headers.Even.InsertParagraph("").AppendPageNumber(PageNumberFormat.normal).Alignment = Alignment.center;
                // Add the page number in the odd Footers.
                document.Headers.Odd.InsertParagraph("").AppendPageNumber(PageNumberFormat.normal).Alignment = Alignment.center;

                System.Console.WriteLine("5");

                // Add a title

                var reportType = document.InsertParagraph("สมุดตรวจราชการอิเล็กทรอนิกส์");
                reportType.FontSize(18d);
                reportType.SpacingBefore(15d);
                reportType.SpacingAfter(5d);
                reportType.Bold();
                reportType.Alignment = Alignment.center;

                System.Console.WriteLine("6");

                Thread.CurrentThread.CurrentCulture = new CultureInfo("th-TH");
                var testDate  = electronicBook.StartDate.Value.ToString("dddd dd MMMM yyyy");
                var printDate = DateTime.Now.ToString("dd MMMM yyyy");
                // Insert a title paragraph.
                var title = document.InsertParagraph("วันที่ตรวจราชการ: " + testDate);
                title.Alignment = Alignment.center;
                title.SpacingAfter(15d);
                title.FontSize(16d);
                title.Bold();

                //var printReport = document.InsertParagraph("วันที่ออกรายงาน: " + printDate);
                //printReport.Alignment = Alignment.center;
                //printReport.SpacingAfter(25d);
                //printReport.FontSize(16d);
                //printReport.Bold();

                System.Console.WriteLine("7");

                //var year = document.InsertParagraph("ตรวจ ณ สถานที่: ");
                //year.Alignment = Alignment.center;
                //year.SpacingAfter(10d);
                //year.FontSize(16d);
                //System.Console.WriteLine("8");


                var subjectTitle = document.InsertParagraph("เรื่อง/ประเด็น/โครงการที่ตรวจติดตาม");
                subjectTitle.Alignment = Alignment.left;
                //subjectTitle.SpacingAfter(10d);
                subjectTitle.FontSize(16d);
                subjectTitle.Bold();
                System.Console.WriteLine("8");

                var subject = document.InsertParagraph("");

                int s = 0;
                for (var i = 0; i < model.subjectData.Length; i++)
                {
                    s += 1;
                    subject.FontSize(16d).Append(s.ToString()).Append(") ").Append(model.subjectData[i] + "\n").FontSize(16d);
                }

                var detailTitle = document.InsertParagraph("ผลการตรวจ");
                detailTitle.SpacingBefore(10d);
                detailTitle.FontSize(16d);
                detailTitle.Bold();
                var detail = document.InsertParagraph(electronicBook.Detail);
                detail.SpacingBefore(5d);
                detail.FontSize(16d);
                // detail.UnderlineColor(Color.Black);
                // detail.UnderlineStyle(UnderlineStyle.dotted);

                var suggestionTitle = document.InsertParagraph("ปัญหาและอุปสรรค");
                suggestionTitle.SpacingBefore(15d);
                suggestionTitle.FontSize(16d);
                suggestionTitle.Bold();
                var suggestion = document.InsertParagraph(electronicBook.Problem);
                suggestion.SpacingBefore(5d);
                suggestion.FontSize(16d);
                // suggestion.UnderlineColor(Color.Black);
                // suggestion.UnderlineStyle(UnderlineStyle.dotted);

                var commandTitle = document.InsertParagraph("ข้อเสนอแนะ");
                commandTitle.SpacingBefore(15d);
                commandTitle.FontSize(16d);
                commandTitle.Bold();
                var command = document.InsertParagraph(electronicBook.Suggestion);
                command.SpacingBefore(5d);
                command.FontSize(16d);
                // command.UnderlineColor(Color.Black);
                // command.UnderlineStyle(UnderlineStyle.dotted);
                //command.InsertPageBreakAfterSelf();
                System.Console.WriteLine("11");


                //System.Console.WriteLine("9");

                //var region = document.InsertParagraph("เขตตรวจราชการที่: " + model.reportData2[i].region + "(จังหวัด: " + model.reportData2[i].province + ")");
                //region.Alignment = Alignment.center;
                //region.SpacingAfter(30d);
                //region.FontSize(16d);

                //var statusReport = document.InsertParagraph("สถานะของรายงาน: " + exportData.Status);
                //statusReport.FontSize(16d);
                //statusReport.Alignment = Alignment.right;

                //var monitorTopic = document.InsertParagraph("หัวข้อการตรวจติดตาม: " + exportData.MonitoringTopics);
                //monitorTopic.SpacingBefore(15d);
                //monitorTopic.FontSize(16d);
                //monitorTopic.Bold();

                //System.Console.WriteLine("99");
                var inspectorTitle = document.InsertParagraph("คำแนะนำผู้ตรวจราชการ");
                inspectorTitle.SpacingBefore(30d);
                inspectorTitle.SpacingAfter(5d);
                inspectorTitle.FontSize(16d);
                inspectorTitle.Bold();

                int dataCount = 0;
                dataCount  = model.printReport.Count();
                dataCount += 1;
                System.Console.WriteLine("Data Count: " + dataCount);
                // Add a table in a document of 1 row and 3 columns.
                var columnWidths = new float[] { 40f, 250f, 90f, 120f, };
                var t            = document.InsertTable(dataCount, columnWidths.Length);

                //System.Console.WriteLine("8");

                //// Set the table's column width and background
                t.SetWidths(columnWidths);
                t.AutoFit   = AutoFit.Contents;
                t.Alignment = Alignment.center;

                var row = t.Rows.First();
                //System.Console.WriteLine("9");

                // Fill in the columns of the first row in the table.
                //for (int i = 0; i < row.Cells.Count; ++i)
                //{
                row.Cells[0].Paragraphs.First().Append("ลำดับ").FontSize(16d).Alignment = Alignment.center;
                row.Cells[1].Paragraphs.First().Append("คำแนะนำหรือสั่งการของผู้ตรวจ").FontSize(16d).Alignment = Alignment.center;
                row.Cells[2].Paragraphs.First().Append("ความเห็นผู้ตรวจ").FontSize(16d).Alignment   = Alignment.center;
                row.Cells[3].Paragraphs.First().Append("ลายมือชื่อผู้ตรวจ").FontSize(16d).Alignment = Alignment.center;

                System.Console.WriteLine("10");

                //}
                // Add rows in the table.
                int j = 0;
                for (int k = 0; k < model.printReport.Length; k++)
                {
                    j += 1;
                    System.Console.WriteLine("10.1");

                    System.Console.WriteLine("9.1: " + model.printReport[k].inspectorDescription);
                    t.Rows[j].Cells[0].Paragraphs[0].Append(j.ToString()).FontSize(16d).Alignment = Alignment.center;
                    t.Rows[j].Cells[1].Paragraphs[0].Append(model.printReport[k].inspectorDescription).FontSize(16d);
                    t.Rows[j].Cells[2].Paragraphs[0].Append(model.printReport[k].approve).FontSize(16d);
                    if (model.printReport[k].inspectorSign != null && model.printReport[k].inspectorSign != "null" && model.printReport[k].inspectorSign != "")
                    {
                        System.Console.WriteLine("9.3: " + model.printReport[k].inspectorSign);
                        var myImageFullPath2 = filePath2 + model.printReport[k].inspectorSign;

                        Image image2 = document.AddImage(myImageFullPath2);
                        System.Console.WriteLine("JJJJJ: ");
                        Picture picture2 = image2.CreatePicture(30, 30);
                        t.Rows[j].Cells[3].Paragraphs[0].AppendPicture(picture2).SpacingBefore(3d).Append("\n" + model.printReport[k].inspectorName).FontSize(16d).Alignment = Alignment.center;
                    }
                    else
                    {
                        System.Console.WriteLine("9.4: ");
                        t.Rows[j].Cells[3].Paragraphs[0].Append(model.printReport[k].inspectorName).FontSize(16d).Alignment = Alignment.center;
                    }
                    System.Console.WriteLine("10");
                }

                // Set a blank border for the table's top/bottom borders.
                var blankBorder = new Border(BorderStyle.Tcbs_none, 0, 0, Color.White);
                //t.SetBorder(TableBorderType.Bottom, blankBorder);
                //t.SetBorder(TableBorderType.Top, blankBorder);

                // document.InsertSectionPageBreak();

                System.Console.WriteLine("IN DEPARTMENT");

                var departmentTitle = document.InsertParagraph("การดำเนินการของหน่วยรับตรวจ");
                departmentTitle.SpacingBefore(30d);
                departmentTitle.SpacingAfter(5d);
                departmentTitle.FontSize(16d);
                departmentTitle.Bold();

                System.Console.WriteLine("IN DEPARTMENT2");

                int dataCount2 = 0;
                dataCount2  = model.printReport2.Count();
                dataCount2 += 1;
                System.Console.WriteLine("Data Count department: " + dataCount2);
                // Add a table in a document of 1 row and 3 columns.
                var columnWidths2 = new float[] { 40f, 250f, 80f, 120f, };
                var t2            = document.InsertTable(dataCount2, columnWidths2.Length);

                //System.Console.WriteLine("8");

                //// Set the table's column width and background
                t2.SetWidths(columnWidths2);
                t2.AutoFit   = AutoFit.Contents;
                t2.Alignment = Alignment.center;

                var row2 = t2.Rows.First();
                //System.Console.WriteLine("9");

                // Fill in the columns of the first row in the table.
                //for (int i = 0; i < row.Cells.Count; ++i)
                //{
                row2.Cells[0].Paragraphs.First().Append("ลำดับ").FontSize(16d).Alignment = Alignment.center;
                row2.Cells[1].Paragraphs.First().Append("การดำเนินการของหน่วยรับตรวจ").FontSize(16d).Alignment = Alignment.center;
                row2.Cells[2].Paragraphs.First().Append("หน่วยรับตรวจ").FontSize(16d).Alignment         = Alignment.center;
                row2.Cells[3].Paragraphs.First().Append("ลายมือชื่อผู้รับตรวจ").FontSize(16d).Alignment = Alignment.center;

                System.Console.WriteLine("10");
                //}
                // Add rows in the table.
                int j2 = 0;
                for (int k = 0; k < model.printReport2.Length; k++)
                {
                    j2 += 1;
                    t2.Rows[j2].Cells[0].Paragraphs[0].Append(j2.ToString()).FontSize(16d).Alignment = Alignment.center;
                    t2.Rows[j2].Cells[1].Paragraphs[0].Append(model.printReport2[k].departmentDescription).FontSize(16d);
                    t2.Rows[j2].Cells[2].Paragraphs[0].Append(model.printReport2[k].department).FontSize(16d);
                    if (model.printReport2[k].departmentSign != null && model.printReport2[k].departmentSign != "null" && model.printReport2[k].departmentSign != "")
                    {
                        var   myImageFullPath3 = filePath2 + model.printReport2[k].departmentSign;
                        Image image3           = document.AddImage(myImageFullPath3);
                        System.Console.WriteLine("JJJJJ: ");
                        Picture picture2 = image3.CreatePicture(30, 30);
                        t2.Rows[j2].Cells[3].Paragraphs[0].AppendPicture(picture2).SpacingBefore(3d).Append("\n" + model.printReport2[k].departmentName).FontSize(16d).Alignment = Alignment.center;
                    }
                    else
                    {
                        t2.Rows[j2].Cells[3].Paragraphs[0].Append(model.printReport2[k].departmentName).FontSize(16d);
                    }

                    System.Console.WriteLine("10");
                }

                // Set a blank border for the table's top/bottom borders.
                var blankBorder2 = new Border(BorderStyle.Tcbs_none, 0, 0, Color.White);


                document.Save();
                Console.WriteLine("\tCreated: InsertHorizontalLine.docx\n");
            }

            return(Ok(new { data = filename }));
        }
示例#30
0
            private static void ApplyProperties(DocX doc, XElement properties, Dictionary <string, Font> fonts, SharedClasses.DB.DB_Connector connection, uint?id, ref string placeholderGroup, string[] singleParams)
            {
                if (properties.Element("Borders") != null)
                {
                    AddBorders(doc);
                }

                if (properties.Element("Format") != null)
                {
                    float width, height;
                    switch (properties.Element("Format").Value)
                    {
                    case "A5":
                        width  = 419.5f;
                        height = 595.2f;
                        break;

                    case "A6":
                        width  = 297.6f;
                        height = 419.5f;
                        break;

                    default:
                        throw new System.Exception("Unreachable reached.");
                    }

                    if (doc.PageLayout.Orientation == Orientation.Portrait)
                    {
                        doc.PageWidth  = width;
                        doc.PageHeight = height;
                    }
                    else
                    {
                        doc.PageHeight = width;
                        doc.PageWidth  = height;
                    }
                }

                if (properties.Element("Album") != null)
                {
                    float width  = doc.PageWidth;
                    float height = doc.PageHeight;
                    doc.PageLayout.Orientation = Orientation.Landscape;
                    doc.PageWidth  = height;
                    doc.PageHeight = width;
                }

                if (properties.Element("Margins") != null)
                {
                    XElement margins = properties.Element("Margins");

                    if (margins.Element("Left") != null)
                    {
                        doc.MarginLeft = float.Parse(margins.Element("Left").Value);
                    }
                    if (margins.Element("Top") != null)
                    {
                        doc.MarginTop = float.Parse(margins.Element("Top").Value);
                    }
                    if (margins.Element("Right") != null)
                    {
                        doc.MarginRight = float.Parse(margins.Element("Right").Value);
                    }
                    if (margins.Element("Bottom") != null)
                    {
                        doc.MarginBottom = float.Parse(margins.Element("Bottom").Value);
                    }
                }

                if (properties.Element("Headers") != null)
                {
                    doc.AddHeaders();
                    doc.Headers.first.RemoveParagraphAt(0);
                    MakeParagraph(properties.Element("Headers"), doc.Headers.first.InsertParagraph(), fonts, connection, id, ref placeholderGroup, singleParams);
                    doc.Headers.odd.RemoveParagraphAt(0);
                    MakeParagraph(properties.Element("Headers"), doc.Headers.odd.InsertParagraph(), fonts, connection, id, ref placeholderGroup, singleParams);
                    doc.Headers.even.RemoveParagraphAt(0);
                    MakeParagraph(properties.Element("Headers"), doc.Headers.even.InsertParagraph(), fonts, connection, id, ref placeholderGroup, singleParams);
                }

                if (properties.Element("PageNumeration") != null)
                {
                    doc.AddFooters();
                    doc.Footers.first.PageNumbers             = true;
                    doc.Footers.odd.PageNumbers               = true;
                    doc.Footers.even.PageNumbers              = true;
                    doc.Footers.first.Paragraphs[0].Alignment = Alignment.right;
                    doc.Footers.odd.Paragraphs[0].Alignment   = Alignment.right;
                    doc.Footers.even.Paragraphs[0].Alignment  = Alignment.right;
                }
            }