Bunachar Eolais

Python PPTX | Conas láimhseáil le cur i láthair PowerPoint

Más mian leat a fháil amach conas cur i láthair PowerPoint agus OpenOffice a chruthú, a léamh, a shaincheapadh, a chomhcheangal, a chóipeáil nó a thiontú ag baint úsáide as Python gan gá le bogearraí seachtracha eile, táimid cúramach ort.

Aspose.Slides for Python via .NET ná leabharlann ranganna chun cur i láthair a láimhseáil, ag tairgiú go leor gnéithe tábhachtacha mar chruthú cur i láthair ón nialas, tiontú cur i láthair, bainistíocht téacsanna, cruthanna, táblaí, beochan, réamhamharc sleamhnán, easpórtáil sleamhnáin go PDF, TIFF, XPS, HTML, srl., agus go leor gnéithe eile. Soláthraíonn Aspose.Slides for Python via .NET taispeántais agus samplaí oibre chun cabhrú leat tuiscint níos fearr a fháil ar ár API.

Cuireann ár API na gnéithe seo a leanas ar fáil:

• Cruthú nó cóipeáil sleamhnán ó teimpléid
• Oibriú le táblaí PowerPoint
• Bain nó cuir cosaint ar chruthanna
• Cuir cairtí MS Excel leis mar OleObjects
• Giniúint cur i láthair ón bhunachar sonraí
• Cosaint cur i láthair
• Cruthú agus modhnú cairteacha
• Easpórtáil cur i láthair go PDF, XPS, HTML, JPEG, PNG, SVG, agus go leor eile

Formáidí comhaid a dtacaítear leo:

Is féidir le Aspose.Slides for Python via .NET comhaid a luchtú agus a shábháil i na formáidí comhaid seo a leanas: PPT, POT, PPS, PPTX, POTX, PPSX, PPTM, PPSM, POTM, ODP, OTP, agus sábháil i na formáidí seo a leanas: TIFF, EMF, PDF, XPS, JPEG, PNG, GIFF, BMP, SVG, SWF, HTML, XAML.

Thíos, taispeánfaimid duit conas cur i láthair a chruthú, a oscailt, a chumasc, agus a shábháil, agus cuirfimid samplaí cód ar fáil.

Python PPTX | Conas láimhseáil le cur i láthair PowerPoint

Conas cur i láthair PowerPoint (PPTX) a chruthú ag baint úsáide as Python

Chun líne nua a chur le sleamhnán ag baint úsáide as Aspose.Slides for Python via .NET, lean na céimeanna seo:

  1. Cruthaigh sampla de rang Presentation
  2. Faigh tagairt sleamhnáin ag baint úsáide as a Innéacs
  3. Ag baint úsáide as an modh add_auto_shape a nochtann an réad shapes, cuir AutoShape den chineál LINE leis
  4. Sábháil an cur i láthair mar chomhad PPTX
import aspose.slides as slides  

# Instantiate a Presentation object that represents a presentation file
with slides.Presentation() as presentation:
    slide = presentation.slides[0]
    slide.shapes.add_auto_shape(slides.ShapeType.LINE, 50, 150, 300, 0)
    presentation.save("NewPresentation_out.pptx", slides.export.SaveFormat.PPTX)

Conas cur i láthair a oscailt ag baint úsáide as Python

Ag baint úsáide as Aspose.Slides for Python via .NET, is féidir le forbróirí rochtain a fháil ar chur i láthair PowerPoint atá ann cheana nó iad a mhodhnú.

Soláthraíonn ár API rang Presentation chun cur i láthair atá ann cheana a oscailt, agus is féidir linn ceann de na tógálaithe oiriúnacha den rang Presentation a úsáid chun a réad a chruthú bunaithe ar chur i láthair PowerPoint atá ann cheana. Sa shampla thíos, taispeánfaimid conas Presentation a oscailt. Sheachuramar ainm an chomhaid cur i láthair chuig tógálaí rang Presentation, agus faighimid an líon iomlán sleamhnán le priontáil ar an scáileán.

import aspose.slides as slides

# Opening the presentation file by passing the file path to the constructor of Presentation class
with slides.Presentation("pres.pptx") as pres:
    # Printing the total number of slides present in the presentation
    print(pres.slides.length)

Agus má tá cur i láthair an-mhór agat (a deirfimid go bhfuil an cur i láthair 3 GB), is féidir leat iad a oscailt leis an gcód sampla a thugtar thíos:

import aspose.slides as slides
import os

loadOptions = slides.LoadOptions()
loadOptions.blob_management_options = slides.BlobManagementOptions()
loadOptions.blob_management_options.presentation_locking_behavior = slides.PresentationLockingBehavior.KEEP_LOCKED

with slides.Presentation("pres.pptx", loadOptions) as pres:
    # the huge presentation is loaded and ready to use, but the memory consumption is still low.

    # make any changes to the presentation.
    pres.slides[0].name = "Very large presentation"

    # presentation will be saved to the other file, the memory consumptions still low during saving.
    pres.save("veryLargePresentation-copy.pptx", slides.export.SaveFormat.PPTX)

    # can't do that! IO exception will be thrown, because the file is locked while pres objects will
    # not be disposed
    os.remove("pres.pptx")

# it's ok to do it here, the source file is not locked by pres object
os.remove("pres.pptx")

*Más tá cur i láthair a chruthaíonn tú a bhfuil réada móra ann (íomhánna an-mhóra, físeán, fuaim, srl.), bain úsáid as Áis Blob chun tomhas cuimhne a laghdú.

Conas cur i láthair PowerPoint a chumasc ag baint úsáide as Python

