翻譯|使用教程|編輯:李顯亮|2021-08-17 10:25:58.410|閱讀 397 次
概述:查找和替換文本通常用于更新 PowerPoint 演示文稿中的內(nèi)容。但是,為了對一批演示執(zhí)行此操作,您需要自動(dòng)化。因此,本文介紹了如何使用 C# 以編程方式查找和替換 PowerPoint PPTX/PPT 中的文本。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
查找和替換文本通常用于更新 PowerPoint 演示文稿中的內(nèi)容。但是,為了對一批演示執(zhí)行此操作,您需要自動(dòng)化。因此,本文介紹了如何使用 C# 以編程方式查找和替換 PowerPoint PPTX/PPT 中的文本。
為了查找和替換 PowerPoint 演示文稿中的文本,我們將使用Aspose.Slides for .NET,它是一個(gè)功能豐富的 API,旨在從 .NET 應(yīng)用程序中創(chuàng)建和操作 PowerPoint 演示文稿。
>>你可以點(diǎn)擊這里下載Aspose.Slides 最新版測試體驗(yàn)。
以下是使用 C# 在 PPTX 演示文稿中查找和替換文本的步驟。
以下代碼示例展示了如何在 PowerPoint 演示文稿中查找和替換文本。
// Load presentation Presentation pres = new Presentation("mytextone.pptx"); string strToFind = "search string"; string strToReplaceWith = "replace string"; // Loop through each slide foreach (Slide slide in pres.Slides) { // Get all text frames in the slide ITextFrame[] tf = SlideUtil.GetAllTextBoxes(slide); for (int i = 0; i < tf.Length; i++) foreach (Paragraph para in tf[i].Paragraphs) foreach (Portion port in para.Portions) // Find text to be replaced if (port.Text.Contains(strToFind)) { // Replace exisitng text with the new text string str = port.Text; int idx = str.IndexOf(strToFind); string strStartText = str.Substring(0, idx); string strEndText = str.Substring(idx + strToFind.Length, str.Length - 1 - (idx + strToFind.Length - 1)); port.Text = strStartText + strToReplaceWith + strEndText; } } // Save the presentation pres.Save("myTextOneAspose.pptx", SaveFormat.Pptx);
如果你想試用Aspose的全部完整功能,可聯(lián)系在線客服獲取30天臨時(shí)授權(quán)體驗(yàn)。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn