Cari dan Ganti dalam Presentasi

Berikut adalah langkah-langkah yang harus diikuti:

  1. Buka presentasi.
  2. Cari teks.
  3. Ganti teks.
  4. Tuliskan presentasi.

 string FilePath = @"..\..\..\Sample Files\";

//Buka presentasi

Presentation pres = new Presentation(FilePath + "Find and Replace.pptx");

//Dapatkan semua kotak teks dalam presentasi

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)

        //Cari teks yang akan diganti

        if (port.Text.Contains(strToFind))

        //Ganti teks yang ada dengan teks baru

        {

            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);


Unduh Kode Contoh