Ceadaíonn Aspose.Slides for Python via .NET duit cur i láthair a chumasc ar bhealaí éagsúla. Is féidir leat cur i láthair PowerPoint a chumasc lena gcruthanna, formáidiú, téacsanna, stíleanna, nótaí, srl. gan cáilíocht nó sonraí a chailliúint. Le ár API, is féidir leat cur i láthair iomlán, sleamhnáin ar leith, agus cur i láthair i bhformáid amháin (PPTX go PPTX, PPT go PPT, srl.) a chumasc, nó i bhformáidí éagsúla (PPTX go PPT, PPTX go ODP, srl.).

Chun cur i láthair a chumasc is féidir leat úsáid a bhaint as add_clone (ón gcomhéadan ISlideCollection ). Tá bailiúchán sleamhnán ag an réad Presentation, agus is féidir leat an modh add_clone a ghlaoch óna chur i láthair roghnaithe, agus sa chur i láthair sin cuirfear na sleamhnáin le chéile.

Cumasc cur i láthair

Ag baint úsáide as an modh AddClone (ISlide) is féidir leat sleamhnáin a chomhcheangal gan imní ort go gcaillfidh na sleamhnáin a n-aimsire agus a stíleanna (paraiméadair réamhshocraithe).
Sa chód thíos, is féidir leat a fheiceáil conas cur i láthair a chumasc:

import aspose.slides as slides

with slides.Presentation("pres.pptx") as pres1:
    with slides.Presentation("Presentation1.pptx") as pres2:
        for slide in pres2.slides:
            pres1.slides.add_clone(slide)
        pres1.save("combined.pptx", slides.export.SaveFormat.PPTX)

Cumasc an cur i láthair agus athraigh stíl na sleamhnán
Más mian leat stíl na sleamhnán sa chur i láthair aschurtha a athrú agus tú ag cumasc sleamhnán, ceadaíonn an modh add_clone (ISlide, IMasterSlide, Boolean) é seo duit.

import aspose.slides as slides

with slides.Presentation("pres.pptx") as pres1:
    with slides.Presentation("Presentation1.pptx") as pres2:
        for slide in pres2.slides:
            pres1.slides.add_clone(slide, pres1.masters[0], allow_clone_missing_layout = True)
        pres1.save("combined_with_master.pptx", slides.export.SaveFormat.PPTX)

Cumasc sleamhnáin ar leith
Ag baint úsáide as an cód thíos, is féidir leat sleamhnáin ar leith a roghnú agus a chomhcheangal ó chur i láthair éagsúla, ag cruthú cur i láthair aschurtha amháin:

import aspose.slides as slides

with slides.Presentation("pres.pptx") as pres1:
    with slides.Presentation("Presentation1.pptx") as pres2:
        for slide in pres2.slides:
            pres1.slides.add_clone(slide, pres1.layout_slides[0])
        pres1.save("combined_with_layout.pptx", slides.export.SaveFormat.PPTX)

Le haghaidh tuilleadh bealaí chun cur i láthair a chumasc, féach an rannán Cumasc Cur I láthair sa doiciméadú.

Conas cur i láthair PowerPoint a shábháil ag baint úsáide as Python

Le Aspose.Slides for Python via .NET is féidir leat cur i láthair a shábháil mar chomhad nó sruth. Thíos, cuirfimid cód sampla ar fáil do na dá mhodh.

Sábháil cur i láthair mar chomhaid
Is féidir leat cur i láthair a shábháil mar chomhaid trí ghlaoch ar an modh Save den rang Presentation .

Sa chód thíos, is féidir leat a fheiceáil conas cur i láthair a shábháil le Aspose.Slides for Python via .NET ag baint úsáide as Python trí ainm an chomhaid agus formáid shábhála a chur chuig an modh Save.

import aspose.slides as slides

# Instantiate a Presentation object that represents a PPT file
with slides.Presentation() as presentation:
    
    #...do some work here...

    # Save your presentation to a file
    presentation.save("Saved_out.pptx", slides.export.SaveFormat.PPTX)

Sábháil cur i láthair go sruthanna
Is bealach amháin chun cur i láthair a shábháil ná é a shábháil go sruth. Cuir sruth aschurtha go simplí chuig an modh Save den rang Presentation . Sa chód thíos, chruthaíomar comhad Presentation nua, chuir muid téacs leis an gcruth, agus shábháil muid an cur i láthair chuig an sruth.

import aspose.slides as slides

# Instantiate a Presentation object that represents a PPT file
with slides.Presentation() as presentation:
    
    shape = presentation.slides[0].shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 200, 200, 200, 200)

    # Save your presentation to a stream
    with open("Save_As_Stream_out.pptx", "bw") as stream:
        presentation.save(stream, slides.export.SaveFormat.PPTX)

Sa doiciméadú, is féidir leat a fháil amach conas sábháil cur i láthair le Cineál Amhairc réamhshainithe , sábháil cur i láthair i bhformáid dhuilleog shriosta Strict Open XML , nó sábháil nuashonruithe dul chun cinn i gcéatadán .

Tá Aspose.Slides for Python via .NET comhoiriúnach le Python 3.5, 3.6, 3.7, 3.8, 3.9, agus más mian leat cód Python a scríobh ar Linux, is féidir leat riachtanais do Linux a sheiceáil.

Comhairle Íoctha

Más gá cabhair duit le do thionscadal, tá saineolaithe againn a oibreoidh leat ar do thionscadal, dearadh réiteach, agus cur i bhfeidhm ár API de réir do riachtanas. Déanfaimid an obair chrua ionas gur féidir leat díriú ar do ghnó.