Esempio n. 1
0
        //ExStart
        //ExFor:Font.Hidden
        //ExFor:Paragraph.Accept
        //ExFor:DocumentVisitor.VisitParagraphStart(Aspose.Words.Paragraph)
        //ExFor:DocumentVisitor.VisitFormField(Aspose.Words.Fields.FormField)
        //ExFor:DocumentVisitor.VisitTableEnd(Aspose.Words.Tables.Table)
        //ExFor:DocumentVisitor.VisitCellEnd(Aspose.Words.Tables.Cell)
        //ExFor:DocumentVisitor.VisitRowEnd(Aspose.Words.Tables.Row)
        //ExFor:DocumentVisitor.VisitSpecialChar(Aspose.Words.SpecialChar)
        //ExFor:DocumentVisitor.VisitGroupShapeStart(Aspose.Words.Drawing.GroupShape)
        //ExFor:DocumentVisitor.VisitShapeStart(Aspose.Words.Drawing.Shape)
        //ExFor:DocumentVisitor.VisitCommentStart(Aspose.Words.Comment)
        //ExFor:DocumentVisitor.VisitFootnoteStart(Aspose.Words.Footnote)
        //ExFor:SpecialChar
        //ExFor:Node.Accept
        //ExFor:Paragraph.ParagraphBreakFont
        //ExFor:Table.Accept
        //ExSummary:Implements the Visitor Pattern to remove all content formatted as hidden from the document.
        public void RemoveHiddenContentFromDocument()
        {
            // Open the document we want to remove hidden content from.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Font.Hidden.doc");

            // Create an object that inherits from the DocumentVisitor class.
            RemoveHiddenContentVisitor hiddenContentRemover = new RemoveHiddenContentVisitor();

            // This is the well known Visitor pattern. Get the model to accept a visitor.
            // The model will iterate through itself by calling the corresponding methods
            // on the visitor object (this is called visiting).

            // We can run it over the entire the document like so:
            doc.Accept(hiddenContentRemover);

            // Or we can run it on only a specific node.
            Paragraph para = (Paragraph)doc.GetChild(NodeType.Paragraph, 4, true);

            para.Accept(hiddenContentRemover);

            // Or over a different type of node like below.
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

            table.Accept(hiddenContentRemover);

            doc.Save(MyDir + "Font.Hidden Out.doc");

            Assert.AreEqual(13, doc.GetChildNodes(NodeType.Paragraph, true).Count); //ExSkip
            Assert.AreEqual(1, doc.GetChildNodes(NodeType.Table, true).Count);      //ExSkip
        }
Esempio n. 2
0
        public void ScalingSpacing()
        {
            //ExStart
            //ExFor:Font.Scaling
            //ExFor:Font.Spacing
            //ExSummary:Shows how to use character scaling and spacing properties.
            // Create an empty document. It contains one empty paragraph.
            Aspose.Words.Document doc = new Aspose.Words.Document();

            // Get the paragraph from the document, we will be adding runs of text to it.
            Paragraph para = (Paragraph)doc.GetChild(NodeType.Paragraph, 0, true);

            // Add a run of text with characters 150% width of normal characters.
            Run run = new Run(doc, "Wide characters");

            run.Font.Scaling = 150;
            para.AppendChild(run);

            // Add a run of text with extra 1pt space between characters.
            run = new Run(doc, "Expanded by 1pt");
            run.Font.Spacing = 1;
            para.AppendChild(run);

            // Add a run of text with with space between characters reduced by 1pt.
            run = new Run(doc, "Condensed by 1pt");
            run.Font.Spacing = -1;
            para.AppendChild(run);
            //ExEnd
        }
Esempio n. 3
0
        public void PrintTableRange()
        {
            //ExStart
            //ExId:PrintTableRange
            //ExSummary:Shows how to print the text range of a table.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Table.SimpleTable.doc");

            // Get the first table in the document.
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

            // The range text will include control characters such as "\a" for a cell.
            // You can call ToString on the desired node to retrieve the plain text content.

            // Print the plain text range of the table to the screen.
            Console.WriteLine("Contents of the table: ");
            Console.WriteLine(table.Range.Text);
            //ExEnd

            //ExStart
            //ExId:PrintRowAndCellRange
            //ExSummary:Shows how to print the text range of row and table elements.
            // Print the contents of the second row to the screen.
            Console.WriteLine("\nContents of the row: ");
            Console.WriteLine(table.Rows[1].Range.Text);

            // Print the contents of the last cell in the table to the screen.
            Console.WriteLine("\nContents of the cell: ");
            Console.WriteLine(table.LastRow.LastCell.Range.Text);
            //ExEnd

            Assert.AreEqual("Apples\r" + ControlChar.Cell + "20\r" + ControlChar.Cell + ControlChar.Cell, table.Rows[1].Range.Text);
            Assert.AreEqual("50\r\a", table.LastRow.LastCell.Range.Text);
        }
Esempio n. 4
0
        public void PositionSubscript()
        {
            //ExStart
            //ExFor:Font.Position
            //ExFor:Font.Subscript
            //ExFor:Font.Superscript
            //ExSummary:Shows how to use subscript, superscript and baseline text position properties.
            // Create an empty document. It contains one empty paragraph.
            Aspose.Words.Document doc = new Aspose.Words.Document();

            // Get the paragraph from the document, we will be adding runs of text to it.
            Paragraph para = (Paragraph)doc.GetChild(NodeType.Paragraph, 0, true);

            // Add a run of text that is raised 5 points above the baseline.
            Run run = new Run(doc, "Raised text");

            run.Font.Position = 5;
            para.AppendChild(run);

            // Add a run of normal text.
            run = new Run(doc, "Normal text");
            para.AppendChild(run);

            // Add a run of text that appears as subscript.
            run = new Run(doc, "Subscript");
            run.Font.Subscript = true;
            para.AppendChild(run);

            // Add a run of text that appears as superscript.
            run = new Run(doc, "Superscript");
            run.Font.Superscript = true;
            para.AppendChild(run);
            //ExEnd
        }
Esempio n. 5
0
        public void InsertNewColumnIntoTable()
        {
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Table.Document.doc");
            Table table = (Table)doc.GetChild(NodeType.Table, 1, true);

            //ExStart
            //ExId:InsertNewColumn
            //ExSummary:Shows how to insert a blank column into a table.
            // Get the second column in the table.
            Column column = Column.FromIndex(table, 1);

            // Create a new column to the left of this column.
            // This is the same as using the "Insert Column Before" command in Microsoft Word.
            Column newColumn = column.InsertColumnBefore();

            // Add some text to each of the column cells.
            foreach (Cell cell in newColumn.Cells)
            {
                cell.FirstParagraph.AppendChild(new Run(doc, "Column Text " + newColumn.IndexOf(cell)));
            }
            //ExEnd

            doc.Save(MyDir + "Table.InsertColumn Out.doc");

            Assert.AreEqual(24, table.GetChildNodes(NodeType.Cell, true).Count);
            Assert.AreEqual("Column Text 0", table.FirstRow.Cells[1].ToString(SaveFormat.Text).Trim());
            Assert.AreEqual("Column Text 3", table.LastRow.Cells[1].ToString(SaveFormat.Text).Trim());
        }
Esempio n. 6
0
        public void RowFormatProperties()
        {
            //ExStart
            //ExFor:RowFormat
            //ExFor:Row.RowFormat
            //ExId:RowFormatProperties
            //ExSummary:Shows how to modify formatting of a table row.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Table.Document.doc");
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

            // Retrieve the first row in the table.
            Row firstRow = table.FirstRow;

            // Modify some row level properties.
            firstRow.RowFormat.Borders.LineStyle     = LineStyle.None;
            firstRow.RowFormat.HeightRule            = HeightRule.Auto;
            firstRow.RowFormat.AllowBreakAcrossPages = true;
            //ExEnd

            doc.Save(MyDir + "Table.RowFormat Out.doc");

            doc   = new Aspose.Words.Document(MyDir + "Table.RowFormat Out.doc");
            table = (Table)doc.GetChild(NodeType.Table, 0, true);
            Assert.AreEqual(LineStyle.None, table.FirstRow.RowFormat.Borders.LineStyle);
            Assert.AreEqual(HeightRule.Auto, table.FirstRow.RowFormat.HeightRule);
            Assert.True(table.FirstRow.RowFormat.AllowBreakAcrossPages);
        }
