public void ChangeFooter() { const string bookmarkName = "footer_table1"; const string val = "Пользователь"; IBSDataObject bo = new BsDataObjectMock("TestBo"); var printParams = new Params(); printParams.SetParams("BookmarkName", bookmarkName); var printScript = new StringBuilder(); printScript.Append("var wordDoc = (IWordDocument) args[1];"); printScript.Append("var p = new ParamsMock(args[3]);"); printScript.Append("var bkmName = (string) p.GetValue(\"BookmarkName\", \"\");"); printScript.Append("var bkms = (IWordDocumentBookmarks) wordDoc.Bookmarks;"); printScript.Append($"bkms.Item(bkmName).Text = \"{val}\";"); var printService = KonturPrintService; var printServiceParams = new Params(); printServiceParams.SetParams("Bo", bo); printServiceParams.SetParams("TemplatePath", templatePath); printServiceParams.SetParams("FileName", tmpPath); printServiceParams.SetParams("ErrorStr", ""); printServiceParams.SetParams("Params", printParams); printService.PrintScripts = new[] { printScript.ToString() }; Assert.IsTrue(printService.Print((int)PrintDocumentType.WordTemplate, printServiceParams)); using (var doc = WordprocessingDocument.Open(tmpPath, false)) { var bookmarks = new WordDocumentBookmarks(doc); Assert.AreEqual(bookmarks.Item(bookmarkName).Text, val); } }
public void FillWordTable() { const string bookmarkName = "fondsalary_table"; const string partName = "Main"; IBSDataObject bo = new BsDataObjectMock("TestBo"); var parts = bo.Parts as PartsMock; parts.AddItem(partName, new SKRecordsetMock()); var part = parts.Item(partName); part.AddNew(new object[] { "Field1", "Field2", "Field3" }, new object[] { "оклад", "руб.", "1000" }); part.AddNew(new object[] { "Field1", "Field2", "Field3" }, new object[] { "премия", "руб.", "2000" }); part.AddNew(new object[] { "Field1", "Field2", "Field3" }, new object[] { "отпускные", "руб.", "3000" }); var printParams = new Params(); printParams.SetParams("BookmarkName", bookmarkName); printParams.SetParams("Parts", parts); printParams.SetParams("PartName", partName); var printScript = new StringBuilder(); printScript.Append("var wordDoc = (IWordDocument) args[1];\r\n"); printScript.Append("var p = new ParamsMock(args[3]);\r\n"); printScript.Append("var parts = (PartsMock) p.GetValue(\"parts\", (PartsMock) null);\r\n"); printScript.Append("var bkmName = (string) p.GetValue(\"BookmarkName\", \"\");\r\n"); printScript.Append("var partName = (string) p.GetValue(\"PartName\", \"\");\r\n"); printScript.Append("var bkms = (IWordDocumentBookmarks) wordDoc.Bookmarks;\r\n"); printScript.Append("var tbl = (IWordDocumentTable) bkms.Item(bkmName).Table;\r\n"); printScript.Append("var part = (SKRecordsetMock) parts.Item(partName);\r\n"); printScript.Append("part.MoveFirst();\r\n"); printScript.Append("int i = 3;\r\n"); printScript.Append("while (!part.EOF) {\r\n"); printScript.Append("tbl.Rows.Add();\r\n"); printScript.Append("i++;\r\n"); printScript.Append("for (int j = 0; j < part.Fields.Count; j++) {\r\n"); printScript.Append("var cell = tbl.Cell(i, j + 1);\r\n"); printScript.Append("cell.Text = (string) part.Fields[j].Value;}\r\n"); printScript.Append("part.MoveNext(); }\r\n"); printParams.SetParams("PrintScript", printScript.ToString()); var printService = KonturPrintService; var printServiceParams = new Params(); printServiceParams.SetParams("Bo", bo); printServiceParams.SetParams("TemplatePath", templatePath); printServiceParams.SetParams("FileName", tmpPath); printServiceParams.SetParams("ErrorStr", ""); printServiceParams.SetParams("Params", printParams); Assert.IsTrue(printService.Print((int)PrintDocumentType.WordTemplate, printServiceParams)); using (var doc = WordprocessingDocument.Open(tmpPath, false)) { var bookmarks = new WordDocumentBookmarks(doc); var tbl = bookmarks.Item(bookmarkName).Table; part.MoveFirst(); Assert.AreEqual(tbl.Cell(4, 1).Text, part.Fields[0].Value); } }
public void BookmarkExists() { using (var doc = WordprocessingDocument.Open(TemplatePath, false)) { var bookmarks = new WordDocumentBookmarks(doc); Assert.IsTrue(bookmarks.Exists("order_number")); } }
public void GetBookmarksCount() { using (var doc = WordprocessingDocument.Open(TemplatePath, false)) { var bookmarks = new WordDocumentBookmarks(doc); Assert.AreNotEqual(bookmarks.Count, 0); } }
public void GetTableByBookmarkInCell() { using (var doc = WordprocessingDocument.Open(TemplatePath, false)) { var bookmarks = new WordDocumentBookmarks(doc); var bkm = bookmarks.Item("fondsalary_table"); Assert.IsNotNull(bkm.Table); } }
public void CanSelectBookmark() { using (var doc = WordprocessingDocument.Open(TemplatePath, false)) { var bookmarks = new WordDocumentBookmarks(doc); var bkm = bookmarks.Item("order_number"); Assert.IsNotNull(bkm); } }
public void GetBookmarkColumnText() { using (var doc = WordprocessingDocument.Open(TemplatePath, false)) { var bookmarks = new WordDocumentBookmarks(doc); var bkm = bookmarks.Item("fondsalary_table_col"); Assert.AreEqual(bkm.Text, "TextInColumn"); } }
public void GetMultiLineText() { using (var doc = WordprocessingDocument.Open(TemplatePath, false)) { var bookmarks = new WordDocumentBookmarks(doc); var bkm = bookmarks.Item("multiline_bkm"); Assert.AreEqual(bkm.Text, "Несколько\r\nСтрок\r\nТекста"); } }
public void CanGetFoundBookmark() { using (var doc = WordprocessingDocument.Open(TemplatePath, false)) { var bookmarks = new WordDocumentBookmarks(doc); var bkm = bookmarks.Item("FOOTER_TABLE"); var bkm1 = bookmarks.Item("FOOTER_TABLE"); Assert.AreEqual(bkm, bkm1); } }
public override void ProcessDocument() { CheckForInitialization(); Doc = WordprocessingDocument.Open(MemStream, true); InnerDoc = (WordprocessingDocument)Doc; Bookmarks = new WordDocumentBookmarks(this); Tables = new WordDocumentTables(this); Footers = new WordDocumentFooters(this); Headers = new WordDocumentHeaders(this); PageEnumerator = new WordDocumentPageEnumerator(); }
public void GetBookmarkTableText() { using (var doc = WordprocessingDocument.Open(TemplatePath, true, new OpenSettings { AutoSave = false })) { var bookmarks = new WordDocumentBookmarks(doc); var bkm = bookmarks.Item("fondsalary_table_bkm"); Assert.IsFalse(string.IsNullOrEmpty(bkm.Text)); } }
public void GetBookmarkText() { var templatePath = System.IO.Path.Combine(TestDirectory, @"../../TestTemplate/TestTemplate.docx"); using (var doc = WordprocessingDocument.Open(templatePath, false)) { var bookmarks = new WordDocumentBookmarks(doc); var bkm = bookmarks.Item("order_caption"); Assert.AreEqual(bkm.Text, "ПРИКАЗ"); } }
public void FindCellTextInFooter() { using (var doc = WordprocessingDocument.Open(TemplatePath, true, new OpenSettings { AutoSave = false })) { var bookmarks = new WordDocumentBookmarks(doc); var bkm = bookmarks.Item("FOOTER_TABLE"); var table = bkm.Table; Assert.AreEqual(table.Cell(1, 1).Text, "составил"); } }
public void ChangePartOfColumn() { using (var doc = WordprocessingDocument.Open(TemplatePath, true, new OpenSettings { AutoSave = false })) { var bookmarks = new WordDocumentBookmarks(doc); var bkm = bookmarks.Item("bkm_part_para"); bkm.Text = "Болен"; Assert.AreEqual(bkm.Text, "Годен\r\nБолен\r\nМолод"); } }
public void SetBookmarkText() { using (var doc = WordprocessingDocument.Open(TemplatePath, true, new OpenSettings { AutoSave = false })) { var bookmarks = new WordDocumentBookmarks(doc); var bkm = bookmarks.Item("text_not_cell"); const string val = "НОВЫЙ Текст"; bkm.Text = val; Assert.AreEqual(bkm.Text, val); } }
public void ReplaceBookmarkColumnText() { using (var doc = WordprocessingDocument.Open(TemplatePath, true, new OpenSettings { AutoSave = false })) { var bookmarks = new WordDocumentBookmarks(doc); var bkm = bookmarks.Item("fondsalary_table_col"); const string val = "New Text"; bkm.Text = val; Assert.AreEqual(bkm.Text, val); } }
public void SetBookmarkMultiLineText() { using (var doc = WordprocessingDocument.Open(TemplatePath, true, new OpenSettings { AutoSave = false })) { var bookmarks = new WordDocumentBookmarks(doc); var bkm = bookmarks.Item("multiline_bkm"); const string val = "Другие\r\nНесколько\r\nстрок"; bkm.Text = val; Assert.AreEqual(bkm.Text, val); } }
public void SetBookmarkMultiLineTextInColumn() { using (var doc = WordprocessingDocument.Open(TemplatePath, true, new OpenSettings { AutoSave = false })) { var bookmarks = new WordDocumentBookmarks(doc); var bkm = bookmarks.Item("order_caption"); const string val = "НОВЫЙ\r\nПриказ"; bkm.Text = val; Assert.AreEqual(bkm.Text, val); } }
public void SetBookmarkTextByReplaceTable() { using (var doc = WordprocessingDocument.Open(TemplatePath, true, new OpenSettings { AutoSave = false })) { var bookmarks = new WordDocumentBookmarks(doc); var bkm = bookmarks.Item("fondsalary_table_bkm"); const string val = "Вместо таблицы"; bkm.Text = val; Assert.AreEqual(bkm.Text, val); } }
public void PrintWordByXMachine() { const string bookmarkName = "order_number"; const string partName = "Main"; IBSDataObject bo = new BsDataObjectMock("TestBo"); var parts = bo.Parts as PartsMock; parts.AddItem(partName, new SKRecordsetMock()); var ndoc = "4532"; ((SKRecordsetMock)parts.Item(partName)).AddNew(new object[] { "ndoc" }, new object[] { ndoc }); var printParams = new Params(); printParams.SetParams("BookmarkName", bookmarkName); printParams.SetParams("Parts", parts); printParams.SetParams("PartName", partName); printParams.SetParams("FieldName", "ndoc"); var printScript = new StringBuilder(); printScript.Append("var wordDoc = (IWordDocument) args[1];"); printScript.Append("var p = new ParamsMock(args[3]);"); printScript.Append("var parts = (PartsMock) p.GetValue(\"parts\", (PartsMock) null);"); printScript.Append("var bkmName = (string) p.GetValue(\"BookmarkName\", \"\");"); printScript.Append("var partName = (string) p.GetValue(\"PartName\", \"\");"); printScript.Append("var fldName = (string) p.GetValue(\"FieldName\", \"\");"); printScript.Append("var bkms = (IWordDocumentBookmarks) wordDoc.Bookmarks;"); printScript.Append("bkms.Item(bkmName).Text = (string) parts.Item(partName).Fields[fldName].Value;"); printParams.SetParams("PrintScript", printScript.ToString()); var printService = KonturPrintService; var printServiceParams = new Params(); printServiceParams.SetParams("Bo", bo); printServiceParams.SetParams("TemplatePath", templatePath); printServiceParams.SetParams("FileName", tmpPath); printServiceParams.SetParams("ErrorStr", ""); printServiceParams.SetParams("Params", printParams); Assert.IsTrue(printService.Print((int)PrintDocumentType.WordTemplate, printServiceParams)); using (var doc = WordprocessingDocument.Open(tmpPath, false)) { var bookmarks = new WordDocumentBookmarks(doc); Assert.AreEqual(bookmarks.Item(bookmarkName).Text, ndoc); } }
public void AddAndCopyRows() { using (var doc = WordprocessingDocument.Open(TemplatePath, true, new OpenSettings { AutoSave = false })) { var bookmarks = new WordDocumentBookmarks(doc); var table = bookmarks.Item("FOOTER_CHIEFS_TABLE").Table; var rows = table.Rows; const string val = "Директор"; table.Cell(1, 2).Text = val; rows.AddEmpty(); rows.AddEmpty(); rows.CopyRow(1); Assert.AreEqual(table.Cell(6, 2).Text, val); } }
public void PrintByPrintScripts() { const string bookmarkName = "order_number"; const string bookmarkName1 = "fondsalary_table_col"; const string text = "123"; const string text1 = "456"; IBSDataObject bo = new BsDataObjectMock("TestBo"); var printParams = new Params(); var printService = KonturPrintService; var printServiceParams = new Params(); printServiceParams.SetParams("Bo", bo); printServiceParams.SetParams("TemplatePath", templatePath); printServiceParams.SetParams("FileName", tmpPath); printServiceParams.SetParams("ErrorStr", ""); printServiceParams.SetParams("Params", printParams); var printScript = new StringBuilder(); printScript.Append("var wordDoc = (IWordDocument) args[1];"); printScript.Append("var p = new ParamsMock(args[3]);"); printScript.Append("var bkms = (IWordDocumentBookmarks) wordDoc.Bookmarks;"); printScript.Append($"bkms.Item(\"{bookmarkName}\").Text = \"{text}\";"); printParams.SetParams("PrintScript", printScript.ToString()); printScript = new StringBuilder(); printScript.Append("var wordDoc = (IWordDocument) args[1];"); printScript.Append("var p = new ParamsMock(args[3]);"); printScript.Append("var bkms = (IWordDocumentBookmarks) wordDoc.Bookmarks;"); printScript.Append($"bkms.Item(\"{bookmarkName1}\").Text = \"{text1}\";"); printService.PrintScripts = new[] { printScript.ToString() }; Assert.IsTrue(printService.Print((int)PrintDocumentType.WordTemplate, printServiceParams)); using (var doc = WordprocessingDocument.Open(tmpPath, false)) { var bookmarks = new WordDocumentBookmarks(doc); Assert.AreEqual(bookmarks.Item(bookmarkName).Text, text); Assert.AreEqual(bookmarks.Item(bookmarkName1).Text, text1); } }
public void CopyBookmark() { using (var doc = WordprocessingDocument.Open(TemplatePath, true, new OpenSettings { AutoSave = false })) { var table = new WordDocumentTable(doc); table.Select("Table1"); var bookmarks = new WordDocumentBookmarks(doc); var bkm = new WordDocumentBookmark(doc); bkm.Select("order_caption"); var dest = new PrintObject(table.Table); Assert.IsFalse(bookmarks.Exists("order_caption_copy")); bkm.CopyTo(dest); Assert.IsTrue(bookmarks.Exists("order_caption_copy")); } }
public void CopyTableToBookmark() { using (var doc = WordprocessingDocument.Open(TemplatePath, true, new OpenSettings { AutoSave = false })) { var table = new WordDocumentTable(doc); table.Select("TableForCopy"); var bookmarks = new WordDocumentBookmarks(doc); var bkm = new WordDocumentBookmark(doc); bkm.Select("table_copy"); Assert.IsNull(bookmarks.Item("table_copy").Table); bkm.GetCopyOf(table); Assert.IsFalse(string.IsNullOrEmpty(bkm.Text)); Assert.IsNotNull(bkm.Table); } }