本文整理汇总了C#中Document.GetChild方法的典型用法代码示例。如果您正苦于以下问题:C# Document.GetChild方法的具体用法?C# Document.GetChild怎么用?C# Document.GetChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Document
的用法示例。
在下文中一共展示了Document.GetChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CombineRows
/// <summary>
/// Shows how to combine the rows from two tables into one.
/// </summary>
private static void CombineRows(string dataDir, string fileName)
{
// ExStart:CombineRows
// Load the document.
Document doc = new Document(dataDir + fileName);
// 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();
dataDir = dataDir + "Table.CombineTables_out.doc";
// Save the finished document.
doc.Save(dataDir);
// ExEnd:CombineRows
Console.WriteLine("\nRows combine successfully from two tables into one.\nFile saved at " + dataDir);
}
示例2: Run
public static void Run()
{
// ExStart:ExtractContentBetweenCommentRange
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithDocument();
Document doc = new Document(dataDir + "TestFile.doc");
// This is a quick way of getting both comment nodes.
// Your code should have a proper method of retrieving each corresponding start and end node.
CommentRangeStart commentStart = (CommentRangeStart)doc.GetChild(NodeType.CommentRangeStart, 0, true);
CommentRangeEnd commentEnd = (CommentRangeEnd)doc.GetChild(NodeType.CommentRangeEnd, 0, true);
// Firstly extract the content between these nodes including the comment as well.
ArrayList extractedNodesInclusive = Common.ExtractContent(commentStart, commentEnd, true);
Document dstDoc = Common.GenerateDocument(doc, extractedNodesInclusive);
dstDoc.Save(dataDir + "TestFile.CommentInclusive_out.doc");
// Secondly extract the content between these nodes without the comment.
ArrayList extractedNodesExclusive = Common.ExtractContent(commentStart, commentEnd, false);
dstDoc = Common.GenerateDocument(doc, extractedNodesExclusive);
dstDoc.Save(dataDir + "TestFile.CommentExclusive_out.doc");
// ExEnd:ExtractContentBetweenCommentRange
Console.WriteLine("\nExtracted content between the comment range successfully.\nFile saved at " + dataDir + "TestFile.CommentExclusive_out.doc");
}
示例3: Main
static void Main(string[] args)
{
// Check for license and apply if exists
string licenseFile = AppDomain.CurrentDomain.BaseDirectory + "Aspose.Words.lic";
if (File.Exists(licenseFile))
{
// Apply Aspose.Words API License
Aspose.Words.License license = new Aspose.Words.License();
// Place license file in Bin/Debug/ Folder
license.SetLicense("Aspose.Words.lic");
}
// Load the document.
Document doc = new Document("../../data/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("Table.CombineTables Out.doc");
}
示例4: ExtractPrintText
private static void ExtractPrintText(string dataDir)
{
// ExStart:ExtractText
Document doc = new Document(dataDir);
// 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 and pass SaveFormat.Text on the desired node to find 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:ExtractText
// ExStart:PrintTextRangeOFRowAndTable
// 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:PrintTextRangeOFRowAndTable
}
示例5: RenderCellToImage
public static void RenderCellToImage(string dataDir, Document doc)
{
Cell cell = (Cell)doc.GetChild(NodeType.Cell, 2, true); // The third cell in the first table.
RenderNode(cell, dataDir + "TestFile.RenderCell Out.png", null);
Console.WriteLine("\nCell rendered to image successfully.\nFile saved at " + dataDir + "TestFile.RenderCell Out.png");
}
示例6: Run
public static void Run()
{
// ExStart:ExtractContentBetweenRuns
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithDocument();
string fileName = "TestFile.doc";
Document doc = new Document(dataDir + fileName);
// Retrieve a paragraph from the first section.
Paragraph para = (Paragraph)doc.GetChild(NodeType.Paragraph, 7, true);
// Use some runs for extraction.
Run startRun = para.Runs[1];
Run endRun = para.Runs[4];
// Extract the content between these nodes in the document. Include these markers in the extraction.
ArrayList extractedNodes = Common.ExtractContent(startRun, endRun, true);
// Get the node from the list. There should only be one paragraph returned in the list.
Node node = (Node)extractedNodes[0];
// Print the text of this node to the console.
Console.WriteLine(node.ToString(SaveFormat.Text));
// ExEnd:ExtractContentBetweenRuns
Console.WriteLine("\nExtracted content betweenn the runs successfully.");
}
示例7: Run
public static void Run()
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithTables() + "Table.SimpleTable.doc";
Document doc = new Document(dataDir);
// ExStart:RetrieveTableIndex
// Get the first table in the document.
Table table = (Table)doc.GetChild(NodeType.Table, 0, true);
NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
int tableIndex = allTables.IndexOf(table);
// ExEnd:RetrieveTableIndex
Console.WriteLine("\nTable index is " + tableIndex.ToString());
// ExStart:RetrieveRowIndex
int rowIndex = table.IndexOf((Row)table.LastRow);
// ExEnd:RetrieveRowIndex
Console.WriteLine("\nRow index is " + rowIndex.ToString());
Row row = (Row)table.LastRow;
// ExStart:RetrieveCellIndex
int cellIndex = row.IndexOf(row.Cells[4]);
// ExEnd:RetrieveCellIndex
Console.WriteLine("\nCell index is " + cellIndex.ToString());
}
示例8: InsertNewColumnIntoTable
public void InsertNewColumnIntoTable()
{
Document doc = new 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].ToTxt().Trim());
Assert.AreEqual("Column Text 3", table.LastRow.Cells[1].ToTxt().Trim());
}
示例9: Main
static void Main(string[] args)
{
// Load the document.
Document doc = new Document("../../data/document.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("Table.SplitTable Out.doc");
}
示例10: Main
static void Main(string[] args)
{
string MyDir = @"E:\Aspose\Aspose Vs OpenXML\Missing Features of OpenXML Words Provided by Aspose.Words v1.1\Sample Files\";
// Load the document.
Document doc = new 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");
}
示例11: ApplyOutlineBorder
/// <summary>
/// Shows how to apply outline border to a table.
/// </summary>
private static void ApplyOutlineBorder(string dataDir)
{
// ExStart:ApplyOutlineBorder
Document doc = new Document(dataDir + "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);
dataDir = dataDir + "Table.SetOutlineBorders_out.doc";
// Save the document to disk.
doc.Save(dataDir);
// ExEnd:ApplyOutlineBorder
Console.WriteLine("\nOutline border applied successfully to a table.\nFile saved at " + dataDir);
}
示例12: AddEx
public void AddEx()
{
//ExStart
//ExFor:TabStopCollection.Add(TabStop)
//ExFor:TabStopCollection.Add(Double, TabAlignment, TabLeader)
//ExSummary:Shows how to create tab stops and add them to a document.
Document doc = new Document(MyDir + "Document.doc");
Paragraph paragraph = (Paragraph)doc.GetChild(NodeType.Paragraph, 0, true);
// Create a TabStop object and add it to the document.
TabStop tabStop = new TabStop(ConvertUtil.InchToPoint(3), TabAlignment.Left, TabLeader.Dashes);
paragraph.ParagraphFormat.TabStops.Add(tabStop);
// Add a tab stop without explicitly creating new TabStop objects.
paragraph.ParagraphFormat.TabStops.Add(ConvertUtil.MillimeterToPoint(100), TabAlignment.Left, TabLeader.Dashes);
// Add tab stops at 5 cm to all paragraphs.
foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
para.ParagraphFormat.TabStops.Add(ConvertUtil.MillimeterToPoint(50), TabAlignment.Left, TabLeader.Dashes);
}
doc.Save(MyDir + @"\Artifacts\Document.AddedTabStops.doc");
//ExEnd
}
示例13: CloneLastRow
/// <summary>
/// Shows how to clone last row of table.
/// </summary>
private static void CloneLastRow(string dataDir)
{
// ExStart:CloneLastRow
Document doc = new Document(dataDir + "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);
dataDir = dataDir + "Table.AddCloneRowToTable_out.doc";
// Save the document to disk.
doc.Save(dataDir);
// ExEnd:CloneLastRow
Console.WriteLine("\nTable last row cloned successfully.\nFile saved at " + dataDir);
}
示例14: 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.
Document doc = new 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.ToTxt().Trim());
Assert.AreEqual(2, table.LastRow.Cells.Count);
}
示例15: Main
static void Main(string[] args)
{
Document doc = new Document("Change text in a table.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 last cell of the table only.
table.Rows[1].Cells[2].Range.Replace("Mr", "test", true, true);
doc.Save("Change text in a table.doc");
}