Esempio n. 7
0
        public void CellFormatProperties()
        {
            //ExStart
            //ExFor:CellFormat
            //ExFor:Cell.CellFormat
            //ExId:CellFormatProperties
            //ExSummary:Shows how to modify formatting of a table cell.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Table.Document.doc");
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

            // Retrieve the first cell in the table.
            Cell firstCell = table.FirstRow.FirstCell;

            // Modify some row level properties.
            firstCell.CellFormat.Width       = 30; // in points
            firstCell.CellFormat.Orientation = TextOrientation.Downward;
            firstCell.CellFormat.Shading.ForegroundPatternColor = Color.LightGreen;
            //ExEnd

            doc.Save(MyDir + "Table.CellFormat Out.doc");

            doc   = new Aspose.Words.Document(MyDir + "Table.CellFormat Out.doc");
            table = (Table)doc.GetChild(NodeType.Table, 0, true);
            Assert.AreEqual(30, table.FirstRow.FirstCell.CellFormat.Width);
            Assert.AreEqual(TextOrientation.Downward, table.FirstRow.FirstCell.CellFormat.Orientation);
            Assert.AreEqual(Color.LightGreen.ToArgb(), table.FirstRow.FirstCell.CellFormat.Shading.ForegroundPatternColor.ToArgb());
        }
Esempio n. 8
0
        public void EnumerateChildNodes()
        {
            Aspose.Words.Document doc = new Aspose.Words.Document();
            //ExStart
            //ExFor:Node
            //ExFor:CompositeNode
            //ExFor:CompositeNode.GetChild
            //ExSummary:Shows how to extract a specific child node from a CompositeNode by using the GetChild method and passing the NodeType and index.
            Paragraph paragraph = (Paragraph)doc.GetChild(NodeType.Paragraph, 0, true);
            //ExEnd

            //ExStart
            //ExFor:CompositeNode.ChildNodes
            //ExFor:CompositeNode.GetEnumerator
            //ExId:ChildNodesForEach
            //ExSummary:Shows how to enumerate immediate children of a CompositeNode using the enumerator provided by the ChildNodes collection.
            NodeCollection children = paragraph.ChildNodes;

            foreach (Aspose.Words.Node child in children)
            {
                // Paragraph may contain children of various types such as runs, shapes and so on.
                if (child.NodeType.Equals(NodeType.Run))
                {
                    // Say we found the node that we want, do something useful.
                    Run run = (Run)child;
                    Console.WriteLine(run.Text);
                }
            }
            //ExEnd
        }
Esempio n. 9
0
        public void SetTableBordersAll()
        {
            //ExStart
            //ExFor:Table.SetBorders
            //ExId:TableBordersAll
            //ExSummary:Shows how to build a table with all borders enabled (grid).
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Table.EmptyTable.doc");
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

            // Clear any existing borders from the table.
            table.ClearBorders();

            // Set a green border around and inside the table.
            table.SetBorders(LineStyle.Single, 1.5, Color.Green);

            doc.Save(MyDir + "Table.SetAllBorders Out.doc");
            //ExEnd

            // Verify the borders were set correctly.
            doc = new Aspose.Words.Document(MyDir + "Table.SetAllBorders Out.doc");
            Assert.AreEqual(Color.Green.ToArgb(), table.FirstRow.RowFormat.Borders.Top.Color.ToArgb());
            Assert.AreEqual(Color.Green.ToArgb(), table.FirstRow.RowFormat.Borders.Left.Color.ToArgb());
            Assert.AreEqual(Color.Green.ToArgb(), table.FirstRow.RowFormat.Borders.Right.Color.ToArgb());
            Assert.AreEqual(Color.Green.ToArgb(), table.FirstRow.RowFormat.Borders.Bottom.Color.ToArgb());
            Assert.AreEqual(Color.Green.ToArgb(), table.FirstRow.RowFormat.Borders.Horizontal.Color.ToArgb());
            Assert.AreEqual(Color.Green.ToArgb(), table.FirstRow.RowFormat.Borders.Vertical.Color.ToArgb());
        }
Esempio n. 10
0
        public void IndexChildNodes()
        {
            Aspose.Words.Document doc       = new Aspose.Words.Document();
            Paragraph             paragraph = (Paragraph)doc.GetChild(NodeType.Paragraph, 0, true);

            //ExStart
            //ExFor:NodeCollection.Count
            //ExFor:NodeCollection.Item
            //ExId:ChildNodesIndexer
            //ExSummary:Shows how to enumerate immediate children of a CompositeNode using indexed access.
            NodeCollection children = paragraph.ChildNodes;

            for (int i = 0; i < children.Count; i++)
            {
                Aspose.Words.Node child = children[i];

                // Paragraph may contain children of various types such as runs, shapes and so on.
                if (child.NodeType.Equals(NodeType.Run))
                {
                    // Say we found the node that we want, do something useful.
                    Run run = (Run)child;
                    Console.WriteLine(run.Text);
                }
            }
            //ExEnd
        }
Esempio n. 11
0
        public void InsertNewColumnIntoTable()
        {
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Table.Document.doc");
            Table table = (Table)doc.GetChild(NodeType.Table, 1, true);

            //ExStart
            //ExId:InsertNewColumn
            //ExSummary:Shows how to insert a blank column into a table.
            // Get the second column in the table.
            Column column = Column.FromIndex(table, 1);

            // Create a new column to the left of this column.
            // This is the same as using the "Insert Column Before" command in Microsoft Word.
            Column newColumn = column.InsertColumnBefore();

            // Add some text to each of the column cells.
            foreach (Cell cell in newColumn.Cells)
                cell.FirstParagraph.AppendChild(new Run(doc, "Column Text " + newColumn.IndexOf(cell)));
            //ExEnd

            doc.Save(MyDir + "Table.InsertColumn Out.doc");

            Assert.AreEqual(24, table.GetChildNodes(NodeType.Cell, true).Count);
            Assert.AreEqual("Column Text 0", table.FirstRow.Cells[1].ToString(SaveFormat.Text).Trim());
            Assert.AreEqual("Column Text 3", table.LastRow.Cells[1].ToString(SaveFormat.Text).Trim());
        }
Esempio n. 12
0
        public void TestNodeIsInsideField()
        {
            //ExStart:
            //ExFor:CompositeNode.SelectNodes
            //ExFor:CompositeNode.GetChild
            //ExSummary:Shows how to test if a node is inside a field by using an XPath expression.
            // Let's pick a document we know has some fields in.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "MailMerge.MergeImage.doc");

            // Let's say we want to check if the Run below is inside a field.
            Run run = (Run)doc.GetChild(NodeType.Run, 5, true);

            // Evaluate the XPath expression. The resulting NodeList will contain all nodes found inside a field a field (between FieldStart
            // and FieldEnd exclusive). There can however be FieldStart and FieldEnd nodes in the list if there are nested fields
            // in the path. Currently does not find rare fields in which the FieldCode or FieldResult spans across multiple paragraphs.
            NodeList resultList = doc.SelectNodes("//FieldStart/following-sibling::node()[following-sibling::FieldEnd]");

            // Check if the specified run is one of the nodes that are inside the field.
            foreach (Aspose.Words.Node node in resultList)
            {
                if (node == run)
                {
                    Console.WriteLine("The node is found inside a field");
                    break;
                }
            }
            //ExEnd
        }
Esempio n. 13
0
        public void AddClonedRowToTable()
        {
            //ExStart
            //ExFor:Row
            //ExId:AddClonedRowToTable
            //ExSummary:Shows how to make a clone of the last row of a table and append it to the table.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Table.SimpleTable.doc");

            // Retrieve the first table in the document.
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

            // Clone the last row in the table.
            Row clonedRow = (Row)table.LastRow.Clone(true);

            // Remove all content from the cloned row's cells. This makes the row ready for
            // new content to be inserted into.
            foreach (Cell cell in clonedRow.Cells)
            {
                cell.RemoveAllChildren();
            }

            // Add the row to the end of the table.
            table.AppendChild(clonedRow);

            doc.Save(MyDir + "Table.AddCloneRowToTable Out.doc");
            //ExEnd

            // Verify that the row was cloned and appended properly.
            Assert.AreEqual(5, table.Rows.Count);
            Assert.AreEqual(string.Empty, table.LastRow.ToString(SaveFormat.Text).Trim());
            Assert.AreEqual(2, table.LastRow.Cells.Count);
        }
