Exemple #1
0
        public void CanSelectTableByName()
        {
            using (var doc = WordprocessingDocument.Open(TemplatePath, false))
            {
                var table = new WordDocumentTable(doc);

                Assert.IsTrue(table.Select("Table1"));
                Assert.IsNotNull(table.Table);
            }
        }
        public void CanGetRow()
        {
            using (var doc = WordprocessingDocument.Open(TemplatePath, false))
            {
                var table = new WordDocumentTable(doc);
                table.Select("Table1");
                var rows = new WordDocumentTableRows(table.Table);

                Assert.IsNotNull(rows.Item(1));
            }
        }
        public void GetRowsCount()
        {
            using (var doc = WordprocessingDocument.Open(TemplatePath, false))
            {
                var table = new WordDocumentTable(doc);
                table.Select("Table1");
                var rows = new WordDocumentTableRows(table.Table);

                Assert.AreEqual(rows.Count, 3);
            }
        }
Exemple #4
0
        public void CanGetCell()
        {
            using (var doc = WordprocessingDocument.Open(TemplatePath, false))
            {
                var table = new WordDocumentTable(doc);
                table.Select("Table1");
                var cell = table.Cell(1, 1);

                Assert.IsNotNull(cell);
            }
        }
Exemple #5
0
        public void CanSelectCell()
        {
            using (var doc = WordprocessingDocument.Open(TemplatePath, false))
            {
                var table = new WordDocumentTable(doc);
                table.Select("Table1");
                var cell = new WordDocumentTableCell(table.Table);

                Assert.IsTrue(cell.Select(1, 1));
            }
        }
Exemple #6
0
        public void GetRowCount()
        {
            using (var doc = WordprocessingDocument.Open(TemplatePath, true, new OpenSettings {
                AutoSave = false
            }))
            {
                var table = new WordDocumentTable(doc);
                table.Select("Table1");

                Assert.AreEqual(table.Rows.Count, 3);
            }
        }
Exemple #7
0
        public void GetCellText()
        {
            using (var doc = WordprocessingDocument.Open(TemplatePath, false))
            {
                var table = new WordDocumentTable(doc);
                table.Select("Table1");
                var cell = table.Cell(3, 2);
                var txt  = cell.Text;

                Assert.AreEqual(txt, "TextInColumn");
            }
        }
Exemple #8
0
        public void GetTableProperties()
        {
            using (var doc = WordprocessingDocument.Open(TemplatePath, false))
            {
                var table = new WordDocumentTable(doc);
                table.Select("Table1");
                var tp = (TableProperties)table.TableProperties;

                Assert.IsNotNull(tp);
                Assert.AreEqual(tp.TableCaption.Val.ToString(), "Table1");
            }
        }
        private void TryFindTable()
        {
            if (BkmStart == null || BkmEnd == null)
            {
                return;
            }
            var table = BkmEnd.GetParent <Table>();

            if (table != null)
            {
                Table = new WordDocumentTable(Doc, table);
            }
        }
Exemple #10
0
        public void GetTableEmptyCellText()
        {
            using (var doc = WordprocessingDocument.Open(TemplatePath, false))
            {
                var table = new WordDocumentTable(doc);
                table.Select("Table1");
                var cell = new WordDocumentTableCell(table.Table);
                cell.Select(3, 1);
                var txt = cell.Text;

                Assert.IsTrue(string.IsNullOrEmpty(txt));
            }
        }
Exemple #11
0
        public void GetTableCellProperties()
        {
            using (var doc = WordprocessingDocument.Open(TemplatePath, false))
            {
                var table = new WordDocumentTable(doc);
                table.Select("Table1");
                var cell = new WordDocumentTableCell(table.Table);
                cell.Select(1, 1);
                var cp = (TableCellProperties)cell.CellProperties;

                Assert.IsNotNull(cp);
                Assert.AreEqual(cp.TableCellWidth.Width.ToString(), "4809");
            }
        }
Exemple #12
0
        public void CopyRow()
        {
            using (var doc = WordprocessingDocument.Open(TemplatePath, true, new OpenSettings {
                AutoSave = false
            }))
            {
                var table = new WordDocumentTable(doc);
                table.Select("Table1");

                table.Rows.Copy();
                var cell = table.Cell(4, 2);

                Assert.AreEqual(cell.Text, "TextInColumn");
            }
        }
Exemple #13
0
        public void CanAddRow()
        {
            using (var doc = WordprocessingDocument.Open(TemplatePath, true, new OpenSettings {
                AutoSave = false
            }))
            {
                var table = new WordDocumentTable(doc);
                table.Select("Table1");

                table.Rows.Add();
                var cell = table.Cell(4, 2);

                Assert.IsNotNull(cell);
            }
        }
        public void CanCopyRowByIndex()
        {
            using (var doc = WordprocessingDocument.Open(TemplatePath, true, new OpenSettings {
                AutoSave = false
            }))
            {
                var table = new WordDocumentTable(doc);
                table.Select("Table1");
                var rows = new WordDocumentTableRows(table);

                rows.CopyRow(2);
                var cell = table.Cell(4, 3);

                Assert.AreEqual(cell.Text, "Количество");
            }
        }
