Localizar e Substituir em Apresentação
Contents
[
Hide
]
A seguir estão os passos a serem seguidos:
- Abrir uma apresentação.
- Pesquisar o texto.
- Substituir o texto.
- Salvar a apresentação.
string FilePath = @"..\..\..\Sample Files\";
//Abrir a apresentação
Presentation pres = new Presentation(FilePath + "Find and Replace.pptx");
//Obter todas as caixas de texto na apresentação
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)
//Encontrar o texto a ser substituído
if (port.Text.Contains(strToFind))
//Substituir o texto existente pelo novo texto
{
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);