Пример #1
0
        public void OpenReplaceSimple()
        {
            string fileName       = "replace-simple-1";
            string fileTargetPath = Path.Combine(s_BasePath, fileName + ".docx");

            using (WordServerDocument doc = new WordServerDocument())
            {
                File.Copy($"{s_BasePath}\\SimpleDocument.docx", fileTargetPath, true);

                Assert.AreEqual(doc.Open(fileTargetPath, out _), OutputCode.OK);

                doc.AddText("Text to be replaced", new List <string>());
                doc.AddText("Start Programmatically: " + DateTime.Now, new List <string>());

                doc.ReplaceText("Aggregate", "AggregateReplacedText", false);
                doc.ReplaceTextWithStyle("clarati", "YYYYY", false, new List <string>()
                {
                    "fontsize:20", "color:red"
                });

                doc.ReplaceTextWithStyle("Text to BE REPLACED", "ReplacedTextOK", false, new List <string>()
                {
                    "fontsize:25", "color:blue"
                });

                doc.AddText("End Programmatically: " + DateTime.Now, new List <string>());

                doc.Save();
            }
            ExtractXlsx(fileTargetPath, Path.Combine(s_BasePath, fileName));
        }
Пример #2
0
        public void ReplaceComplexTextNoStyle()
        {
            string fileName       = "replaced-complex-test-no-style-2";
            string fileTargetPath = Path.Combine(s_BasePath, fileName + ".docx");

            using (WordServerDocument doc = new WordServerDocument())
            {
                File.Copy($"{s_BasePath}\\SampleFull.docx", fileTargetPath, true);

                Assert.AreEqual(doc.Open(fileTargetPath, out _), OutputCode.OK);

                // Assert.IsTrue(doc.ReplaceText("Aggregate", "AggregateReplacedText", false) > 0);
                Assert.IsTrue(doc.ReplaceTextWithStyle("Declaration", "OtherText", true, new List <string>()
                {
                    "fontsize:54", "color:pink"
                }) > 0);

                Assert.IsTrue(doc.ReplaceTextWithStyle("onsumed", "ONSUMED", true, new List <string>()
                {
                    "fontsize:20", "color:pink"
                }) > 0);

                doc.AddText("FAX:", new List <string>()
                {
                    "fontsize:54", "color:pink"
                });

                doc.Save();
            }
            ExtractXlsx(fileTargetPath, Path.Combine(s_BasePath, fileName));
        }
Пример #3
0
        public void CreateReplaceSimple()
        {
            string fileName       = "create-replace-simple-1";
            string fileTargetPath = Path.Combine(s_BasePath, fileName + ".docx");

            using (WordServerDocument doc = new WordServerDocument())
            {
                Assert.AreEqual(doc.Create(fileTargetPath, true, out _), OutputCode.OK);

                doc.AddText("Text with no Bold no formatting style", new List <string>());
                doc.AddText("Text with Bold", new List <string>()
                {
                    "bold"
                });
                doc.AddText("Text with bold and italic", new List <string>()
                {
                    "bold", "italic"
                });
                doc.AddText("Text with bold and italic and red color", new List <string>()
                {
                    "bold", "italic", "color:red"
                });

                Assert.AreEqual(doc.ReplaceTextWithStyle("bold", "BOLD", false, new List <string>()
                {
                    "color:blue"
                }), 4);

                doc.Save();
            }
            ExtractXlsx(fileTargetPath, Path.Combine(s_BasePath, fileName));
        }
Пример #4
0
        public void ReplaceAndAddWithStyle()
        {
            using (WordServerDocument doc = new WordServerDocument())
            {
                File.Copy($"{s_BasePath}\\TemplateSample.docx", $"{s_BasePath}\\Sample.docx", true);

                Assert.AreEqual(doc.Open($"{s_BasePath}\\Sample.docx", out _), OutputCode.OK);

                Assert.AreEqual(doc.ReplaceTextWithStyle("REP01", "新潟県新潟市", true, new List <string>()
                {
                    "color:blue", "italic", "fontsize:24", "fontfamily:MS PMincho"
                }), 2);
                Assert.AreEqual(doc.ReplaceTextWithStyle("REP02", "中央区米山", true, new List <string>()
                {
                    "italic", "bold", "color:green", "fontfamily:MS PGothic"
                }), 1);
                Assert.AreEqual(doc.ReplaceTextWithStyle("REP03", "Remplazo con bold blue italic", true, new List <string>()
                {
                    "italic", "bold", "color:blue"
                }), 1);


                doc.AddText("製品企画室", new List <string>()
                {
                    "fontsize:110"
                });
                doc.AddText("TEL:", new List <string>()
                {
                    "italic"
                });
                doc.AddText("FAX:", new List <string>()
                {
                    "fontsize:54", "color:pink"
                });

                doc.Save();
            }
        }