Esempio n. 14
0
        public void AddClonedRowToTable()
        {
            //ExStart
            //ExFor:Row
            //ExId:AddClonedRowToTable
            //ExSummary:Shows how to make a clone of the last row of a table and append it to the table.
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Table.SimpleTable.doc");

            // Retrieve the first table in the document.
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

            // Clone the last row in the table.
            Row clonedRow = (Row)table.LastRow.Clone(true);

            // Remove all content from the cloned row's cells. This makes the row ready for
            // new content to be inserted into.
            foreach (Cell cell in clonedRow.Cells)
                cell.RemoveAllChildren();

            // Add the row to the end of the table.
            table.AppendChild(clonedRow);

            doc.Save(ExDir + "Table.AddCloneRowToTable Out.doc");
            //ExEnd

            // Verify that the row was cloned and appended properly.
            Assert.AreEqual(5, table.Rows.Count);
            Assert.AreEqual(string.Empty, table.LastRow.ToString(SaveFormat.Text).Trim());
            Assert.AreEqual(2, table.LastRow.Cells.Count);
        }
Esempio n. 15
0
        public void GetFieldType()
        {
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Document.TableOfContents.doc");

            //ExStart
            //ExFor:FieldType
            //ExFor:FieldChar
            //ExFor:FieldChar.FieldType
            //ExSummary:Shows how to find the type of field that is represented by a node which is derived from FieldChar.
            FieldChar fieldStart = (FieldChar)doc.GetChild(NodeType.FieldStart, 0, true);
            FieldType type       = fieldStart.FieldType;
            //ExEnd
        }
Esempio n. 16
0
        public void EnsureCellMinimum()
        {
            //ExStart
            //ExFor:Cell.EnsureMinimum
            //ExSummary:Shows how to ensure a cell node is valid.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Table.Document.doc");

            // Gets the first cell in the document.
            Cell cell = (Cell)doc.GetChild(NodeType.Cell, 0, true);

            // Ensure the cell is valid (the last child is a paragraph).
            cell.EnsureMinimum();
            //ExEnd
        }
Esempio n. 17
0
        public void CombineTables()
        {
            //ExStart
            //ExFor:Table
            //ExFor:Cell.CellFormat
            //ExFor:CellFormat.Borders
            //ExFor:Table.Rows
            //ExFor:Table.FirstRow
            //ExFor:CellFormat.ClearFormatting
            //ExId:CombineTables
            //ExSummary:Shows how to combine the rows from two tables into one.
            // Load the document.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Table.Document.doc");

            // Get the first and second table in the document.
            // The rows from the second table will be appended to the end of the first table.
            Table firstTable  = (Table)doc.GetChild(NodeType.Table, 0, true);
            Table secondTable = (Table)doc.GetChild(NodeType.Table, 1, true);

            // Append all rows from the current table to the next.
            // Due to the design of tables even tables with different cell count and widths can be joined into one table.
            while (secondTable.HasChildNodes)
            {
                firstTable.Rows.Add(secondTable.FirstRow);
            }

            // Remove the empty table container.
            secondTable.Remove();

            doc.Save(MyDir + "Table.CombineTables Out.doc");
            //ExEnd

            Assert.AreEqual(1, doc.GetChildNodes(NodeType.Table, true).Count);
            Assert.AreEqual(9, doc.FirstSection.Body.Tables[0].Rows.Count);
            Assert.AreEqual(42, doc.FirstSection.Body.Tables[0].GetChildNodes(NodeType.Cell, true).Count);
        }
Esempio n. 18
0
        public void TableColumnToTxt()
        {
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Table.Document.doc");
            Table table = (Table)doc.GetChild(NodeType.Table, 1, true);

            //ExStart
            //ExId:TableColumnToTxt
            //ExSummary:Shows how to get the plain text of a table column.
            // Get the first column in the table.
            Column column = Column.FromIndex(table, 0);

            // Print the plain text of the column to the screen.
            Console.WriteLine(column.ToTxt());
            //ExEnd

            Assert.AreEqual("\r\nRow 1\r\nRow 2\r\nRow 3\r\n", column.ToTxt());
        }
Esempio n. 19
0
        public void TableColumnToTxt()
        {
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Table.Document.doc");
            Table table = (Table)doc.GetChild(NodeType.Table, 1, true);

            //ExStart
            //ExId:TableColumnToTxt
            //ExSummary:Shows how to get the plain text of a table column.
            // Get the first column in the table.
            Column column = Column.FromIndex(table, 0);

            // Print the plain text of the column to the screen.
            Console.WriteLine(column.ToTxt());
            //ExEnd

            Assert.AreEqual("\r\nRow 1\r\nRow 2\r\nRow 3\r\n", column.ToTxt());
        }
Esempio n. 20
0
        public void RemoveBordersFromAllCells()
        {
            //ExStart
            //ExFor:Table
            //ExFor:Table.ClearBorders
            //ExSummary:Shows how to remove all borders from a table.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Table.Document.doc");

            // Remove all borders from the first table in the document.
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

            // Clear the borders all cells in the table.
            table.ClearBorders();

            doc.Save(MyDir + "Table.ClearBorders Out.doc");
            //ExEnd
        }
Esempio n. 21
0
        [Test] //ExSkip
        public void CheckCellsMerged()
        {
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Table.MergedCells.doc");

            // Retrieve the first table in the document.
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

            foreach (Row row in table.Rows)
            {
                foreach (Cell cell in row.Cells)
                {
                    Console.WriteLine(PrintCellMergeType(cell));
                }
            }

            Assert.AreEqual("The cell at R1, C1 is horizontally merged.", PrintCellMergeType(table.FirstRow.FirstCell)); //ExSkip
        }
Esempio n. 22
0
        public void KeepTableTogether()
        {
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Table.TableAcrossPage.doc");

            // Retrieve the first table in the document.
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

            //ExStart
            //ExFor:ParagraphFormat.KeepWithNext
            //ExFor:Row.IsLastRow
            //ExFor:Paragraph.IsEndOfCell
            //ExFor:Cell.ParentRow
            //ExFor:Cell.Paragraphs
            //ExId:KeepTableTogether
            //ExSummary:Shows how to set a table to stay together on the same page.
            // To keep a table from breaking across a page we need to enable KeepWithNext
            // for every paragraph in the table except for the last paragraphs in the last
            // row of the table.
            foreach (Cell cell in table.GetChildNodes(NodeType.Cell, true))
            {
                foreach (Paragraph para in cell.Paragraphs)
                {
                    if (!(cell.ParentRow.IsLastRow && para.IsEndOfCell))
                    {
                        para.ParagraphFormat.KeepWithNext = true;
                    }
                }
            }
            //ExEnd

            doc.Save(MyDir + "Table.KeepTableTogether Out.doc");

            // Verify the correct paragraphs were set properly.
            foreach (Paragraph para in table.GetChildNodes(NodeType.Paragraph, true))
            {
                if (para.IsEndOfCell && ((Cell)para.ParentNode).ParentRow.IsLastRow)
                {
                    Assert.False(para.ParagraphFormat.KeepWithNext);
                }
                else
                {
                    Assert.True(para.ParagraphFormat.KeepWithNext);
                }
            }
        }
Esempio n. 23
0
        public void SplitTable()
        {
            //ExStart
            //ExId:SplitTableAtRow
            //ExSummary:Shows how to split a table into two tables a specific row.
            // Load the document.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Table.SimpleTable.doc");

            // Get the first table in the document.
            Table firstTable = (Table)doc.GetChild(NodeType.Table, 0, true);

            // We will split the table at the third row (inclusive).
            Row row = firstTable.Rows[2];

            // Create a new container for the split table.
            Table table = (Table)firstTable.Clone(false);

            // Insert the container after the original.
            firstTable.ParentNode.InsertAfter(table, firstTable);

            // Add a buffer paragraph to ensure the tables stay apart.
            firstTable.ParentNode.InsertAfter(new Paragraph(doc), firstTable);

            Row currentRow;

            do
            {
                currentRow = firstTable.LastRow;
                table.PrependChild(currentRow);
            }while (currentRow != row);

            doc.Save(MyDir + "Table.SplitTable Out.doc");
            //ExEnd

            doc = new Aspose.Words.Document(MyDir + "Table.SplitTable Out.doc");
            // Test we are adding the rows in the correct order and the
            // selected row was also moved.
            Assert.AreEqual(row, table.FirstRow);

            Assert.AreEqual(2, firstTable.Rows.Count);
            Assert.AreEqual(2, table.Rows.Count);
            Assert.AreEqual(2, doc.GetChildNodes(NodeType.Table, true).Count);
        }
