Εύρεση και Αντικατάσταση σε Παρουσίαση

Ακολουθούν τα βήματα που πρέπει να ακολουθήσετε:

  1. Ανοίξτε μια παρουσίαση.
  2. Αναζητήστε το κείμενο.
  3. Αντικαταστήστε το κείμενο.
  4. Γράψτε την παρουσίαση.

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

//Ανοίξτε την παρουσίαση

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

//Λάβετε όλα τα πλαίσια κειμένου στην παρουσίαση

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)

        //Βρείτε το κείμενο προς αντικατάσταση

        if (port.Text.Contains(strToFind))

        //Αντικαταστήστε το υπάρχον κείμενο με το νέο κείμενο

        {

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


Κατεβάστε δείγμα κώδικα