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();
            }
        }
        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 void AddFooterWithRomanPageNumbers()
        {
            using (var doc = new DocX())
            {
                doc.Create();

                doc.AddFooters();
                doc.DefaultFooter
                .AddParagraph()
                .Append("Page: ")
                .AppendPageNumber(PageNumberFormat.Roman)
                .Append(" of ")
                .AppendPageCount(PageNumberFormat.Roman)
                .Bold()
                .Alignment = Align.Center;

                for (int i = 0; i < 9; i++)
                {
                    doc.InsertPageBreak();
                }

                Validate(doc);

                doc.Close();
            }
        }
Example #4
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();
        }
        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();
            }
        }
Example #6
0
        public void InFooter()
        {
            using (var doc = new DocX())
            {
                doc.Create();

                doc.AddFooters();

                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.DefaultFooter.AddImage(GetEmbeddedResourceStream("Peggys_Cove_Nova_Scotia_01.jpg"), "image/jpg", Units.InchToEMU(inchWidth), Units.InchToEMU(inchHeight));
                doc.DefaultFooter.AddParagraph().Append(drawing);

                Validate(doc);

                doc.Close();
            }
        }
Example #7
0
        private void implementarFooter(DocX doc)
        {
            doc.AddFooters();
            // Footer con número de página
            Footer footer_default = doc.Footers.odd;

            footer_default.PageNumbers = true;
        }
Example #8
0
        private DocX addFooter(DocX _doc)
        {
            DocX doc = _doc;

            doc.AddFooters();
            doc.DifferentFirstPage = true;
            doc.Footers.First.InsertParagraph(mainViewModel.profileCompanyName + "   " + mainViewModel.profilePostalCode + " " + mainViewModel.profileAddress + " "
                                              + mainViewModel.profileAddressNumber + "   Finanzamt Elmshorn Steuernummer: 130800907", false, getStandardFormat()).Alignment = Alignment.center;

            return(doc);
        }
Example #9
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();
        }
        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);
        }
Example #11
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;
        }
Example #12
0
        public void AddFooter()
        {
            using (var doc = new DocX())
            {
                doc.Create();

                doc.AddFooters();
                doc.DefaultFooter.AddParagraph().Append("Footer Paragraph");

                Validate(doc);

                doc.Close();
            }
        }
Example #13
0
 public void OpenTask(Exam exam, Ticket ticket, bool markAnswers)
 {
     CloseWord();
     OneAnswerQuestion[] questions = ticket.GetQuestions().Cast <OneAnswerQuestion>().ToArray();
     using (DocX docXdocument = DocX.Create(path.ToString()))
     {
         int i, j;
         docXdocument.AddFooters();
         docXdocument.SetDefaultFont(new Xceed.Document.NET.Font("Times New Roman"));
         Xceed.Document.NET.Paragraph headerParagraph = docXdocument.InsertParagraph();
         Xceed.Document.NET.Paragraph paragraph       = docXdocument.InsertParagraph();
         headerParagraph.Append($"Перегляд завдання")
         .Bold()
         .FontSize(28);
         paragraph.Append($"Завдання білету \"{ticket.TicketName}\":")
         .FontSize(24);
         Xceed.Document.NET.Table table = docXdocument.AddTable(questions.Length, 2);
         table.SetWidthsPercentage(new[] { 50f, 50 }, docXdocument.PageWidth - docXdocument.PageWidth / 5);
         table.SetBorder(TableBorderType.Bottom, new Xceed.Document.NET.Border(BorderStyle.Tcbs_double, BorderSize.two, 0, Color.Black));
         table.SetBorder(TableBorderType.Top, new Xceed.Document.NET.Border(BorderStyle.Tcbs_double, BorderSize.two, 0, Color.Black));
         table.SetBorder(TableBorderType.Left, new Xceed.Document.NET.Border(BorderStyle.Tcbs_double, BorderSize.two, 0, Color.Black));
         table.SetBorder(TableBorderType.Right, new Xceed.Document.NET.Border(BorderStyle.Tcbs_double, BorderSize.two, 0, Color.Black));
         table.SetBorder(TableBorderType.InsideV, new Xceed.Document.NET.Border(BorderStyle.Tcbs_double, BorderSize.two, 0, Color.Black));
         for (i = 0; i < questions.Length; i++)
         {
             table.Rows[i].Cells[0]
             .InsertParagraph()
             .Append($"{questions[i].QuestionNumber + exam.FirstQuestionNumber}) {questions[i].QuestionContent.Text}")
             .FontSize(12);
             Xceed.Document.NET.Paragraph tableParagraph = table.Rows[i].Cells[1].InsertParagraph();
             for (j = 0; j < questions[i].QuestionContent.Answers.Count; j++)
             {
                 Xceed.Document.NET.Paragraph tempParagraph = tableParagraph.Append($"{(j < questions[i].QuestionContent.Letters.Length ? questions[i].QuestionContent.Letters[j].ToString() : "*")}{questions[i].QuestionContent.Devider} { questions[i].QuestionContent.Answers[j]};{Environment.NewLine}");
                 if (markAnswers && questions[i].Answer.Content == questions[i].QuestionContent.Answers[j])
                 {
                     tempParagraph.Bold()
                     .FontSize(12);
                 }
             }
         }
         docXdocument.InsertTable(table);
         docXdocument.Footers.Odd.InsertParagraph()
         .Append("Створено за допомогою SimplEx Program")
         .FontSize(10)
         .UnderlineStyle(UnderlineStyle.singleLine)
         .Alignment = Alignment.right;
         docXdocument.Save();
     }
     OpenWord();
 }