Esempio n. 24
0
        public void RemoveColumnFromTable()
        {
            //ExStart
            //ExId:RemoveTableColumn
            //ExSummary:Shows how to remove a column from a table in a document.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Table.Document.doc");
            Table table = (Table)doc.GetChild(NodeType.Table, 1, true);

            // Get the third column from the table and remove it.
            Column column = Column.FromIndex(table, 2);
            column.Remove();
            //ExEnd

            doc.Save(MyDir + "Table.RemoveColumn Out.doc");

            Assert.AreEqual(16, table.GetChildNodes(NodeType.Cell, true).Count);
            Assert.AreEqual("Cell 3 contents", table.Rows[2].Cells[2].ToString(SaveFormat.Text).Trim());
            Assert.AreEqual("Cell 3 contents", table.LastRow.Cells[2].ToString(SaveFormat.Text).Trim());
        }
Esempio n. 25
0
        public void SetTableBordersOutline()
        {
            //ExStart
            //ExFor:Table.Alignment
            //ExFor:TableAlignment
            //ExFor:Table.ClearBorders
            //ExFor:Table.SetBorder
            //ExFor:TextureIndex
            //ExFor:Table.SetShading
            //ExId:TableBordersOutline
            //ExSummary:Shows how to apply a outline border to a table.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Table.EmptyTable.doc");
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

            // Align the table to the center of the page.
            table.Alignment = TableAlignment.Center;

            // Clear any existing borders from the table.
            table.ClearBorders();

            // Set a green border around the table but not inside.
            table.SetBorder(BorderType.Left, LineStyle.Single, 1.5, Color.Green, true);
            table.SetBorder(BorderType.Right, LineStyle.Single, 1.5, Color.Green, true);
            table.SetBorder(BorderType.Top, LineStyle.Single, 1.5, Color.Green, true);
            table.SetBorder(BorderType.Bottom, LineStyle.Single, 1.5, Color.Green, true);

            // Fill the cells with a light green solid color.
            table.SetShading(TextureIndex.TextureSolid, Color.LightGreen, Color.Empty);

            doc.Save(MyDir + "Table.SetOutlineBorders Out.doc");
            //ExEnd

            // Verify the borders were set correctly.
            doc = new Aspose.Words.Document(MyDir + "Table.SetOutlineBorders Out.doc");
            Assert.AreEqual(TableAlignment.Center, table.Alignment);
            Assert.AreEqual(Color.Green.ToArgb(), table.FirstRow.RowFormat.Borders.Top.Color.ToArgb());
            Assert.AreEqual(Color.Green.ToArgb(), table.FirstRow.RowFormat.Borders.Left.Color.ToArgb());
            Assert.AreEqual(Color.Green.ToArgb(), table.FirstRow.RowFormat.Borders.Right.Color.ToArgb());
            Assert.AreEqual(Color.Green.ToArgb(), table.FirstRow.RowFormat.Borders.Bottom.Color.ToArgb());
            Assert.AreNotEqual(Color.Green.ToArgb(), table.FirstRow.RowFormat.Borders.Horizontal.Color.ToArgb());
            Assert.AreNotEqual(Color.Green.ToArgb(), table.FirstRow.RowFormat.Borders.Vertical.Color.ToArgb());
            Assert.AreEqual(Color.LightGreen.ToArgb(), table.FirstRow.FirstCell.CellFormat.Shading.ForegroundPatternColor.ToArgb());
        }
Esempio n. 26
0
        public void MailMergeImageFromUrl()
        {
            //ExStart
            //ExFor:MailMerge.Execute(String[], Object[])
            //ExSummary:Demonstrates how to merge an image from a web address using an Image field.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "MailMerge.MergeImageSimple.doc");

            // Pass a URL which points to the image to merge into the document.
            doc.MailMerge.Execute(new string[] { "Logo" }, new object[] { "http://www.aspose.com/images/aspose-logo.gif" });

            doc.Save(MyDir + "MailMerge.MergeImageFromUrl Out.doc");
            //ExEnd

            // Verify the image was merged into the document.
            Shape logoImage = (Shape)doc.GetChild(NodeType.Shape, 0, true);

            Assert.IsNotNull(logoImage);
            Assert.IsTrue(logoImage.HasImage);
        }
Esempio n. 27
0
        public void CheckShapeInline()
        {
            //ExStart
            //ExFor:ShapeBase.IsInline
            //ExSummary:Shows how to test if a shape in the document is inline or floating.
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Shape.DeleteAllShapes.doc");

            foreach (Shape shape in doc.GetChildNodes(NodeType.Shape, true))
            {
                if(shape.IsInline)
                    Console.WriteLine("Shape is inline.");
                else
                    Console.WriteLine("Shape is floating.");
            }

            //ExEnd

            // Verify that the first shape in the document is not inline.
            Assert.False(((Shape)doc.GetChild(NodeType.Shape, 0, true)).IsInline);
        }
Esempio n. 28
0
        public void RemoveColumnFromTable()
        {
            //ExStart
            //ExId:RemoveTableColumn
            //ExSummary:Shows how to remove a column from a table in a document.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Table.Document.doc");
            Table table = (Table)doc.GetChild(NodeType.Table, 1, true);

            // Get the third column from the table and remove it.
            Column column = Column.FromIndex(table, 2);

            column.Remove();
            //ExEnd

            doc.Save(MyDir + "Table.RemoveColumn Out.doc");

            Assert.AreEqual(16, table.GetChildNodes(NodeType.Cell, true).Count);
            Assert.AreEqual("Cell 3 contents", table.Rows[2].Cells[2].ToString(SaveFormat.Text).Trim());
            Assert.AreEqual("Cell 3 contents", table.LastRow.Cells[2].ToString(SaveFormat.Text).Trim());
        }
Esempio n. 29
0
        public void GetPreferredWidthTypeAndValue()
        {
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Table.Document.doc");

            // Find the first table in the document
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);
            //ExStart
            //ExFor:PreferredWidthType
            //ExFor:PreferredWidth.Type
            //ExFor:PreferredWidth.Value
            //ExId:GetPreferredWidthTypeAndValue
            //ExSummary:Retrieves the preferred width type of a table cell.
            Cell firstCell           = table.FirstRow.FirstCell;
            PreferredWidthType type  = firstCell.CellFormat.PreferredWidth.Type;
            double             value = firstCell.CellFormat.PreferredWidth.Value;

            //ExEnd

            Assert.AreEqual(PreferredWidthType.Percent, type);
            Assert.AreEqual(11.16, value);
        }
Esempio n. 30
0
        public void Caps()
        {
            //ExStart
            //ExFor:Font.AllCaps
            //ExFor:Font.SmallCaps
            //ExSummary:Shows how to use all capitals and small capitals character formatting properties.
            // Create an empty document. It contains one empty paragraph.
            Aspose.Words.Document doc = new Aspose.Words.Document();

            // Get the paragraph from the document, we will be adding runs of text to it.
            Paragraph para = (Paragraph)doc.GetChild(NodeType.Paragraph, 0, true);

            Run run = new Run(doc, "All capitals");
            run.Font.AllCaps = true;
            para.AppendChild(run);

            run = new Run(doc, "SMALL CAPITALS");
            run.Font.SmallCaps = true;
            para.AppendChild(run);
            //ExEnd
        }
