文檔半島外圍網上直營>>Aspose中文文檔>>更改表格中的文本
                更改表格中的文本
Aspose.Words是一種高級Word文檔處理API,用于執行各種文檔管理和操作任務。API支持生成,修改,轉換,呈現和打印文檔,而無需在跨平臺應用程序中直接使用Microsoft Word。
Aspose API支持流行文件格式處理,并允許將各類文檔導出或轉換為固定布局文件格式和最常用的圖像/多媒體格式。
使用 Aspose.Words在 Aspose.Words 中,通常可以使用Range.Replace方法更改表格中的文本。
以下代碼示例演示如何更改表中的文本:
public void ChangeTextInATableFeature()
{
Document doc = new Document(MyDir + "Change text in a table.docx");
// 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.
FindReplaceOptions options = new FindReplaceOptions
{
MatchCase = true,
FindWholeWordsOnly = true
};
table.Rows[1].Cells[2].Range.Replace("Mr", "test", options);
doc.Save(ArtifactsDir + "Change text in a table - Aspose.Words.docx");
}
	點擊復制
使用 Open XML SDK
需要添加的命名空間:
	
using System.Linq; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; using NUnit.Framework;
點擊復制
	
以下代碼示例演示如何更改表中的文本:
	
public void ChangeTextInATableFeature()
{
// Use the file name and path passed in as an argument to 
// open an existing document.            
using (WordprocessingDocument doc =
WordprocessingDocument.Open(MyDir + "Change text in a table.docx", true))
{
// Find the first table in the document.
Table table =
doc.MainDocumentPart.Document.Body.Elements<Table>().First();
// Find the second row in the table.
TableRow row = table.Elements<TableRow>().ElementAt(1);
// Find the third cell in the row.
TableCell cell = row.Elements<TableCell>().ElementAt(2);
// Find the first paragraph in the table cell.
Paragraph p = cell.Elements<Paragraph>().First();
// Find the first run in the paragraph.
Run r = p.Elements<Run>().First();
// Set the text for the run.
Text t = r.Elements<Text>().First();
t.Text = "The text from the OpenXML API example";
}
}
	點擊復制
	

 QQ交談
QQ交談 在線咨詢
在線咨詢 
                 
                
 渝公網安備
            50010702500608號
渝公網安備
            50010702500608號
             
            
 客服熱線
客服熱線