Exemple #15
0
        public void SetCellText()
        {
            using (var doc = WordprocessingDocument.Open(TemplatePath, true, new OpenSettings {
                AutoSave = false
            }))
            {
                var table = new WordDocumentTable(doc);
                table.Select("Table1");
                var          cell = table.Cell(3, 2);
                const string val  = "New Text";

                cell.Text = val;

                Assert.AreEqual(cell.Text, val);
            }
        }
        public void GetCopyOfTableToTable()
        {
            using (var doc = WordprocessingDocument.Open(TemplatePath, true, new OpenSettings {
                AutoSave = false
            }))
            {
                var destTable = new WordDocumentTable(doc);
                destTable.Select("TableForCopy");
                var sourceTable = new WordDocumentTable(doc);
                sourceTable.Select("Table2");

                sourceTable.GetCopyOf(destTable);

                Assert.AreEqual(sourceTable.Cell(5, 1).Text, "Вид инструктажа");
            }
        }
        public void CopyTableToTable()
        {
            using (var doc = WordprocessingDocument.Open(TemplatePath, true, new OpenSettings {
                AutoSave = false
            }))
            {
                var destTable = new WordDocumentTable(doc);
                destTable.Select("TableForCopy");
                var sourceTable = new WordDocumentTable(doc);
                sourceTable.Select("Table2");

                sourceTable.CopyTo(destTable);

                Assert.AreEqual(destTable.Cell(9, 1).Text, "Годен\r\nЗдоров\r\nМолод");
            }
        }
        public void CanCopyRow()
        {
            using (var doc = WordprocessingDocument.Open(TemplatePath, true, new OpenSettings {
                AutoSave = false
            }))
            {
                var table = new WordDocumentTable(doc);
                table.Select("Table1");
                var rows = new WordDocumentTableRows(table);
                var cnt  = rows.Count;

                var newRow = rows.Copy();

                Assert.IsNotNull(newRow);
                Assert.AreEqual(cnt + 1, rows.Count);
            }
        }
Exemple #19
0
        public void SetTableProperties()
        {
            using (var doc = WordprocessingDocument.Open(TemplatePath, true, new OpenSettings {
                AutoSave = false
            }))
            {
                var table = new WordDocumentTable(doc);
                table.Select("Table1");
                var ntp = new TableProperties(
                    new TableCaption
                {
                    Val = "Table2"
                });
                table.TableProperties = ntp;
                var tp = (TableProperties)table.TableProperties;

                Assert.IsNotNull(tp);
                Assert.AreEqual(tp.TableCaption.Val.ToString(), "Table2");
            }
        }
        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);
            }
        }
        public void GetCopyOfTableToFooter()
        {
            using (var doc = WordprocessingDocument.Open(TemplatePath, true, new OpenSettings {
                AutoSave = false
            }))
            {
                var table = new WordDocumentTable(doc);
                table.Select("Table1");
                var footer = doc.MainDocumentPart.FooterParts
                             .Select(f => f.Footer)
                             .LastOrDefault();

                var source = new PrintObject(table.Table);
                var dest   = new PrintObject(footer);

                Assert.AreEqual(footer.Descendants <Table>().Count(), 0);

                dest.GetCopyOf(source);

                Assert.AreEqual(footer.Descendants <Table>().Count(), 1);
            }
        }
Exemple #23
0
        public void SetTableCellProperties()
        {
            using (var doc = WordprocessingDocument.Open(TemplatePath, true, new OpenSettings {
                AutoSave = false
            }))
            {
                var table = new WordDocumentTable(doc);
                table.Select("Table1");
                var cell = new WordDocumentTableCell(table.Table);
                cell.Select(1, 1);

                var ncp = new TableCellProperties(
                    new TableCellWidth
                {
                    Type  = TableWidthUnitValues.Dxa,
                    Width = "2400"
                });
                cell.CellProperties = ncp;
                var cp = (TableCellProperties)cell.CellProperties;

                Assert.IsNotNull(cp);
                Assert.AreEqual(cp.TableCellWidth.Width.ToString(), "2400");
            }
        }
        private void CopyTableToBookmark(IWordDocumentTable sourceTable)
        {
            var parentPara =
                (Paragraph)BkmEnd.Parent.ElementsBefore().LastOrDefault(e => e.GetType() == typeof(Paragraph));

            SiblingElement = parentPara;
            BkmEnd.Parent.Remove();
            Table    = null;
            BkmStart = new BookmarkStart
            {
                Name = BkmStart.Name,
                Id   = BkmStart.Id
            };
            BkmEnd = new BookmarkEnd
            {
                Id = BkmStart.Id
            };
            var newTable = (Table)sourceTable.GetCopy().Table;

            InsertXmlELement(newTable);
            newTable.GetFirstChild <TableRow>().GetFirstChild <TableCell>().Append(BkmStart);
            newTable.AppendChild(BkmEnd);
            Table = new WordDocumentTable(Doc, newTable);
        }