Esempio n. 31
0
        public void GetFieldFromDocument()
        {
            //ExStart
            //ExFor:FieldChar.GetField
            //ExId:GetField
            //ExSummary:Demonstrates how to retrieve the field class from an existing FieldStart node in the document.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Document.TableOfContents.doc");

            FieldStart fieldStart = (FieldStart)doc.GetChild(NodeType.FieldStart, 0, true);

            // Retrieve the facade object which represents the field in the document.
            Field field = fieldStart.GetField();

            Console.WriteLine("Field code:" + field.GetFieldCode());
            Console.WriteLine("Field result: " + field.Result);
            Console.WriteLine("Is locked: " + field.IsLocked);

            // This updates only this field in the document.
            field.Update();
            //ExEnd
        }
Esempio n. 32
0
        public void GetFieldFromDocument()
        {
            //ExStart
            //ExFor:FieldChar.GetField
            //ExId:GetField
            //ExSummary:Demonstrates how to retrieve the field class from an existing FieldStart node in the document.
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Document.TableOfContents.doc");

            FieldStart fieldStart = (FieldStart)doc.GetChild(NodeType.FieldStart, 0, true);

            // Retrieve the facade object which represents the field in the document.
            Field field = fieldStart.GetField();

            Console.WriteLine("Field code:" + field.GetFieldCode());
            Console.WriteLine("Field result: " + field.Result);
            Console.WriteLine("Is locked: " + field.IsLocked);

            // This updates only this field in the document.
            field.Update();
            //ExEnd
        }
Esempio n. 33
0
        public void ReplaceTextInTable()
        {
            //ExStart
            //ExFor:Range.Replace(String, String, Boolean, Boolean)
            //ExFor:Cell
            //ExId:ReplaceTextTable
            //ExSummary:Shows how to replace all instances of string of text in a table and cell.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Table.SimpleTable.doc");

            // Get the first table in the document.
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

            // Replace any instances of our string in the entire table.
            table.Range.Replace("Carrots", "Eggs", true, true);
            // Replace any instances of our string in the last cell of the table only.
            table.LastRow.LastCell.Range.Replace("50", "20", true, true);

            doc.Save(MyDir + "Table.ReplaceCellText Out.doc");
            //ExEnd

            Assert.AreEqual("20", table.LastRow.LastCell.ToString(SaveFormat.Text).Trim());
        }
Esempio n. 34
0
        public void Caps()
        {
            //ExStart
            //ExFor:Font.AllCaps
            //ExFor:Font.SmallCaps
            //ExSummary:Shows how to use all capitals and small capitals character formatting properties.
            // Create an empty document. It contains one empty paragraph.
            Aspose.Words.Document doc = new Aspose.Words.Document();

            // Get the paragraph from the document, we will be adding runs of text to it.
            Paragraph para = (Paragraph)doc.GetChild(NodeType.Paragraph, 0, true);

            Run run = new Run(doc, "All capitals");

            run.Font.AllCaps = true;
            para.AppendChild(run);

            run = new Run(doc, "SMALL CAPITALS");
            run.Font.SmallCaps = true;
            para.AppendChild(run);
            //ExEnd
        }
Esempio n. 35
0
        public void Strikethrough()
        {
            //ExStart
            //ExFor:Font.StrikeThrough
            //ExFor:Font.DoubleStrikeThrough
            //ExSummary:Shows how to use strike-through character formatting properties.
            // Create an empty document. It contains one empty paragraph.
            Aspose.Words.Document doc = new Aspose.Words.Document();

            // Get the paragraph from the document, we will be adding runs of text to it.
            Paragraph para = (Paragraph)doc.GetChild(NodeType.Paragraph, 0, true);

            Run run = new Run(doc, "Double strike through text");

            run.Font.DoubleStrikeThrough = true;
            para.AppendChild(run);

            run = new Run(doc, "Single strike through text");
            run.Font.StrikeThrough = true;
            para.AppendChild(run);
            //ExEnd
        }
Esempio n. 36
0
        public void CloneTable()
        {
            //ExStart
            //ExId:CloneTable
            //ExSummary:Shows how to make a clone of a table in the document and insert it after the original table.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Table.SimpleTable.doc");

            // Retrieve the first table in the document.
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

            // Create a clone of the table.
            Table tableClone = (Table)table.Clone(true);

            // Insert the cloned table into the document after the original
            table.ParentNode.InsertAfter(tableClone, table);

            // Insert an empty paragraph between the two tables or else they will be combined into one
            // upon save. This has to do with document validation.
            table.ParentNode.InsertAfter(new Paragraph(doc), table);

            doc.Save(MyDir + "Table.CloneTableAndInsert Out.doc");
            //ExEnd

            // Verify that the table was cloned and inserted properly.
            Assert.AreEqual(2, doc.GetChildNodes(NodeType.Table, true).Count);
            Assert.AreEqual(table.Range.Text, tableClone.Range.Text);

            //ExStart
            //ExId:CloneTableRemoveContent
            //ExSummary:Shows how to remove all content from the cells of a cloned table.
            foreach (Cell cell in tableClone.GetChildNodes(NodeType.Cell, true))
            {
                cell.RemoveAllChildren();
            }
            //ExEnd

            Assert.AreEqual(String.Empty, tableClone.ToString(SaveFormat.Text).Trim());
        }
Esempio n. 37
0
        public void RowFormatDisableBreakAcrossPages()
        {
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Table.TableAcrossPage.doc");

            // Retrieve the first table in the document.
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

            //ExStart
            //ExFor:RowFormat.AllowBreakAcrossPages
            //ExId:RowFormatAllowBreaks
            //ExSummary:Shows how to disable rows breaking across pages for every row in a table.
            // Disable breaking across pages for all rows in the table.
            foreach (Row row in table)
            {
                row.RowFormat.AllowBreakAcrossPages = false;
            }
            //ExEnd

            doc.Save(MyDir + "Table.DisableBreakAcrossPages Out.doc");

            Assert.False(table.FirstRow.RowFormat.AllowBreakAcrossPages);
            Assert.False(table.LastRow.RowFormat.AllowBreakAcrossPages);
        }
Esempio n. 38
0
        public void OpenFromStreamWithBaseUri()
        {
            //ExStart
            //ExFor:Document.#ctor(Stream,LoadOptions)
            //ExFor:LoadOptions
            //ExFor:LoadOptions.BaseUri
            //ExId:DocumentCtor_LoadOptions
            //ExSummary:Opens an HTML document with images from a stream using a base URI.

            // We are opening this HTML file:
            //    <html>
            //    <body>
            //    <p>Simple file.</p>
            //    <p><img src="Aspose.Words.gif" width="80" height="60"></p>
            //    </body>
            //    </html>
            string fileName = MyDir + "Document.OpenFromStreamWithBaseUri.html";

            // Open the stream.
            Stream stream = File.OpenRead(fileName);

            // Open the document. Note the Document constructor detects HTML format automatically.
            // Pass the URI of the base folder so any images with relative URIs in the HTML document can be found.
            LoadOptions loadOptions = new LoadOptions();
            loadOptions.BaseUri = MyDir;
            Aspose.Words.Document doc = new Aspose.Words.Document(stream, loadOptions);

            // You can close the stream now, it is no longer needed because the document is in memory.
            stream.Close();

            // Save in the DOC format.
            doc.Save(MyDir + "Document.OpenFromStreamWithBaseUri Out.doc");
            //ExEnd

            // Lets make sure the image was imported successfully into a Shape node.
            // Get the first shape node in the document.
            Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true);

            // Verify some properties of the image.
            Assert.IsTrue(shape.IsImage);
            Assert.IsNotNull(shape.ImageData.ImageBytes);
            Assert.AreEqual(80.0, Aspose.Words.ConvertUtil.PointToPixel(shape.Width));
            Assert.AreEqual(60.0, Aspose.Words.ConvertUtil.PointToPixel(shape.Height));
        }
Esempio n. 39
0
        public void SetTableBordersAll()
        {
            //ExStart
            //ExFor:Table.SetBorders
            //ExId:TableBordersAll
            //ExSummary:Shows how to build a table with all borders enabled (grid).
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Table.EmptyTable.doc");
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

            // Clear any existing borders from the table.
            table.ClearBorders();

            // Set a green border around and inside the table.
            table.SetBorders(LineStyle.Single, 1.5, Color.Green);

            doc.Save(ExDir + "Table.SetAllBorders Out.doc");
            //ExEnd

            // Verify the borders were set correctly.
            doc = new Aspose.Words.Document(ExDir + "Table.SetAllBorders Out.doc");
            Assert.AreEqual(Color.Green.ToArgb(), table.FirstRow.RowFormat.Borders.Top.Color.ToArgb());
            Assert.AreEqual(Color.Green.ToArgb(), table.FirstRow.RowFormat.Borders.Left.Color.ToArgb());
            Assert.AreEqual(Color.Green.ToArgb(), table.FirstRow.RowFormat.Borders.Right.Color.ToArgb());
            Assert.AreEqual(Color.Green.ToArgb(), table.FirstRow.RowFormat.Borders.Bottom.Color.ToArgb());
            Assert.AreEqual(Color.Green.ToArgb(), table.FirstRow.RowFormat.Borders.Horizontal.Color.ToArgb());
            Assert.AreEqual(Color.Green.ToArgb(), table.FirstRow.RowFormat.Borders.Vertical.Color.ToArgb());
        }
Esempio n. 40
0
        public void TableStyleToDirectFormatting()
        {
            //ExStart
            //ExFor:Document.ExpandTableStylesToDirectFormatting
            //ExId:TableStyleToDirectFormatting
            //ExSummary:Shows how to expand the formatting from styles onto the rows and cells of the table as direct formatting.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Table.TableStyle.docx");

            // Get the first cell of the first table in the document.
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);
            Cell firstCell = table.FirstRow.FirstCell;

            // First print the color of the cell shading. This should be empty as the current shading
            // is stored in the table style.
            Color cellShadingBefore = firstCell.CellFormat.Shading.BackgroundPatternColor;
            Console.WriteLine("Cell shading before style expansion: " + cellShadingBefore.ToString());

            // Expand table style formatting to direct formatting.
            doc.ExpandTableStylesToDirectFormatting();

            // Now print the cell shading after expanding table styles. A blue background pattern color
            // should have been applied from the table style.
            Color cellShadingAfter = firstCell.CellFormat.Shading.BackgroundPatternColor;
            Console.WriteLine("Cell shading after style expansion: " + cellShadingAfter.ToString());
            //ExEnd

            doc.Save(MyDir + "Table.ExpandTableStyleFormatting Out.docx");

            Assert.AreEqual(Color.Empty, cellShadingBefore);
            Assert.AreNotEqual(Color.Empty, cellShadingAfter);
        }
Esempio n. 41
0
        //ExStart
        //ExFor:INodeChangingCallback
        //ExFor:INodeChangingCallback.NodeInserting
        //ExFor:INodeChangingCallback.NodeInserted
        //ExFor:INodeChangingCallback.NodeRemoving
        //ExFor:INodeChangingCallback.NodeRemoved
        //ExFor:NodeChangingArgs
        //ExFor:NodeChangingArgs.Node
        //ExFor:DocumentBase.NodeChangingCallback
        //ExId:NodeChangingInDocument
        //ExSummary:Shows how to implement custom logic over node insertion in the document by changing the font of inserted HTML content.
        public void TestNodeChangingInDocument()
        {
            // Create a blank document object
            Aspose.Words.Document doc = new Aspose.Words.Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // Set up and pass the object which implements the handler methods.
            doc.NodeChangingCallback = new HandleNodeChanging_FontChanger();

            // Insert sample HTML content
            builder.InsertHtml("<p>Hello World</p>");

            doc.Save(MyDir + "Document.FontChanger Out.doc");

            // Check that the inserted content has the correct formatting
            Run run = (Run)doc.GetChild(NodeType.Run, 0, true);
            Assert.AreEqual(24.0, run.Font.Size);
            Assert.AreEqual("Arial", run.Font.Name);
        }
Esempio n. 42
0
        public void GetPreferredWidthTypeAndValue()
        {
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Table.Document.doc");

            // Find the first table in the document
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);
            //ExStart
            //ExFor:PreferredWidthType
            //ExFor:PreferredWidth.Type
            //ExFor:PreferredWidth.Value
            //ExId:GetPreferredWidthTypeAndValue
            //ExSummary:Retrieves the preferred width type of a table cell.
            Cell firstCell = table.FirstRow.FirstCell;
            PreferredWidthType type = firstCell.CellFormat.PreferredWidth.Type;
            double value = firstCell.CellFormat.PreferredWidth.Value;
            //ExEnd

            Assert.AreEqual(PreferredWidthType.Percent, type);
            Assert.AreEqual(11.16, value);
        }
Esempio n. 43
0
        public void SetTableBordersOutline()
        {
            //ExStart
            //ExFor:Table.Alignment
            //ExFor:TableAlignment
            //ExFor:Table.ClearBorders
            //ExFor:Table.SetBorder
            //ExFor:TextureIndex
            //ExFor:Table.SetShading
            //ExId:TableBordersOutline
            //ExSummary:Shows how to apply a outline border to a table.
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Table.EmptyTable.doc");
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

            // Align the table to the center of the page.
            table.Alignment = TableAlignment.Center;

            // Clear any existing borders from the table.
            table.ClearBorders();

            // Set a green border around the table but not inside.
            table.SetBorder(BorderType.Left, LineStyle.Single, 1.5, Color.Green, true);
            table.SetBorder(BorderType.Right, LineStyle.Single, 1.5, Color.Green, true);
            table.SetBorder(BorderType.Top, LineStyle.Single, 1.5, Color.Green, true);
            table.SetBorder(BorderType.Bottom, LineStyle.Single, 1.5, Color.Green, true);

            // Fill the cells with a light green solid color.
            table.SetShading(TextureIndex.TextureSolid, Color.LightGreen, Color.Empty);

            doc.Save(ExDir + "Table.SetOutlineBorders Out.doc");
            //ExEnd

            // Verify the borders were set correctly.
            doc = new Aspose.Words.Document(ExDir + "Table.SetOutlineBorders Out.doc");
            Assert.AreEqual(TableAlignment.Center, table.Alignment);
            Assert.AreEqual(Color.Green.ToArgb(), table.FirstRow.RowFormat.Borders.Top.Color.ToArgb());
            Assert.AreEqual(Color.Green.ToArgb(), table.FirstRow.RowFormat.Borders.Left.Color.ToArgb());
            Assert.AreEqual(Color.Green.ToArgb(), table.FirstRow.RowFormat.Borders.Right.Color.ToArgb());
            Assert.AreEqual(Color.Green.ToArgb(), table.FirstRow.RowFormat.Borders.Bottom.Color.ToArgb());
            Assert.AreNotEqual(Color.Green.ToArgb(), table.FirstRow.RowFormat.Borders.Horizontal.Color.ToArgb());
            Assert.AreNotEqual(Color.Green.ToArgb(), table.FirstRow.RowFormat.Borders.Vertical.Color.ToArgb());
            Assert.AreEqual(Color.LightGreen.ToArgb(), table.FirstRow.FirstCell.CellFormat.Shading.ForegroundPatternColor.ToArgb());
        }
Esempio n. 44
0
        public void Strikethrough()
        {
            //ExStart
            //ExFor:Font.StrikeThrough
            //ExFor:Font.DoubleStrikeThrough
            //ExSummary:Shows how to use strike-through character formatting properties.
            // Create an empty document. It contains one empty paragraph.
            Aspose.Words.Document doc = new Aspose.Words.Document();

            // Get the paragraph from the document, we will be adding runs of text to it.
            Paragraph para = (Paragraph)doc.GetChild(NodeType.Paragraph, 0, true);

            Run run = new Run(doc, "Double strike through text");
            run.Font.DoubleStrikeThrough = true;
            para.AppendChild(run);

            run = new Run(doc, "Single strike through text");
            run.Font.StrikeThrough = true;
            para.AppendChild(run);
            //ExEnd
        }
