Esempio n. 1
0
        /// <summary>
        /// Initialize Word Report --> Support Method
        /// </summary>
        public static void InsertSummaryResults()
        {
            try
            {
                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(smrw.ToString() + ".");
                smrw += 1;
                table.Rows[0].Cells[1].Paragraphs.First().Append(BaseUtilities.scenarioName);
                switch (BaseUtilities.scenarioStatus.ToLower())
                {
                case "pass":

                    table.Rows[0].Cells[2].Paragraphs.First().Append("Pass").Color(System.Drawing.Color.FromArgb(52, 168, 83));
                    break;

                case "fail":

                    table.Rows[0].Cells[2].Paragraphs.First().Append("Fail").Color(System.Drawing.Color.FromArgb(234, 67, 53));
                    break;

                case "skip":

                    table.Rows[0].Cells[2].Paragraphs.First().Append("Skip").Color(System.Drawing.Color.FromArgb(234, 67, 53));
                    break;
                }


                Hyperlink link = resultSummarydocument.AddHyperlink("Click here", new Uri(reportpath));
                table.Rows[0].Cells[3].Paragraphs.First().AppendHyperlink(link).Color(System.Drawing.Color.FromArgb(1, 91, 168));

                resultSummarydocument.InsertTable(table);

                resultSummarydocument.Save();
            }
            catch (Exception e)
            {
                Reports.SetupErrorLog(e);
            }
        }
        public void CopyFromFileTextOnly_Test_CopiesNoStyle()
        {
            _tmpFile = GetNewRandomFilePath(GetOrCreateTmpDirectory());
            using (DocX doc = DocX.Create(_tmpFile)) {
                doc.InsertParagraph()
                .Append("text")
                .Bold()
                .Italic()
                .Color(Color.Green)
                .FontSize(20);
                doc.Save();
            }

            Range targetRange = _application.Documents.Add().Range();

            targetRange.Text = "unexpected";

            new OpenXmlHelper().CopyFromFileTextOnly(_tmpFile, targetRange);

            Range result = targetRange.Document.Range(1, 2);

            Assert.Zero(result.Bold);
            Assert.Zero(result.Italic);
            Assert.That(result.Font.Size, Is.Not.EqualTo(20).Within(0.001));
            Assert.That(result.Font.Color, Is.Not.EqualTo(WdColor.wdColorGreen));
        }
Esempio n. 3
0
        private DocX outputDoc(string nowBalance, string nowSum, string nowBalanceAfterBuy, string nowBonus)
        {
            string pathDocument = "C:\\Users\\oobit\\Desktop\\first.docx";
            DocX   document     = DocX.Create(pathDocument);

            document.MarginLeft   = 60.0f;
            document.MarginRight  = 60.0f;
            document.MarginTop    = 60.0f;
            document.MarginBottom = 60.0f;
            document.InsertParagraph("Чек покупки").Bold().Font("Times New Roman").FontSize(14);
            Table table = document.AddTable(4, 2);

            table.Alignment = Alignment.center;
            table.Design    = TableDesign.TableGrid;
            table.SetWidths(new float[] { 180.0f, 600.0f });
            table.Rows[0].Cells[0].Paragraphs[0].Append("Баланс до покупки").Font("Times New Roman").FontSize(12).Bold();
            table.Rows[0].Cells[1].Paragraphs[0].Append(nowBalance).Font("Times New Roman").FontSize(12);
            table.Rows[1].Cells[0].Paragraphs[0].Append("Сумма").Font("Times New Roman").FontSize(12).Bold();
            table.Rows[1].Cells[1].Paragraphs[0].Append(nowSum).Font("Times New Roman").FontSize(12);
            table.Rows[2].Cells[0].Paragraphs[0].Append("Баланс после покупки").Font("Times New Roman").FontSize(12).Bold();
            table.Rows[2].Cells[1].Paragraphs[0].Append(nowBalanceAfterBuy).Font("Times New Roman").FontSize(12);
            table.Rows[3].Cells[0].Paragraphs[0].Append("Текущее количество бонусов").Font("Times New Roman").FontSize(12).Bold();
            table.Rows[3].Cells[1].Paragraphs[0].Append(nowBonus).Font("Times New Roman").FontSize(12);
            document.InsertParagraph().InsertTableAfterSelf(table);
            document.Save();
            return(document);
        }
