本文整理汇总了C#中Aspose.Words.Document.GetChild方法的典型用法代码示例。如果您正苦于以下问题:C# Document.GetChild方法的具体用法?C# Document.GetChild怎么用?C# Document.GetChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Aspose.Words.Document
的用法示例。
在下文中一共展示了Document.GetChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InsertNewColumnIntoTable
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());
}
示例2: AddClonedRowToTable
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);
}
示例3: TableColumnToTxt
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());
}
示例4: RemoveColumnFromTable
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());
}
示例5: CheckShapeInline
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);
}
示例6: GetFieldFromDocument
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
}
示例7: Caps
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
}
示例8: TableStyleToDirectFormatting
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);
}
示例9: TestNodeChangingInDocument
//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);
}
示例10: InsertImageFromUrl
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);
}
示例11: BuildSimpleTable
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);
}
示例12: Strikethrough
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
}
示例13: PrintTableRange
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);
}
示例14: GetFieldType
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
}
示例15: ReplaceTextInTable
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());
}