วิธีขีดฆ่าข้อความใน PPTX โดยใช้ Python

หัวข้อนี้มุ่งเน้นไปที่ วิธีขีดฆ่าข้อความใน PPTX โดยใช้ Python ประกอบด้วยรายละเอียดในการสร้างสภาพแวดล้อมพร้อมกับทรัพยากรที่จำเป็น กระบวนการทีละขั้นตอน และโค้ดตัวอย่างการทำงานเพื่อ ขีดฆ่าข้อความ PPTX โดยใช้ Python แสดงรายละเอียดขั้นตอนต่างๆ ได้แก่ การสร้างตัวอย่างงานนำเสนอ การใส่ autoshape การเพิ่มกรอบข้อความโดยการใส่ข้อความและการขีดฆ่าข้อความ

ขั้นตอนในการขีดฆ่าข้อความใน PPTX โดยใช้ Python

  1. สร้างสภาพแวดล้อมเป็น ใช้ Aspose.Slides สำหรับ Python ผ่าน .NET เพื่อขีดฆ่าข้อความใน PPTX
  2. สร้างงานนำเสนอว่างเริ่มต้นโดยใช้อินสแตนซ์ของคลาส Presentation และเข้าถึงสไลด์แรก
  3. สร้างรูปร่างอัตโนมัติและใส่กรอบข้อความตัวอย่างเข้าไปข้างใน
  4. แทรกส่วนของข้อความภายในกรอบข้อความและตั้งค่าการขีดเส้นคู่ผ่านสำหรับข้อความส่วนโดยใช้ตัวแจงนับ TextStrikethroughType
  5. แทรกข้อความส่วนที่สองภายในกรอบข้อความและตั้งค่าการขีดฆ่าบรรทัดเดียวสำหรับข้อความส่วนโดยใช้ตัวแจง TextStrikethroughType
  6. บันทึกงานนำเสนอ PPTX ด้วยการขีดทับข้อความบนดิสก์

ขั้นตอนข้างต้นแสดง วิธีขีดฆ่าข้อความในการนำเสนอโดยใช้ Python โดยเปิดเผยรายละเอียดเกี่ยวกับคลาส เมธอด และคุณสมบัติที่จำเป็นทั้งหมดเพื่อให้ได้ผลลัพธ์ที่ต้องการ คลาสการนำเสนอใช้เพื่อสร้างไฟล์ว่างหรือโหลดไฟล์ PPTX ที่มีอยู่ คลาส ShapeCollection ใช้เพื่อเพิ่มรูปร่างอัตโนมัติในสไลด์ PPTX และใช้ตัวแจงนับ TextStrikethroughType เพื่อตั้งค่าประเภทการขีดฆ่าข้อความที่จำเป็นสำหรับส่วนที่เลือก

รหัสเพื่อขีดฆ่าข้อความใน PPTX โดยใช้ 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 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")

โค้ดตัวอย่างข้างต้น ขีดฆ่าข้อความใน PPT โดยใช้ Python ใช้อินสแตนซ์ของคลาส Presentation เพื่อสร้างงานนำเสนอเปล่าเริ่มต้น และใช้คุณสมบัติ Presentation.Slides เพื่อเข้าถึงสไลด์แรกภายในคอลเลกชันสไลด์นำเสนอ มีการแทรกรูปร่างอัตโนมัติ ซึ่งตามด้วยการแทรกส่วนของข้อความภายในนั้น สุดท้าย ด้วยความช่วยเหลือของตัวแจงนับ TextStrikethroughType ข้อความที่ต้องการจะถูกขีดฆ่าในงานนำเสนอและบันทึกไว้ในดิสก์

ในบทช่วยสอนนี้ เราได้เรียนรู้การ ขีดฆ่าข้อความนำเสนอโดยใช้ Python หากคุณสนใจที่จะเรียนรู้เกี่ยวกับการรวม Islides ไว้ในงานนำเสนอ โปรดดูบทความใน วิธีผสานไฟล์ PowerPoint โดยใช้ Python

 ไทย