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

ตัวอย่างสั้นๆ นี้ประกอบด้วย วิธีขีดฆ่าข้อความใน PPTX โดยใช้ C# โดยจะครอบคลุมข้อมูลเกี่ยวกับทรัพยากรที่จำเป็น กระบวนการทีละขั้นตอน และโค้ดตัวอย่างที่ใช้งานได้เพื่อ ขีดฆ่าข้อความ PPTX โดยใช้ c# มันแชร์รายละเอียดกระบวนการรวมถึงการสร้างงานนำเสนอตัวอย่าง การเพิ่มรูปร่างอัตโนมัติ การสร้างกรอบข้อความโดยการเพิ่มข้อความ และการขีดฆ่าข้อความ

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

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

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

รหัสเพื่อขีดฆ่าข้อความใน PPTX โดยใช้ C#

using System;
using System.Drawing;
using Aspose.Slides;
using Aspose.Slides.Export;
namespace TestSlides
{
public class StrikeThroughText
{
public static void StrikeText()
{
String path = @"/Users/KnowledgeBase/TestData/";
//Setting the API linence
License SlidesLicense = new License();
SlidesLicense.SetLicense(path + "Conholdate.Total.Product.Family.lic");
//Instantiate a Presentation class object to create a presentation
using (Presentation presentation = new Presentation())
{
//Insert a Blank empty slide inside the presentation
ISlide slide = presentation.Slides.AddEmptySlide(presentation.LayoutSlides.GetByType(SlideLayoutType.Blank));
//Add a new autoshape of the Rectangle type
IAutoShape autoShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 0, 120, 300, 300);
// Filling the shape with no fill color
autoShape.FillFormat.FillType = FillType.NoFill;
//Add the text frame inside the autoshape
ITextFrame textFrame = autoShape.AddTextFrame("This is sample strikethrough text");
// Set the textual properties on the portion
IPortionFormat portionFormat = textFrame.Paragraphs[0].Portions[0].PortionFormat;
portionFormat.FillFormat.FillType = FillType.Solid;
portionFormat.FillFormat.SolidFillColor.Color = Color.Red;
//Strikethrough with a double line
portionFormat.StrikethroughType = TextStrikethroughType.Double;
//Add a second line of text inside the shape
IPortion secondPortion = new Portion("Second text line ");
textFrame.Paragraphs[0].Portions.Add(secondPortion);
portionFormat = secondPortion.PortionFormat;
portionFormat.FillFormat.FillType = FillType.Solid;
portionFormat.FillFormat.SolidFillColor.Color = Color.Blue;
//Strikethrouh with a single line
portionFormat.StrikethroughType = TextStrikethroughType.Single;
// Save the presentation with strikethrough text on the disk
presentation.Save(path + "StrikethroughText.pptx", SaveFormat.Pptx);
}
}
}
}

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

บทช่วยสอนนี้แนะนำให้เรา ขีดฆ่าข้อความนำเสนอโดยใช้ C# หากคุณต้องการเรียนรู้ขั้นตอนการรวมสไลด์ภายในงานนำเสนอ โปรดดูบทความใน วิธีผสานสไลด์ใน C#

 ไทย