Example #14
0
        public void SaveAs(WebBook book, string path)
        {
            var fileName = string.Format(FileTemplate, $"{path}\\", book.Name);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            if (new DirectoryInfo(path).GetFiles().Any(f => f.Name.Contains(book.Name)))
            {
                return;
            }

            DocX doc = DocX.Create(fileName);

            doc.DifferentFirstPage = true;
            doc.AddFooters();

            InsertImage(doc, _download.DownloadFile(book.ImageUrl, book.Name));
            foreach (var page in book.Pages)
            {
                foreach (var data in page.WebBookTexts)
                {
                    switch (data)
                    {
                    case WebBookHeader _:
                        InsertHeader(doc, data.Text);
                        break;

                    case WebBookParagraph _:
                        InsertParagraph(doc, data.Text);
                        break;
                    }
                }
            }

            var even = doc.Footers.Even.InsertParagraph("Page №");

            even.Alignment = Alignment.center;
            even.AppendPageNumber(PageNumberFormat.normal);
            var odd = doc.Footers.Odd.InsertParagraph("Page №");

            odd.Alignment = Alignment.center;
            odd.AppendPageNumber(PageNumberFormat.normal);

            doc.Save();
        }
Example #15
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();
            }
        }
Example #16
0
        public void AddFooters()
        {
            using (var doc = new DocX())
            {
                doc.Create();

                doc.AddFooters();

                doc.DefaultFooter
                .AddParagraph()
                .Append("Default (Odd) Footer");

                doc.EvenFooter
                .AddParagraph()
                .Append("Even Footer");

                doc.FirstFooter
                .AddParagraph()
                .Append("First Footer");

                doc.DifferentFirstPage = true;
                doc.EvenAndOddHeaders  = true;

                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();
            }
        }
        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;
        }
Example #18
0
        private static Footers CreateFooter(DocX doc)
        {
            var formattingBold = new Formatting {
                Bold = true, Size = DefaultSize, FontFamily = Font
            };
            var formattingWithoutBold = new Formatting {
                Bold = false, Size = DefaultSize, FontFamily = Font
            };

            doc.AddFooters();
            doc.Footers.Odd.InsertParagraph().Append("_______________________________________________________________________________________________________________", formattingWithoutBold);
            var p = doc.Footers.Odd.InsertParagraph();

            p.AppendPageNumber(PageNumberFormat.normal);
            p.Append("/");
            p.AppendPageCount(PageNumberFormat.normal);
            p.Bold();
            p.FontSize(8);
            p.Alignment = Alignment.right;

            return(doc.Footers);
        }