Esempio n. 4
0
        /// <summary>
        /// Modify the direction of text in a paragraph or document.
        /// </summary>
        public static void SetDirection()
        {
            Console.WriteLine("\tSetDirection()");

            // Create a document.
            using (DocX document = DocX.Create(MarginSample.MarginSampleOutputDirectory + @"SetDirection.docx"))
            {
                // Add a title.
                document.InsertParagraph("Modify direction of paragraphs").FontSize(15d).SpacingAfter(50d).Alignment = Alignment.center;

                // Add first paragraph.
                var p = document.InsertParagraph("This is the first paragraph.");
                p.SpacingAfter(30);

                // Add second paragraph.
                var p2 = document.InsertParagraph("This is the second paragraph.");
                p2.SpacingAfter(30);
                // Make this Paragraph flow right to left. Default is left to right.
                p2.Direction = Direction.RightToLeft;

                // Add third paragraph.
                var p3 = document.InsertParagraph("This is the third paragraph.");
                p3.SpacingAfter(30);

                // Add fourth paragraph.
                var p4 = document.InsertParagraph("This is the fourth paragraph.");
                p4.SpacingAfter(30);

                // To modify the direction of each paragraph in a document, just set the direction on the document.
                document.SetDirection(Direction.RightToLeft);

                document.Save();
                Console.WriteLine("\tCreated: SetDirection.docx\n");
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Create a read only document that can be edited by stopping the protection.
        /// </summary>
        public static void AddProtection()
        {
            Console.WriteLine("\tAddProtection()");

            // Create a new document.
            using (DocX document = DocX.Create(ProtectionSample.ProtectionSampleOutputDirectory + @"AddProtection.docx"))
            {
                // Add a title.
                document.InsertParagraph("Document protection not using password").FontSize(15d).SpacingAfter(50d).Alignment = Alignment.center;

                // Insert a Paragraph into this document.
                var p = document.InsertParagraph();

                // Append some text and add formatting.
                p.Append("This document is protected and can only be edited by stopping its protection.")
                .Font(new Font("Arial"))
                .FontSize(25)
                .Color(Color.Red)
                .Bold();

                document.AddProtection(EditRestrictions.readOnly);

                // Save this document to disk.
                document.Save();
                Console.WriteLine("\tCreated: AddProtection.docx\n");
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Add a Table of content to a document by inserting it just before a reference paragraph.
        /// </summary>
        public static void InsertTableOfContentWithReference()
        {
            Console.WriteLine("\tInsertTableOfContentWithReference()");

            // Create a document.
            using (DocX document = DocX.Create(TableOfContentSample.TableOfContentSampleOutputDirectory + @"InsertTableOfContentWithReference.docx"))
            {
                // Add a title.
                document.InsertParagraph("Insert Table of content with reference").FontSize(15d).SpacingAfter(50d).Alignment = Alignment.center;

                // Add an intro paragraph.
                var intro = document.InsertParagraph("This page will show the team rosters of the American League East Division.");
                intro.SpacingAfter(150d);

                // Create a paragraph and fill it in method AddTeams().
                var p       = document.InsertParagraph();
                var rosters = TableOfContentSample.AddTeams(p);
                document.InsertParagraph(rosters);

                // Insert a table of content with a page break just before the paragraph p.
                document.InsertTableOfContents(p,
                                               "Teams",
                                               TableOfContentsSwitches.O | TableOfContentsSwitches.U | TableOfContentsSwitches.Z | TableOfContentsSwitches.H,
                                               "Heading4");

                document.Save();
                Console.WriteLine("\tCreated: InsertTableOfContentWithReference.docx\n");
            }
        }
Esempio n. 7
0
        public void crearwordRegistroproyecto()
        {
            string destinipath = "Formatos\\" + solicitante.NoControl;

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

            DocX testTemplate = DocX.Load(@"Templatesformatos\Registrodeproyecto.docx");
            //Paragraph p = testTemplate.InsertParagraph("Hello World.");

            DocX testDoc = testTemplate;

            //Paragraph pa = testDoc.InsertParagraph("Foo.");
            try
            {
                testDoc.ReplaceText("{fecha}", DateTime.Now.Date.ToString());
                testDoc.ReplaceText("{correoelectronico}", solicitante.Correo);
                testDoc.ReplaceText("{numtelefono}", solicitante.Telefono);
                testDoc.ReplaceText("{nombreproyecto}", solicitante.Proyecto_Residencia.Nombre_Proyecto);
                testDoc.ReplaceText("{nombreestudiante}", solicitante.Nombre + " " + solicitante.Apellido_Paterno + " " + solicitante.Apellido_Materno);
                testDoc.ReplaceText("{numestudiantes}", "1");
                testDoc.ReplaceText("{asesorinterno}", solicitante.Proyecto_Residencia.Asesor_Interno.Nombre);
                testDoc.ReplaceText("{nombreempresa}", solicitante.Proyecto_Residencia.Nombre_de_la_Empresa);
                testDoc.ReplaceText("{nocontrol}", solicitante.NoControl.ToString());
            }
            catch { }



            testDoc.SaveAs(destinipath + @"\Registrodeproyecto" + solicitante.NoControl + ".docx");
            testTemplate.Save();
        }
Esempio n. 8
0
        public void crearwordconstanciarevisores()
        {
            string destinipath = "Formatos\\" + solicitante.NoControl;

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

            DocX testTemplate = DocX.Load(@"Templatesformatos\constanciarevisores.docx");
            //Paragraph p = testTemplate.InsertParagraph("Hello World.");

            DocX testDoc = testTemplate;

            //Paragraph pa = testDoc.InsertParagraph("Foo.");
            try
            {
                testDoc.ReplaceText("{nombrealumno}", solicitante.Nombre + " " + solicitante.Apellido_Paterno + " " + solicitante.Apellido_Materno);
                testDoc.ReplaceText("{nocontrol}", solicitante.NoControl.ToString());
                testDoc.ReplaceText("{nombreproyecto}", solicitante.Proyecto_Residencia.Nombre_Proyecto);
                testDoc.ReplaceText("{nombreempresa}", solicitante.Proyecto_Residencia.Nombre_de_la_Empresa);
                testDoc.ReplaceText("{nombreasesorinterno}", solicitante.Proyecto_Residencia.Asesor_Interno.Nombre);
                testDoc.ReplaceText("{nombreasesorexterno}", solicitante.Proyecto_Residencia.Nombre_Asesor_Externo);
            }
            catch { }



            testDoc.SaveAs(destinipath + @"\constanciarevisores" + solicitante.NoControl + ".docx");
            testTemplate.Save();
        }
Esempio n. 9
0
        private static void LineChart()
        {
            // Create new document.
            using (DocX document = DocX.Create(@"docs\LineChart.docx"))
            {
                // Create chart.
                LineChart c = new LineChart();
                c.AddLegend(ChartLegendPosition.Bottom, false);

                // Create data.
                List <ChartData> company1 = ChartData.CreateCompanyList1();
                List <ChartData> company2 = ChartData.CreateCompanyList2();

                // Create and add series
                Series s1 = new Series("Microsoft");
                s1.Color = Color.GreenYellow;
                s1.Bind(company1, "Mounth", "Money");
                c.AddSeries(s1);
                Series s2 = new Series("Apple");
                s2.Bind(company2, "Mounth", "Money");
                c.AddSeries(s2);

                // Insert chart into document
                document.InsertParagraph("Diagram").FontSize(20);
                document.InsertChart(c);
                document.Save();
            }
        }
        private void MyFunc()
        {
            var list = new OpstiUsloviDa().Prep();

            foreach (var item in list)
            {
                if (item.Length > 3)
                {
                    var downloadDirectory = HttpRuntime.AppDomainAppPath + "Uslovi\\";
                    if (!Directory.Exists(downloadDirectory))
                    {
                        Directory.CreateDirectory(downloadDirectory);
                    }
                    var    outFileName     = string.Format("pu_{0}.docx", item);
                    string docTemplatePath = HttpRuntime.AppDomainAppPath + "Templates\\blank_0.docx";
                    string docOutputPath   = downloadDirectory + outFileName;
                    ////create copy of template so that we don't overwrite it
                    File.Copy(docTemplatePath, docOutputPath);
                    // Load a .docx file
                    using (DocX document = DocX.Load(docOutputPath))
                    {
                        var imetabela = item.Split('_')[0];
                        var stranici  = item.Split('_')[1];
                        foreach (var grupa in stranici.Split(';'))
                        {
                            int start = 0;
                            int stop  = 0;
                            if (grupa.Contains('-'))
                            {
                                start = int.Parse(grupa.Split('-')[0]);
                                stop  = int.Parse(grupa.Split('-')[1]);
                            }
                            else
                            {
                                start = stop = int.Parse(grupa);
                            }
                            for (int i = start; i <= stop; i++)
                            {
                                try
                                {
                                    Image image =
                                        document.AddImage(downloadDirectory + "izvod\\" + imetabela + "\\" + "uslovi_" +
                                                          i +
                                                          ".jpg");
                                    var picture   = image.CreatePicture(1100, 778);
                                    var paragraph = document.InsertParagraph("", false);
                                    paragraph.InsertPicture(picture);
                                    paragraph.Alignment = Alignment.center;
                                }
                                catch (Exception ex)
                                {
                                    Logger.Error(ex);
                                }
                            }
                        }
                        document.Save();
                    }
                }
            }
        }
Esempio n. 11
0
        private void UpdateDoc(DocX doc, FileContent fileCnt)
        {
            //1、页眉
            //logo
            if (fileCnt.logo.IsNotEmpty() && File.Exists(fileCnt.logo))
            {
                Novacode.Image img = doc.AddImage(fileCnt.logo);
                AddLogoToHeader(doc.Headers.odd, img);
                AddLogoToHeader(doc.Headers.first, img, 100, 100);
            }

            doc.ReplaceText("A2", fileCnt.filename);
            doc.ReplaceText("A3", fileCnt.filecode);
            doc.ReplaceText("A4", fileCnt.versioncode);
            doc.ReplaceText("A5", fileCnt.efdate);

            //2、表格
            doc.ReplaceText("A6", fileCnt.draftdept);
            doc.ReplaceText("A7", fileCnt.checkdept1);
            doc.ReplaceText("A8", fileCnt.checkdept2);
            doc.ReplaceText("A9", fileCnt.checkdept3);
            doc.ReplaceText("A10", fileCnt.approver);

            doc.ReplaceText("A11", "1");
            doc.ReplaceText("A12", fileCnt.remark);
            doc.ReplaceText("A13", fileCnt.writer);

            doc.Save();
        }
Esempio n. 12
0
        //added by LIUJIE 2017-09-18
        /// <summary>
        /// 插入图片及图片注释(对图片尺寸没有要求)
        /// </summary>
        /// <param name="oldPath">添加的doc路径</param>
        /// <param name="oPath">添加图片的数组</param>
        /// <param name="replaceFlag">替换符</param>
        /// <param name="oRemark">图片备注数组</param>
        public void AddWordPic(string oldPath, object[] oPath, string replaceFlag, object[] oRemark)
        {
            DocX      oldDocument = DocX.Load(oldPath);
            Paragraph ss          = null;

            Novacode.Image img = null;
            ss = GetParagraphByReplaceFlag(oldDocument, replaceFlag, "CENTER");
            ss.ReplaceText(replaceFlag, "");
            if (!(oPath == null || oRemark == null))
            {
                try
                {
                    string[] imagePath = classLims_NPOI.dArray2String1(oPath);
                    string[] remark    = classLims_NPOI.dArray2String1(oRemark);
                    for (int i = 0; i < imagePath.Length; i++)
                    {
                        img = oldDocument.AddImage(imagePath[i]);
                        Picture pic = img.CreatePicture();
                        ss.AppendPicture(pic);
                        pic.Height = Convert.ToInt32(Convert.ToDouble(pic.Height) / Convert.ToDouble(pic.Width) * Convert.ToDouble(oldDocument.PageWidth));
                        pic.Width  = Convert.ToInt32(Convert.ToDouble(oldDocument.PageWidth));
                        ss.AppendLine(remark[i] + "\n");
                        //ss.AppendLine("\n");
                        ss.Alignment = Alignment.center;
                    }
                }
                catch (System.InvalidOperationException e)
                {
                    classLims_NPOI.WriteLog(e, "");
                    return;
                }
            }
            oldDocument.Save();
            return;
        }
Esempio n. 13
0
        public ActionResult Generate(JIUViewModel model)
        {
            //get temp name from reg expression plus lang plus symb
            string fname = model.tempname.ToString();

            g_assembly = Assembly.GetExecutingAssembly();

            //   string source = Server.MapPath(Path.Combine("/", "IN/" + fname + ".docx"));
            //  string Dest = Server.MapPath(Path.Combine("/", "OUT/" + fname + ".docx"));

            string source = Server.MapPath(Path.Combine("/", "GDGS/IN/" + fname + ".docx"));
            string Dest   = Server.MapPath(Path.Combine("/", "GDGS/OUT/" + fname + ".docx"));

            string tempname = fname.Remove(fname.Length - 1);

            model.tempname = tempname;
            g_document     = DocX.Load(source);
            g_document     = CreateDocA(DocX.Load(source), model, source);

            g_document.SaveAs(Dest);
            g_document.AddCoreProperty("dc:title", model.Sym.ToString());
            // g_document.AddCoreProperty("dc:author", model.Sym.ToString());
            g_document.Save();
            //   Changegdoc(source);
            return(RedirectToAction("download", "JIU", new { name = fname }));
        }
Esempio n. 14
0
        /// <summary>
        /// Set different Heading type for a Paragraph.
        /// </summary>
        public static void Heading()
        {
            Console.WriteLine("\tHeading()");

            // Create a document.
            using (DocX document = DocX.Create(ParagraphSample.ParagraphSampleOutputDirectory + @"Heading.docx"))
            {
                // Add a title.
                document.InsertParagraph("Heading types").FontSize(15d).SpacingAfter(50d).Alignment = Alignment.center;

                var headingTypes = Enum.GetValues(typeof(HeadingType));

                foreach (HeadingType heading in headingTypes)
                {
                    // Set a text containing the current Heading type.
                    var text = string.Format("This Paragraph is using \"{0}\" heading type.", heading.EnumDescription());
                    // Add a paragraph.
                    var p = document.InsertParagraph().AppendLine(text);
                    // Set the paragraph's heading type.
                    p.Heading(heading);
                }

                document.Save();
                Console.WriteLine("\tCreated: Heading.docx\n");
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Create a document and add a paragraph with all its lines on the same page as the next paragraph.
        /// </summary>
        public static void ForceMultiParagraphsOnSinglePage()
        {
            Console.WriteLine("\tForceMultiParagraphsOnSinglePage()");

            // Create a new document.
            using (DocX document = DocX.Create(ParagraphSample.ParagraphSampleOutputDirectory + @"ForceMultiParagraphsOnSinglePage.docx"))
            {
                // Add a title.
                document.InsertParagraph("Keeps Paragraphs on same page").FontSize(15d).SpacingAfter(50d).Alignment = Alignment.center;

                // Create a Paragraph that will appear on 1st page.
                var p = document.InsertParagraph("This is a paragraph on first page.\nLine2\nLine3\nLine4\nLine5\nLine6\nLine7\nLine8\nLine9\nLine10\nLine11\nLine12\nLine13\nLine14\nLine15\nLine16\nLine17\nLine18\nLine19\nLine20\nLine21\nLine22\n");
                p.FontSize(15).SpacingAfter(30);

                // Create a Paragraph where all its lines will appear on a same page as the next paragraph.
                var p2 = document.InsertParagraph("This is a paragraph where all its lines are on the same page as the next paragraph.\nLine2\nLine3\nLine4\nLine5\nLine6\nLine7\nLine8\nLine9\nLine10");
                p2.SpacingAfter(30);

                // Indicate that this paragraph will be on the same page as the next paragraph.
                p2.KeepWithNextParagraph();

                // Create a Paragraph that will appear on 2nd page.
                var p3 = document.InsertParagraph("This is a paragraph on second page.\nLine2\nLine3\nLine4\nLine5\nLine6\nLine7\nLine8\nLine9\nLine10");

                // Indicate that all this paragraph's lines will be on the same page.
                p3.KeepLinesTogether();

                // Save this document to disk.
                document.Save();
                Console.WriteLine("\tCreated: ForceMultiParagraphsOnSinglePage.docx\n");
            }
        }
Esempio n. 16
0
        static void Main(string[] args)
        {
            var imageFolderPath = @"c:\temp\image\z1";

            var imageFiles = new List <string>();

            string[] filePaths = Directory.GetFiles(imageFolderPath, "*.*", SearchOption.AllDirectories);
            foreach (var fp in filePaths)
            {
                if (Regex.IsMatch(fp.ToLower(), @".jpg|.png|.gif$"))
                {
                    imageFiles.Add(fp);
                }
            }


            using (DocX document = DocX.Create(@"c:\temp\image\test.docx"))
            {
                document.SetTitle("tytuł");
                document.SetPageMargins();

                int imageIndex = 1;
                int imageCount = imageFiles.Count;

                foreach (var fp in imageFiles.OrderBy(fp => fp))
                {
                    //document.AddPicture(fp, title: $"{fp}\r\n");
                    document.AddPicture(fp);
                    Console.WriteLine($"Added image {imageIndex++} / {imageCount} ({fp}).");
                }

                document.Save();
            }
        }
Esempio n. 17
0
        public void crearwordasignarrevisor()
        {
            string destinipath = "Formatos\\" + solicitante.NoControl;

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

            DocX testTemplate = DocX.Load(@"Templatesformatos\asignarevisor.docx");
            //Paragraph p = testTemplate.InsertParagraph("Hello World.");

            DocX testDoc = testTemplate;

            //Paragraph pa = testDoc.InsertParagraph("Foo.");

            testDoc.ReplaceText("{nombreproyecto}", solicitante.Proyecto_Residencia.Nombre_Proyecto);

            testDoc.ReplaceText("{Nombrealumno}", solicitante.Nombre + " " + solicitante.Apellido_Paterno + " " + solicitante.Apellido_Materno);



            testDoc.SaveAs(destinipath + @"\asignarevisor" + solicitante.NoControl + ".docx");
            testTemplate.Save();
        }
Esempio n. 18
0
        /// <summary>
        /// For each of the documents in the folder 'docs\',
        /// Replace the string a with the string b,
        /// Do this in Parrallel accross many CPU cores.
        /// </summary>
        static void ReplaceTextParallel()
        {
            Console.WriteLine("\tReplaceTextParallel()\n");
            const string a = "apple";
            const string b = "pear";

            // Directory containing many .docx documents.
            DirectoryInfo di = new DirectoryInfo(@"docs\");

            // Loop through each document in this specified direction.
            Parallel.ForEach
            (
                di.GetFiles(),
                currentFile =>
            {
                // Load the document.
                using (DocX document = DocX.Load(currentFile.FullName))
                {
                    // Replace text in this document.
                    document.ReplaceText(a, b);

                    // Save changes made to this document.
                    document.Save();
                }     // Release this document from memory.
            }
            );
            Console.WriteLine("\tCreated: None\n");
        }
Esempio n. 19
0
        public void crearwordasignacionasesorinterno()
        {
            string destinipath = "Formatos\\" + solicitante.NoControl;

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

            DocX testTemplate = DocX.Load(@"Templatesformatos\Asignacionasesorinterno.docx");
            //Paragraph p = testTemplate.InsertParagraph("Hello World.");

            DocX testDoc = testTemplate;

            //Paragraph pa = testDoc.InsertParagraph("Foo.");
            try
            {
                testDoc.ReplaceText("{nombrealumno}", solicitante.Nombre + " " + solicitante.Apellido_Paterno + " " + solicitante.Apellido_Materno);
                testDoc.ReplaceText("{correoalumno}", solicitante.Correo);
                testDoc.ReplaceText("{telefonoalumno}", solicitante.Telefono);
                testDoc.ReplaceText("{nombreproyecto}", solicitante.Proyecto_Residencia.Nombre_Proyecto);
                testDoc.ReplaceText("{nombreempresa}", solicitante.Proyecto_Residencia.Nombre_de_la_Empresa);
                testDoc.ReplaceText("{telefonoasesor}", solicitante.Proyecto_Residencia.Telefono_Asesor_Externo);
                testDoc.ReplaceText("{nombreasesor}", solicitante.Proyecto_Residencia.Nombre_Asesor_Externo);
                testDoc.ReplaceText("{cargoasesor}", solicitante.Proyecto_Residencia.Cargo_Asesor_Externo);
            }
            catch { }



            testDoc.SaveAs(destinipath + @"\Asignacionasesorinterno" + solicitante.NoControl + ".docx");
            testTemplate.Save();
        }
Esempio n. 20
0
            public async Task <Result> Handle(Command request, CancellationToken cancellationToken)
            {
                var extactor   = ExtractorFactory.GetExtraactor(request.Url);
                var chordsheet = await extactor.GetChordSheetText(request.Url);

                if (!string.IsNullOrEmpty(request.NewKey))
                {
                    var transposer = new Transposer();
                    chordsheet = await transposer.ChangeKey(chordsheet, request.NewKey, request.OriginalKey);
                }

                using (DocX document = DocX.Create(request.DestinationFilename))
                {
                    document.MarginTop    = 36f;
                    document.MarginBottom = 36f;
                    document.MarginLeft   = 36f;
                    document.MarginRight  = 36f;

                    // Add a new Paragraph to the document.
                    var p = document.InsertParagraph();

                    // Append some text.
                    p.Append(chordsheet).Font("Courier New");

                    // Save the document.
                    document.Save();
                }

                return(new Result {
                    OutputFilename = request.DestinationFilename
                });
            }
Esempio n. 21
0
        public void crearwordsolicitudresidencia()
        {
            string destinipath = "Formatos\\" + solicitante.NoControl;

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

            DocX testTemplate = DocX.Load(@"Templatesformatos\solicitudresidencia.docx");
            //Paragraph p = testTemplate.InsertParagraph("Hello World.");

            DocX testDoc = testTemplate;

            //Paragraph pa = testDoc.InsertParagraph("Foo.");

            testDoc.ReplaceText("{Fecha}", DateTime.Now.Date.ToString());
            testDoc.ReplaceText("{Nombreproyecto}", solicitante.Proyecto_Residencia.Nombre_Proyecto);
            testDoc.ReplaceText("{nombreempresa}", solicitante.Proyecto_Residencia.Nombre_de_la_Empresa);
            testDoc.ReplaceText("{Asesorexterno}", solicitante.Proyecto_Residencia.Nombre_Asesor_Externo);
            testDoc.ReplaceText("{cargoasesor}", solicitante.Proyecto_Residencia.Cargo_Asesor_Externo);
            testDoc.ReplaceText("{asesorexterno}", solicitante.Proyecto_Residencia.Nombre_Asesor_Externo);
            testDoc.ReplaceText("{cargoasesorexterno}", solicitante.Proyecto_Residencia.Cargo_Asesor_Externo);
            testDoc.ReplaceText("{nombrealumno}", solicitante.Nombre + " " + solicitante.Apellido_Paterno + " " + solicitante.Apellido_Materno);
            testDoc.ReplaceText("{Nocontrol}", solicitante.NoControl.ToString());
            testDoc.ReplaceText("{Correoalumno}", solicitante.Correo);
            testDoc.ReplaceText("{telefonoalumno}", solicitante.Telefono);


            testDoc.SaveAs(destinipath + @"\Solicitudresidencia" + solicitante.NoControl + ".docx");
            testTemplate.Save();
        }
Esempio n. 22
0
        /// <summary>
        /// Add a Pie chart to a document.
        /// </summary>
        public static void PieChart()
        {
            Console.WriteLine("\tPieChart()");

            // Creates a document
            using (DocX document = DocX.Create(ChartSample.ChartSampleOutputDirectory + @"PieChart.docx"))
            {
                // Add a title
                document.InsertParagraph("Pie Chart").FontSize(15d).SpacingAfter(50d).Alignment = Alignment.center;

                // Create a pie chart.
                var c = new PieChart();
                c.AddLegend(ChartLegendPosition.Left, false);

                // Create the data.
                var brazil = ChartData.CreateBrazilExpenses();

                // Create and add series
                var s1 = new Series("Canada");
                s1.Bind(brazil, "Category", "Expenses");
                c.AddSeries(s1);

                // Insert chart into document
                document.InsertParagraph("Expenses(M$) for selected categories in Canada").FontSize(15).SpacingAfter(10d);
                document.InsertChart(c);

                document.Save();
                Console.WriteLine("\tCreated: PieChart.docx\n");
            }
        }
        public void CopyFromFile_Test_CopiesCorrectHyperlinksToBookmarks()
        {
            _tmpFile = GetNewRandomFilePath(GetOrCreateTmpDirectory());
            using (DocX doc = DocX.Create(_tmpFile)) {
                Hyperlink hyperlink = doc.AddHyperlink("hypelink text", "bookmark");
                doc.InsertParagraph()
                .AppendBookmark("bookmark")
                .Append("bookmark text");
                doc.InsertParagraph()
                .AppendHyperlink(hyperlink);
                doc.Save();
            }

            Range targetRange = _application.Documents.Add().Range();

            targetRange.Text = "unexpected";

            new OpenXmlHelper().CopyFromFile(_tmpFile, targetRange);

            Bookmarks  bookmarks  = targetRange.Document.Bookmarks;
            Hyperlinks hyperlinks = targetRange.Document.Hyperlinks;

            Assert.NotZero(bookmarks.Count);
            Assert.NotZero(hyperlinks.Count);
            Assert.That(hyperlinks[1].SubAddress, Is.EqualTo(bookmarks[1].Name));
        }
Esempio n. 24
0
        /// <summary>
        /// Add a 3D bar chart to a document.
        /// </summary>
        ///
        public static void Chart3D()
        {
            Console.WriteLine("\tChart3D)");

            // Creates a document
            using (DocX document = DocX.Create(ChartSample.ChartSampleOutputDirectory + @"3DChart.docx"))
            {
                // Add a title
                document.InsertParagraph("3D Chart").FontSize(15d).SpacingAfter(50d).Alignment = Alignment.center;

                // Create a 3D Bar chart.
                var c = new BarChart();
                c.View3D = true;

                // Create the data.
                var brazil = ChartData.CreateBrazilExpenses();

                // Create and add series
                var s1 = new Series("Brazil");
                s1.Color = Color.GreenYellow;
                s1.Bind(brazil, "Category", "Expenses");
                c.AddSeries(s1);

                // Insert chart into document
                document.InsertParagraph("Expenses(M$) for selected categories in Brazil").FontSize(15).SpacingAfter(10d);
                document.InsertChart(c);

                document.Save();
                Console.WriteLine("\tCreated: 3DChart.docx\n");
            }
        }
Esempio n. 25
0
        /// <summary>
        /// Add margins for a document.
        /// </summary>
        public static void Margins()
        {
            Console.WriteLine("\tMargins()");

            // Create a document.
            using (DocX document = DocX.Create(MarginSample.MarginSampleOutputDirectory + @"Margins.docx"))
            {
                // Add a title.
                document.InsertParagraph("Document margins").FontSize(15d).SpacingAfter(50d).Alignment = Alignment.center;

                // Set the page width to be smaller.
                document.PageWidth = 350f;

                // Set the document margins.
                document.MarginLeft   = 85f;
                document.MarginRight  = 85f;
                document.MarginTop    = 0f;
                document.MarginBottom = 50f;

                // Add a paragraph. It will be affected by the document margins.
                var p = document.InsertParagraph("This is a paragraph from a document with a left margin of 85, a right margin of 85, a top margin of 0 and a bottom margin of 50.");

                document.Save();
                Console.WriteLine("\tCreated: Margins.docx\n");
            }
        }
Esempio n. 26
0
        private void reportItem_Click(object sender, EventArgs e)
        {
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                DocX      document  = DocX.Create(saveFileDialog.FileName);
                Paragraph paragraph = document.InsertParagraph();
                paragraph.FontSize(14);
                paragraph.Append(DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss"));
                paragraph.AppendLine("Отчет за месяц").Alignment = Alignment.center;
                Paragraph content = document.InsertParagraph();
                using (MySqlApplicationContext db = new MySqlApplicationContext())
                {
                    content.Append("Количество выполненных проектов:");
                    foreach (ProjectType item in db.ProjectTypes.Include(item => item.Projects)
                             .ThenInclude(item => item.ProjectStatus).ToList())
                    {
                        content.AppendLine(item.Name + ": " + item.Projects.Count(project =>
                                                                                  project.ProjectStatus.Name == "Готово" &&
                                                                                  project.FinishDate.Month == DateTime.Now.Month));
                    }

                    content.AppendLine("Заработано денег: " + db.Projects.Include(item => item.ProjectType)
                                       .Include(item => item.ProjectStatus)
                                       .Where(item =>
                                              item.FinishDate.Month == DateTime.Now.Month &&
                                              item.ProjectStatus.Name == "Готово")
                                       .Sum(item => item.ProjectType.Price));
                }

                document.Save();
            }
        }
Esempio n. 27
0
        /// <summary>
        /// Add indentations on paragraphs.
        /// </summary>
        public static void Indentation()
        {
            Console.WriteLine("\tIndentation()");

            // Create a document.
            using (DocX document = DocX.Create(MarginSample.MarginSampleOutputDirectory + @"Indentation.docx"))
            {
                // Add a title.
                document.InsertParagraph("Paragraph indentation").FontSize(15d).SpacingAfter(50d).Alignment = Alignment.center;

                // Set a smaller page width.
                document.PageWidth = 250f;

                // Add the first paragraph.
                var p = document.InsertParagraph("This is the first paragraph. It doesn't contain any indentation.");
                p.SpacingAfter(30);

                // Add the second paragraph.
                var p2 = document.InsertParagraph("This is the second paragraph. It contains an indentation on the first line.");
                // Indent only the first line of the Paragraph.
                p2.IndentationFirstLine = 1.0f;
                p2.SpacingAfter(30);

                // Add the third paragraph.
                var p3 = document.InsertParagraph("This is the third paragraph. It contains an indentation on all the lines except the first one.");
                // Indent all the lines of the Paragraph, except the first.
                p3.IndentationHanging = 1.0f;

                document.Save();
                Console.WriteLine("\tCreated: Indentation.docx\n");
            }
        }
Esempio n. 28
0
        protected void SaveDOCX_Click(object sender, EventArgs e)
        {
            try
            {
                if (File.Exists(Server.MapPath("Deciper\\Program\\") + "AppDataDocx.docx"))
                {
                    File.Delete(Server.MapPath("Deciper\\Program\\") + "AppDataDocx.docx");
                }
                string pathDocument = Server.MapPath("Deciper\\Program\\") + "AppDataDocx.docx";

                // создаём документ
                DocX document = DocX.Create(pathDocument);



                // вставляем параграф и передаём текст
                document.InsertParagraph(data.DeciperData).
                // устанавливаем шрифт
                Font("Calibri").
                // устанавливаем размер шрифта
                FontSize(36);

                // сохраняем документ
                document.Save();
                Response.Redirect(@"/Deciper/Program/" + "AppDataDocx.docx");
            }
            finally
            {
            }
        }
Esempio n. 29
0
        static void Main(string[] args)
        {
            //EPPlus (excel lib)

            DocX report = DocX.Create("Report.docx", DocumentTypes.Document);


            var paragraph = report.InsertParagraph("YoY Value Report", false,
                                                   new Formatting()
            {
                Bold = true
            });

            report.InsertParagraph();
            report.InsertParagraph();

            var table = report.InsertTable(2, 3);

            table.Rows[0].Cells[0].InsertParagraph("Year");
            table.Rows[0].Cells[1].InsertParagraph("Value");
            table.Rows[0].Cells[2].InsertParagraph("Remarks");

            table.Design = TableDesign.ColorfulList;

            report.Save();
            report.Dispose();
        }
Esempio n. 30
0
        public void ToReport(string filePath, int language)
        {
            List <string> tableString = new List <string>();

            tableString.Add("Table: ");
            tableString.Add("Таблиця: ");
            tableString.Add("Таблица: ");
            List <string> databaseString = new List <string>();

            databaseString.Add("Database: ");
            databaseString.Add("База даних: ");
            databaseString.Add("База данных: ");
            List <string> tablesString = new List <string>();

            tablesString.Add("Tables: ");
            tablesString.Add("Таблиць: ");
            tablesString.Add("Таблиц: ");
            List <string> dateString = new List <string>();

            dateString.Add("Creation date: ");
            dateString.Add("Дата створення: ");
            dateString.Add("Дата создания: ");
            DocX doc = DocX.Create(filePath);

            doc.InsertParagraph(databaseString[language] + name + "        " + tablesString[language] + tables.Count + "        " + dateString[language] + DateTime.Now + "\r\n");
            foreach (Table tbl in tables)
            {
                doc.InsertParagraph(tableString[language] + tbl.ToString() + "\r\n");
                tbl.ToReport(filePath, ref doc, language);
            }
            doc.Save();
        }