Home > Enterprise >  How to automate deletion of all text with Strikethrough formatting in a PowerPoint presentation?
How to automate deletion of all text with Strikethrough formatting in a PowerPoint presentation?

Time:10-16

How can I automate the deletion of all text with Strikethrough formatting in a PowerPoint presentation?

I found this useful link to do it in Excel: enter image description here

To give a bit more details about how those tables are stored in the presentation, this is the code I have in python-pptx to get to one of the tables:

import pptx

def parse_pptx(file_name):
    prs = pptx.Presentation(file_name)
    slides = prs.slides
    for i, slide in enumerate(slides):
        if i == 66:
            shapes = slide.shapes
            for shape in shapes:
                if type(shape) == pptx.shapes.graphfrm.GraphicFrame and shape.has_table:
                    table = shape.table
                    if "Test_Table_1" in table.cell(0, 0).text:
                        for j in range(len(table.rows)):
                            for i in range(len(table.columns)):
                                print(table.cell(j, i).text, end=", ")
                            print("")


if __name__ == "__main__":
    pptx_name = Path("test.pptx")
    parse_pptx(pptx_name)

CodePudding user response:

If the 'tables' in discussion really are PowerPoint (inserted) tables, please, try using the next code:

Sub testIterateShapesType()
     Dim sl As Slide, sh As Shape, tbl As Table, i As Long, j As Long, k As Long
     
     For Each sl In ActivePresentation.Slides
        For Each sh In sl.Shapes
            If sh.Type = msoTable Then
                Set tbl = sh.Table
                For i = 1 To tbl.Rows.Count
                    For j = 1 To tbl.Columns.Count
                        For k = tbl.Cell(i, j).Shape.TextFrame2.TextRange.Characters.Count To 1 Step -1
                            If tbl.Cell(i, j).Shape.TextFrame2.TextRange.Characters(k, 1).Font.Strikethrough Then
                                tbl.Cell(i, j).Shape.TextFrame2.TextRange.Characters(k, 1) = ""
                            End If
                        Next k
                    Next j
                Next i
            End If
        Next
     Next
End Sub

Please, send some feedback after testing it.

  • Related