Hitta och ersätt i presentation
Contents
[
Hide
]
Följande är stegen att följa:
- Öppna en presentation.
- Sök efter texten.
- Byt ut texten.
- Skriv presentationen.
string FilePath = @"..\..\..\Sample Files\";
//Öppna presentationen
Presentation pres = new Presentation(FilePath + "Find and Replace.pptx");
//Hämta alla textrutor i presentationen
ITextFrame[] tb = SlideUtil.GetAllTextBoxes(pres.Slides[0]);
for (int i = 0; i < tb.Length; i++)
foreach (Paragraph para in tb[i].Paragraphs)
foreach (Portion port in para.Portions)
//Hitta text som ska ersättas
if (port.Text.Contains(strToFind))
//Ersätt befintlig text med den nya texten
{
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;
}
pres.Save(FilePath + "Find and Replace.pptx",Aspose.Slides.Export.SaveFormat.Pptx);