Esempio n. 45
0
        public void GetFieldType()
        {
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Document.TableOfContents.doc");

            //ExStart
            //ExFor:FieldType
            //ExFor:FieldChar
            //ExFor:FieldChar.FieldType
            //ExSummary:Shows how to find the type of field that is represented by a node which is derived from FieldChar.
            FieldChar fieldStart = (FieldChar)doc.GetChild(NodeType.FieldStart, 0, true);
            FieldType type = fieldStart.FieldType;
            //ExEnd
        }
        public void BuildSimpleTable()
        {
            //ExStart
            //ExFor:DocumentBuilder
            //ExFor:DocumentBuilder.Write
            //ExFor:DocumentBuilder.InsertCell
            //ExId:BuildSimpleTable
            //ExSummary:Shows how to create a simple table using DocumentBuilder with default formatting.
            Aspose.Words.Document doc = new Aspose.Words.Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // We call this method to start building the table.
            builder.StartTable();
            builder.InsertCell();
            builder.Write("Row 1, Cell 1 Content.");

            // Build the second cell
            builder.InsertCell();
            builder.Write("Row 1, Cell 2 Content.");
            // Call the following method to end the row and start a new row.
            builder.EndRow();

            // Build the first cell of the second row.
            builder.InsertCell();
            builder.Write("Row 2, Cell 1 Content");

            // Build the second cell.
            builder.InsertCell();
            builder.Write("Row 2, Cell 2 Content.");
            builder.EndRow();

            // Signal that we have finished building the table.
            builder.EndTable();

            // Save the document to disk.
            doc.Save(ExDir + "DocumentBuilder.CreateSimpleTable Out.doc");
            //ExEnd

            // Verify that the cell count of the table is four.
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);
            Assert.IsNotNull(table);
            Assert.AreEqual(table.GetChildNodes(NodeType.Cell, true).Count, 4);
        }
Esempio n. 47
0
        //ExStart
        //ExFor:Font.Hidden
        //ExFor:Paragraph.Accept
        //ExFor:DocumentVisitor.VisitParagraphStart(Aspose.Words.Paragraph)
        //ExFor:DocumentVisitor.VisitFormField(Aspose.Words.Fields.FormField)
        //ExFor:DocumentVisitor.VisitTableEnd(Aspose.Words.Tables.Table)
        //ExFor:DocumentVisitor.VisitCellEnd(Aspose.Words.Tables.Cell)
        //ExFor:DocumentVisitor.VisitRowEnd(Aspose.Words.Tables.Row)
        //ExFor:DocumentVisitor.VisitSpecialChar(Aspose.Words.SpecialChar)
        //ExFor:DocumentVisitor.VisitGroupShapeStart(Aspose.Words.Drawing.GroupShape)
        //ExFor:DocumentVisitor.VisitShapeStart(Aspose.Words.Drawing.Shape)
        //ExFor:DocumentVisitor.VisitCommentStart(Aspose.Words.Comment)
        //ExFor:DocumentVisitor.VisitFootnoteStart(Aspose.Words.Footnote)
        //ExFor:SpecialChar
        //ExFor:Node.Accept
        //ExFor:Paragraph.ParagraphBreakFont
        //ExFor:Table.Accept
        //ExSummary:Implements the Visitor Pattern to remove all content formatted as hidden from the document.
        public void RemoveHiddenContentFromDocument()
        {
            // Open the document we want to remove hidden content from.
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Font.Hidden.doc");

            // Create an object that inherits from the DocumentVisitor class.
            RemoveHiddenContentVisitor hiddenContentRemover = new RemoveHiddenContentVisitor();

            // This is the well known Visitor pattern. Get the model to accept a visitor.
            // The model will iterate through itself by calling the corresponding methods
            // on the visitor object (this is called visiting).

            // We can run it over the entire the document like so:
            doc.Accept(hiddenContentRemover);

            // Or we can run it on only a specific node.
            Paragraph para = (Paragraph)doc.GetChild(NodeType.Paragraph, 4, true);
            para.Accept(hiddenContentRemover);

            // Or over a different type of node like below.
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);
            table.Accept(hiddenContentRemover);

            doc.Save(ExDir + "Font.Hidden Out.doc");

            Assert.AreEqual(13, doc.GetChildNodes(NodeType.Paragraph, true).Count); //ExSkip
            Assert.AreEqual(1, doc.GetChildNodes(NodeType.Table, true).Count); //ExSkip
        }
        public void InsertImageFromUrl()
        {
            //ExStart
            //ExFor:DocumentBuilder.InsertImage(String)
            //ExSummary:Shows how to insert an image into a document from a web address.
            Aspose.Words.Document doc = new Aspose.Words.Document();
            DocumentBuilder builder = new DocumentBuilder(doc);
            builder.InsertImage("http://www.aspose.com/images/aspose-logo.gif");

            doc.Save(ExDir + "DocumentBuilder.InsertImageFromUrl Out.doc");
            //ExEnd

            // Verify that the image was inserted into the document.
            Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true);
            Assert.IsNotNull(shape);
            Assert.True(shape.HasImage);
        }
Esempio n. 49
0
        public void MailMergeImageFromUrl()
        {
            //ExStart
            //ExFor:MailMerge.Execute(String[], Object[])
            //ExSummary:Demonstrates how to merge an image from a web address using an Image field.
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "MailMerge.MergeImageSimple.doc");

            // Pass a URL which points to the image to merge into the document.
            doc.MailMerge.Execute(new string[] { "Logo" }, new object[] { "http://www.aspose.com/images/aspose-logo.gif" });

            doc.Save(ExDir + "MailMerge.MergeImageFromUrl Out.doc");
            //ExEnd

            // Verify the image was merged into the document.
            Shape logoImage = (Shape)doc.GetChild(NodeType.Shape, 0, true);
            Assert.IsNotNull(logoImage);
            Assert.IsTrue(logoImage.HasImage);
        }
Esempio n. 50
0
        public void GetIndexOfTableElements()
        {
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Table.Document.doc");

            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);
            //ExStart
            //ExFor:NodeCollection.IndexOf
            //ExId:IndexOfTable
            //ExSummary:Retrieves the index of a table in the document.
            NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
            int tableIndex = allTables.IndexOf(table);
            //ExEnd

            Row row = table.Rows[2];
            //ExStart
            //ExFor:Row
            //ExFor:CompositeNode.IndexOf
            //ExId:IndexOfRow
            //ExSummary:Retrieves the index of a row in a table.
            int rowIndex = table.IndexOf(row);
            //ExEnd

            Cell cell = row.LastCell;
            //ExStart
            //ExFor:Cell
            //ExFor:CompositeNode.IndexOf
            //ExId:IndexOfCell
            //ExSummary:Retrieves the index of a cell in a row.
            int cellIndex = row.IndexOf(cell);
            //ExEnd

            Assert.AreEqual(0, tableIndex);
            Assert.AreEqual(2, rowIndex);
            Assert.AreEqual(4, cellIndex);
        }
Esempio n. 51
0
        public void RowFormatProperties()
        {
            //ExStart
            //ExFor:RowFormat
            //ExFor:Row.RowFormat
            //ExId:RowFormatProperties
            //ExSummary:Shows how to modify formatting of a table row.
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Table.Document.doc");
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

            // Retrieve the first row in the table.
            Row firstRow = table.FirstRow;

            // Modify some row level properties.
            firstRow.RowFormat.Borders.LineStyle = LineStyle.None;
            firstRow.RowFormat.HeightRule = HeightRule.Auto;
            firstRow.RowFormat.AllowBreakAcrossPages = true;
            //ExEnd

            doc.Save(ExDir + "Table.RowFormat Out.doc");

            doc = new Aspose.Words.Document(ExDir + "Table.RowFormat Out.doc");
            table = (Table)doc.GetChild(NodeType.Table, 0, true);
            Assert.AreEqual(LineStyle.None, table.FirstRow.RowFormat.Borders.LineStyle);
            Assert.AreEqual(HeightRule.Auto, table.FirstRow.RowFormat.HeightRule);
            Assert.True(table.FirstRow.RowFormat.AllowBreakAcrossPages);
        }
Esempio n. 52
0
        public void ReplaceTextInTable()
        {
            //ExStart
            //ExFor:Range.Replace(String, String, Boolean, Boolean)
            //ExFor:Cell
            //ExId:ReplaceTextTable
            //ExSummary:Shows how to replace all instances of string of text in a table and cell.
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Table.SimpleTable.doc");

            // Get the first table in the document.
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

            // Replace any instances of our string in the entire table.
            table.Range.Replace("Carrots", "Eggs", true, true);
            // Replace any instances of our string in the last cell of the table only.
            table.LastRow.LastCell.Range.Replace("50", "20", true, true);

            doc.Save(ExDir + "Table.ReplaceCellText Out.doc");
            //ExEnd

            Assert.AreEqual("20", table.LastRow.LastCell.ToString(SaveFormat.Text).Trim());
        }
