이 주제는 Python을 사용하여 PPTX에서 텍스트를 취소선으로 지우는 방법에 중점을 둡니다. 여기에는 필요한 리소스, 단계별 절차 및 Python을 사용하여 PPTX 텍스트를 삭제하는 작업 예제 코드와 함께 환경을 설정하는 세부 정보가 포함되어 있습니다. 샘플 프레젠테이션 생성, 자동 모양 삽입, 텍스트 삽입 및 텍스트 삭제를 통한 텍스트 프레임 추가를 포함한 프로세스 세부 정보를 보여줍니다.
Python을 사용하여 PPTX에서 텍스트를 취소하는 단계
- PPTX에서 텍스트를 취소선으로 지우려면 환경을 .NET을 통해 Python용 Aspose.Slides 사용로 설정하세요.
- Presentation 클래스의 인스턴스를 사용하여 비어 있는 기본 프레젠테이션을 생성하고 첫 번째 슬라이드에 액세스
- 자동 모양을 만들고 그 안에 샘플 텍스트 프레임을 삽입합니다.
- 텍스트 프레임 안에 텍스트의 일부를 삽입하고 TextStrikethroughType 열거자를 사용하여 부분 텍스트에 이중선 취소선을 설정합니다.
- 텍스트 프레임 안에 텍스트의 두 번째 부분을 삽입하고 TextStrikethroughType 열거자를 사용하여 해당 부분 텍스트에 대한 한 줄 취소선을 설정합니다.
- 텍스트에 취소선이 있는 PPTX 프레젠테이션을 디스크에 저장합니다.
위의 단계는 원하는 출력을 얻기 위해 필요한 모든 클래스, 메서드 및 속성에 대한 세부 정보를 노출하여 Python을 사용하여 Presentation에서 텍스트를 삭제하는 방법을 보여줍니다. Presentation 클래스는 비어 있는 PPTX 파일을 만들거나 기존 PPTX 파일을 로드하는 데 사용되고, ShapeCollection 클래스는 PPTX 슬라이드에 자동 모양을 추가하는 데 사용되며, TextStrikethroughType 열거자는 선택한 부분에 필요한 텍스트 취소선 유형을 설정하는 데 사용됩니다.
Python을 사용하여 PPTX에서 텍스트를 취소하는 코드
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 a strikethrough text | |
slidesTextLicense = slides.License() | |
slidesTextLicense.set_license(filepath + "Conholdate.Total.Product.Family.lic") | |
# Instantiate the Presentation object to strikethrough text | |
with slides.Presentation() as presentationText: | |
#Access the first default slide | |
slide = presentationText.slides[0] | |
#Add an autoshape of the Rectangle type | |
autoShape = slide.shapes.add_auto_ahape(slides.ShapeType.Rectangle, 50, 150, 300, 0) | |
#Filling the shape with no fill color | |
autoShape.fill_format.fill_type = slides.FillType.NoFill | |
#Add the text frame inside the autoshape | |
textFrame = autoShape.add_text_frame("This is sample strikethrough text") | |
#Set the textual properties on the portion | |
portionFormat = textFrame.paragraphs[0].portions[0].portion_format | |
portionFormat.fill_format.fill_type = slides.FillType.Solid | |
portionFormat.fill_format.solid_fill_color.dolor = draw.Color.red | |
#Strikethrouh with double line | |
portionFormat.strikethrough_type = slides.TextStrikethroughType.Double; | |
#Add a second line of text | |
secondPortion = slides.Portion("Second text line ") | |
textFrame.Paragraphs[0].Portions.Add(secondPortion) | |
portionFormat = secondPortion.PortionFormat | |
portionFormat.fill_format.fill_type = slides.FillType.Solid | |
portionFormat.fill_format.solid_fill_color.color = draw.Color.blue | |
#Strikethrouh with a single line | |
portionFormat.strikethrough_type = slides.TextStrikethroughType.Single | |
#Save the presentation with strikethrough text on the disk | |
presentationText.save(filepath + "StrikethroughText.pptx", slides.export.SaveFormat.Pptx) | |
print("Done") |
위의 예제 코드는 Python을 사용하는 PPT의 취소선 텍스트입니다. Presentation 클래스 인스턴스를 사용하여 빈 기본 프레젠테이션을 생성하고 Presentation.Slides 속성을 사용하여 프레젠테이션 슬라이드 컬렉션 내의 첫 번째 슬라이드에 액세스합니다. 자동 모양이 삽입된 다음 그 안에 텍스트 부분이 삽입됩니다. 마지막으로 TextStrikethroughType 열거자를 사용하여 프레젠테이션에서 원하는 텍스트를 삭제하고 디스크에 저장합니다.
이 자습서에서는 Python을 사용하여 프레젠테이션 텍스트를 삭제하는 방법을 배웠습니다. 프레젠테이션 내에서 Islides를 병합하는 방법에 대해 알아보려면 Python을 사용하여 PowerPoint 파일을 병합하는 방법의 문서를 참조하세요.