Example #19
0
        public static void ExportConfigAsDocX(string fileName, XmlConfigFileViewModel xmlConfigFile)
        {
            DocX doc = DocX.Create(fileName);

            doc.AddFooters();
            doc.Footers.even.InsertParagraph(xmlConfigFile.FileName);
            doc.Footers.odd.InsertParagraph(xmlConfigFile.FileName);

            Paragraph p = doc.InsertParagraph();

            p           = doc.InsertParagraph();
            p.StyleName = "Title";
            p.InsertText("Acma Configuration");

            p           = doc.InsertParagraph();
            p.StyleName = "Heading1";
            p.InsertText("Description");

            p = doc.InsertParagraph(xmlConfigFile.Description);

            doc.InsertSectionPageBreak();
            p           = doc.InsertParagraph();
            p.StyleName = "Heading1";
            p.InsertText("Class Constructors");

            foreach (var classConstructor in xmlConfigFile.Constructors)
            {
                p           = doc.InsertParagraph();
                p.StyleName = "Heading2";
                p.InsertText(classConstructor.Name);

                DocXExporter.WriteConstructorObject(classConstructor.Constructors, doc);
                doc.InsertSectionPageBreak();
            }

            doc.Save();
        }
Example #20
0
        public static void ExportUnitTestAsDocX(string fileName, UnitTestFileViewModel unitTestFile)
        {
            DocX doc = DocX.Create(fileName);

            doc.AddFooters();
            doc.Footers.even.InsertParagraph(unitTestFile.FileName);
            doc.Footers.odd.InsertParagraph(unitTestFile.FileName);

            Paragraph p = doc.InsertParagraph();

            p           = doc.InsertParagraph();
            p.StyleName = "Title";
            p.InsertText("Acma Unit Test Definitions");

            doc.InsertSectionPageBreak();

            foreach (var unitTest in unitTestFile.UnitTestObjects)
            {
                if (unitTest is UnitTestGroupViewModel)
                {
                    DocXExporter.WriteUnitTestGroup(unitTest as UnitTestGroupViewModel, doc);
                }
                else if (unitTest is UnitTestViewModel)
                {
                    DocXExporter.WriteUnitTest(unitTest as UnitTestViewModel, doc);
                }
                else
                {
                    throw new ArgumentException("Unknown unit test object");
                }

                doc.InsertSectionPageBreak();
            }

            doc.Save();
        }
        internal void addFooters(DocX document, HeaderFooterOption footerOption, bool firstOption, bool oddEvenOption)
        {
            document.AddFooters();

            if (firstOption)
            {
                document.DifferentFirstPage = true;
                this.headerFooterSetting.firstFooter(document, footerOption);
            }
            else
            {
                document.DifferentFirstPage = false;
            }
            if (oddEvenOption)
            {
                document.DifferentOddAndEvenPages = true;
                this.headerFooterSetting.oddFooter(document, footerOption);
                this.headerFooterSetting.evenFooter(document, footerOption);
            }
            else
            {
                this.headerFooterSetting.pageFooter(document, footerOption);
            }
        }
        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 }));
            }
        }
        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 }));
            }
        }
Example #24
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");
            }
        }
Example #25
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);
            }
        }
Example #26
0
        public void AddFooterLandscapeThenLandscape()
        {
            using (var doc = new DocX())
            {
                doc.Create();
                doc.Orientation = PageOrientation.Landscape;

                doc.AddFooters();

                var table = doc.DefaultFooter.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");
                    }

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

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

                // default is to link previous footer
                // 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.AddFooters();

                // and recreate the header

                table           = doc.DefaultFooter.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");
                    }

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

                Validate(doc);

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

                doc.Close();
            }
        }
Example #27
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.
        }
        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 }));
        }
Example #29
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);
            }
        }
Example #30
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);
            }
        }