Esempio n. 53
0
        public void RowFormatDisableBreakAcrossPages()
        {
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Table.TableAcrossPage.doc");

            // Retrieve the first table in the document.
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

            //ExStart
            //ExFor:RowFormat.AllowBreakAcrossPages
            //ExId:RowFormatAllowBreaks
            //ExSummary:Shows how to disable rows breaking across pages for every row in a table.
            // Disable breaking across pages for all rows in the table.
            foreach(Row row in table)
                row.RowFormat.AllowBreakAcrossPages = false;
            //ExEnd

            doc.Save(ExDir + "Table.DisableBreakAcrossPages Out.doc");

            Assert.False(table.FirstRow.RowFormat.AllowBreakAcrossPages);
            Assert.False(table.LastRow.RowFormat.AllowBreakAcrossPages);
        }
Esempio n. 54
0
        public void SplitTable()
        {
            //ExStart
            //ExId:SplitTableAtRow
            //ExSummary:Shows how to split a table into two tables a specific row.
            // Load the document.
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Table.SimpleTable.doc");

            // Get the first table in the document.
            Table firstTable = (Table)doc.GetChild(NodeType.Table, 0, true);

            // We will split the table at the third row (inclusive).
            Row row = firstTable.Rows[2];

            // Create a new container for the split table.
            Table table = (Table)firstTable.Clone(false);

            // Insert the container after the original.
            firstTable.ParentNode.InsertAfter(table, firstTable);

            // Add a buffer paragraph to ensure the tables stay apart.
            firstTable.ParentNode.InsertAfter(new Paragraph(doc), firstTable);

            Row currentRow;

            do
            {
                currentRow = firstTable.LastRow;
                table.PrependChild(currentRow);
            }
            while (currentRow != row);

            doc.Save(ExDir + "Table.SplitTable Out.doc");
            //ExEnd

            doc = new Aspose.Words.Document(ExDir + "Table.SplitTable Out.doc");
            // Test we are adding the rows in the correct order and the
            // selected row was also moved.
            Assert.AreEqual(row, table.FirstRow);

            Assert.AreEqual(2, firstTable.Rows.Count);
            Assert.AreEqual(2, table.Rows.Count);
            Assert.AreEqual(2, doc.GetChildNodes(NodeType.Table, true).Count);
        }
Esempio n. 55
0
        public void PositionSubscript()
        {
            //ExStart
            //ExFor:Font.Position
            //ExFor:Font.Subscript
            //ExFor:Font.Superscript
            //ExSummary:Shows how to use subscript, superscript and baseline text position properties.
            // Create an empty document. It contains one empty paragraph.
            Aspose.Words.Document doc = new Aspose.Words.Document();

            // Get the paragraph from the document, we will be adding runs of text to it.
            Paragraph para = (Paragraph)doc.GetChild(NodeType.Paragraph, 0, true);

            // Add a run of text that is raised 5 points above the baseline.
            Run run = new Run(doc, "Raised text");
            run.Font.Position = 5;
            para.AppendChild(run);

            // Add a run of normal text.
            run = new Run(doc, "Normal text");
            para.AppendChild(run);

            // Add a run of text that appears as subscript.
            run = new Run(doc, "Subscript");
            run.Font.Subscript = true;
            para.AppendChild(run);

            // Add a run of text that appears as superscript.
            run = new Run(doc, "Superscript");
            run.Font.Superscript = true;
            para.AppendChild(run);
            //ExEnd
        }
Esempio n. 56
0
        public void KeepTableTogether()
        {
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Table.TableAcrossPage.doc");

            // Retrieve the first table in the document.
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

            //ExStart
            //ExFor:ParagraphFormat.KeepWithNext
            //ExFor:Row.IsLastRow
            //ExFor:Paragraph.IsEndOfCell
            //ExFor:Cell.ParentRow
            //ExFor:Cell.Paragraphs
            //ExId:KeepTableTogether
            //ExSummary:Shows how to set a table to stay together on the same page.
            // To keep a table from breaking across a page we need to enable KeepWithNext
            // for every paragraph in the table except for the last paragraphs in the last
            // row of the table.
            foreach (Cell cell in table.GetChildNodes(NodeType.Cell, true))
                foreach (Paragraph para in cell.Paragraphs)
                    if (!(cell.ParentRow.IsLastRow && para.IsEndOfCell))
                        para.ParagraphFormat.KeepWithNext = true;
            //ExEnd

            doc.Save(ExDir + "Table.KeepTableTogether Out.doc");

            // Verify the correct paragraphs were set properly.
            foreach (Paragraph para in table.GetChildNodes(NodeType.Paragraph, true))
                if (para.IsEndOfCell && ((Cell)para.ParentNode).ParentRow.IsLastRow)
                    Assert.False(para.ParagraphFormat.KeepWithNext);
                else
                    Assert.True(para.ParagraphFormat.KeepWithNext);
        }
Esempio n. 57
0
        public void ScalingSpacing()
        {
            //ExStart
            //ExFor:Font.Scaling
            //ExFor:Font.Spacing
            //ExSummary:Shows how to use character scaling and spacing properties.
            // Create an empty document. It contains one empty paragraph.
            Aspose.Words.Document doc = new Aspose.Words.Document();

            // Get the paragraph from the document, we will be adding runs of text to it.
            Paragraph para = (Paragraph)doc.GetChild(NodeType.Paragraph, 0, true);

            // Add a run of text with characters 150% width of normal characters.
            Run run = new Run(doc, "Wide characters");
            run.Font.Scaling = 150;
            para.AppendChild(run);

            // Add a run of text with extra 1pt space between characters.
            run = new Run(doc, "Expanded by 1pt");
            run.Font.Spacing = 1;
            para.AppendChild(run);

            // Add a run of text with with space between characters reduced by 1pt.
            run = new Run(doc, "Condensed by 1pt");
            run.Font.Spacing = -1;
            para.AppendChild(run);
            //ExEnd
        }
Esempio n. 58
0
        public void EnsureCellMinimum()
        {
            //ExStart
            //ExFor:Cell.EnsureMinimum
            //ExSummary:Shows how to ensure a cell node is valid.
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Table.Document.doc");

            // Gets the first cell in the document.
            Cell cell = (Cell)doc.GetChild(NodeType.Cell, 0, true);

            // Ensure the cell is valid (the last child is a paragraph).
            cell.EnsureMinimum();
            //ExEnd
        }
Esempio n. 59
0
        public void RemoveBordersFromAllCells()
        {
            //ExStart
            //ExFor:Table
            //ExFor:Table.ClearBorders
            //ExSummary:Shows how to remove all borders from a table.
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Table.Document.doc");

            // Remove all borders from the first table in the document.
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

            // Clear the borders all cells in the table.
            table.ClearBorders();

            doc.Save(ExDir + "Table.ClearBorders Out.doc");
            //ExEnd
        }
Esempio n. 60
0
        public void PrintTableRange()
        {
            //ExStart
            //ExId:PrintTableRange
            //ExSummary:Shows how to print the text range of a table.
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Table.SimpleTable.doc");

            // Get the first table in the document.
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

            // The range text will include control characters such as "\a" for a cell.
            // You can call ToString on the desired node to retrieve the plain text content.

            // Print the plain text range of the table to the screen.
            Console.WriteLine("Contents of the table: ");
            Console.WriteLine(table.Range.Text);
            //ExEnd

            //ExStart
            //ExId:PrintRowAndCellRange
            //ExSummary:Shows how to print the text range of row and table elements.
            // Print the contents of the second row to the screen.
            Console.WriteLine("\nContents of the row: ");
            Console.WriteLine(table.Rows[1].Range.Text);

            // Print the contents of the last cell in the table to the screen.
            Console.WriteLine("\nContents of the cell: ");
            Console.WriteLine(table.LastRow.LastCell.Range.Text);
            //ExEnd

            Assert.AreEqual("Apples\r" + ControlChar.Cell + "20\r" + ControlChar.Cell + ControlChar.Cell, table.Rows[1].Range.Text);
            Assert.AreEqual("50\r\a", table.LastRow.LastCell.Range.Text);
        }