Exemplo n.º 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));
        }
Exemplo n.º 2
0
        public void AppendAndReplace()
        {
            using (WordServerDocument doc = new WordServerDocument())
            {
                string fileTargetPath = $"{s_BasePath}\\append-replace-test.docx";

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

                Assert.AreEqual(doc.AddText("Aggregate", new List <string>()), OutputCode.OK);
                Assert.AreEqual(doc.AddText("Declaration", new List <string>()), OutputCode.OK);
                doc.ReplaceText("Aggregate", "AggregateReplacedText", false);
                doc.ReplaceText("Declaration", "OtherText", false);

                doc.Save();
            }
        }