Kaip sukurti lentelę PowerPoint naudojant Python

Šiame paprastame straipsnyje paaiškinama, kaip sukurti lentelę PowerPoint naudojant Python**. Jame pateikiama visa informacija, skirta aplinkai nustatyti, žingsnis po žingsnio procedūra, kaip įterpti ir užpildyti duomenis lentelėje, ir veikiantis pavyzdinis kodas, iliustruojantis kaip įterpti lentelę skaidrėje naudojant Python. Taip pat aprašoma, kaip formatuoti tekstą lentelės langelyje ir išsaugoti pristatymą diske PPT arba PPTX formatu.

Veiksmai, kaip sukurti lentelę PowerPoint naudojant Python

  1. Sukonfigūruokite aplinką, kad galėtumėte naudoti Aspose.Slides for Python per .NET savo programoje, kad pridėtumėte lentelę
  2. Sukurkite naują tuščią pristatymą naudodami Presentation klasę ir pasiekite pirmąją numatytąją skaidrę
  3. Į skaidrę įterpkite lentelę su apibrėžtais stulpelių pločiais ir eilučių aukščiais naudodami add_table() metodą
  4. Pereikite per kiekvieną eilutę ir atitinkamą langelį naujai pridėtoje lentelėje
  5. Kiekviename langelyje nustatykite teksto pavyzdį ir su jo šriftu susijusias savybes
  6. Išsaugokite pristatymą su lentele PPTX formatu diske

Aukščiau pateiktuose veiksmuose paaiškinama, kaip sukurti lentelę PowerPoint naudojant Python. Pirmuoju žingsniu sukursime numatytąjį pristatymą ir pasieksime pirmąją skaidrę. Tolesniuose etapuose pridėsime lentelę, pateikdami lentelės padėties koordinates kartu su stulpelių pločiais ir eilučių aukščiais. Paskutiniuose žingsniuose mes pakartosime kiekvieną langelį lentelės viduje, kad nustatytume tekstą kartu su atitinkamu formatavimu, prieš išsaugodami gautą pristatymą diske.

Kodas, skirtas pridėti lentelę PowerPoint naudojant Python

import aspose.pydrawing as draw
import aspose.slides as slides
# Path to the license file directory
filepath = "Y://Documents//KnowledgeBase//TestData//"
# Load the license in your application for creating the table
slidesTableLicense = slides.License()
slidesTableLicense.set_license(filepath + "Conholdate.Total.Product.Family.lic")
# Instantiate the Presentation object to add the table
with slides.Presentation() as presentationTable:
# Access the first default slide
slide = presentationTable.slides[0]
# Define the columns widths and rows heights
dblColsWidth = [50, 50, 50]
dblRowsHeight = [50, 30, 30, 30, 30]
# Insert the table shape to slide
table = slide.shapes.add_table(100, 50, dblColsWidth, dblRowsHeight)
# Set the border format for each cell
for rowIndex in range(len(table.rows)):
for cellIndex in range(len(table.rows[rowIndex])):
table.rows[rowIndex][cellIndex].cell_format.border_top.fill_format.fill_type = slides.FillType.SOLID
table.rows[rowIndex][cellIndex].cell_format.border_top.fill_format.solid_fill_color.color = draw.Color.red
table.rows[rowIndex][cellIndex].cell_format.border_top.width = 5
table.rows[rowIndex][cellIndex].cell_format.border_bottom.fill_format.fill_type = slides.FillType.SOLID
table.rows[rowIndex][cellIndex].cell_format.border_bottom.fill_format.solid_fill_color.color= draw.Color.red
table.rows[rowIndex][cellIndex].cell_format.border_bottom.width =5
table.rows[rowIndex][cellIndex].cell_format.border_left.fill_format.fill_type = slides.FillType.SOLID
table.rows[rowIndex][cellIndex].cell_format.border_left.fill_format.solid_fill_color.color =draw.Color.red
table.rows[rowIndex][cellIndex].cell_format.border_left.width = 5
table.rows[rowIndex][cellIndex].cell_format.border_right.fill_format.fill_type = slides.FillType.SOLID
table.rows[rowIndex][cellIndex].cell_format.border_right.fill_format.solid_fill_col or.color = draw.Color.red
table.rows[rowIndex][cellIndex].cell_format.border_right.width = 5
# Merge the cells 1 and 2 of row 1
table.merge_cells(table.rows[0][0], table.rows[1][1], False)
# Add the text inside the merged cell
table.rows[0][0].text_frame.text = "Merged Table Cells"
presentationTable.save(filepath + "NewPresentationWithTable.pptx", slides.export.SaveFormat.PPTX)
print("Done")

Šiame pavyzdyje aprašoma kaip sukurti lenteles programoje PowerPoint naudojant Python, kur lentelės klasės egzempliorius naudojamas įterpti lentelę, kurioje yra eilučių ir stulpelių rinkinys. TextFrame klasės objektas nustato pastraipos teksto tekstą, šrifto aukštį ir ženklelio tipą. Taip pat galite naudoti kitas susijusias ypatybes, pvz., paryškinti tekstą, nustatyti užpildymo formatą, pridėti arba pašalinti lauką ir nustatyti paryškinimo spalvą.

Šioje temoje paaiškinta, kaip į pristatymą įterpsite lentelę naudodami Python. Jei norite sužinoti, kaip pridėti vandens ženklo vaizdą, kad apsaugotumėte pristatymą, žr. straipsnį kaip pridėti vaizdo vandens ženklą PPTX naudojant Python.

 Latviski