Как вы перебираете таблицу и редактируете информацию с помощью pptx в python? - PullRequest
1 голос
/ 01 мая 2020

Как вы перебираете таблицу, находите и заменяете текст? Я могу go через текстовые поля, как показано ниже, но мне нужна возможность доступа и редактирования информации в таблице:

for slide in prs.slides:
    for shape in slide.shapes:
        if shape.has_text_frame: 
            j = 0
            k = 0
            for i in searchList:  
                #find the search term from the searchList
                searchString = searchList[j]
                j+=1
                #replace the search term from the dataframe
                dfIndexName = dfIndex.keys()[k]
                k+=1
                replaceString = df.at[0, dfIndexName] 
                if (shape.text.find(searchString))!=1: 
                    text_frame = shape.text_frame
                    cur_text = text_frame.paragraphs[0].runs[0].text
                    new_text = cur_text.replace(searchString, str(replaceString))
                    text_frame.paragraphs[0].runs[0].text = new_text  

Спасибо!

1 Ответ

0 голосов
/ 09 мая 2020

Я не уверен, что вы хотите сделать с searchList, но именно так вы можете получить доступ к ячейкам в таблице.

  for slide in prs.slides:
    for shape in slide.shapes:
      if shape.has_table: 
        table = shape.table
        for cell in iter_cells(table):
          # do something with cell
...