จัดรูปแบบข้อความการนำเสนอบน Android
ภาพรวม
บทความนี้แสดงวิธีจัดรูปแบบข้อความในงานนำเสนอ PowerPoint และ OpenDocument โดยใช้ Aspose.Slides สำหรับ Android ผ่าน Java. ครอบคลุมสีพื้นหลัง, ความโปร่งใส, การเว้นระยะอักขระ, คุณสมบัติของฟอนต์, การหมุน, ระยะห่างย่อหน้า, พฤติกรรม autofit, การยึดข้อความ, จุดหยุดแท็บ, และการตั้งค่าภาษา
หากไม่มีการระบุเป็นอย่างอื่น ตัวอย่างจะใช้ sample.pptx. รูปร่างแรกบนสไลด์แรกเป็นกล่องข้อความและย่อหน้าแรกของมันมีข้อความดังที่แสดงด้านล่าง ทั้งดัชนีสไลด์และรูปทรงเริ่มจากศูนย์ ตัวอย่างที่เลือกส่วนข้อความหนาใช้การจัดรูปแบบที่มีผลรวม รวมถึงการจัดรูปแบบหนาที่สืบทอดมา:

เพื่อค้นหาและเน้นข้อความที่ตรงตามตัวอักษรหรือการจับคู่แบบ regular-expression ดูที่ ค้นหาและแทนที่ข้อความ.
ตั้งค่าสีพื้นหลังของข้อความ
ใช้ IParagraphFormat.getDefaultPortionFormat เพื่อกำหนดสีไฮไลท์เริ่มต้นสำหรับย่อหน้า หรือใช้ IBasePortionFormat.getHighlightColor สำหรับส่วนข้อความแต่ละส่วน
ตัวอย่างต่อไปนี้กำหนดไฮไลท์สีเทาอ่อนเป็นค่าเริ่มต้นสำหรับย่อหน้าแรก สีไฮไลท์ที่กำหนดโดยตรงบนส่วนข้อความแต่ละส่วนจะมีลำดับความสำคัญเหนือค่าเริ่มต้นนี้:
import com.aspose.slides.*;
import android.graphics.Color;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
// ตั้งค่าสีไฮไลท์สำหรับย่อหน้าทั้งหมด.
paragraph.getParagraphFormat().getDefaultPortionFormat().getHighlightColor().setColor(Color.LTGRAY);
presentation.save("gray_paragraph.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
ผลลัพธ์:

ตัวอย่างโค้ดด้านล่างแสดงวิธีตั้งค่าสีพื้นหลังสำหรับ ส่วนข้อความที่มีฟอนต์หนา:
import com.aspose.slides.*;
import android.graphics.Color;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
for (IPortion portion : paragraph.getPortions()) {
if (portion.getPortionFormat().getEffective().getFontBold()) {
// ตั้งค่าสีไฮไลท์สำหรับส่วนข้อความ.
portion.getPortionFormat().getHighlightColor().setColor(Color.LTGRAY);
}
}
presentation.save("gray_text_portions.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
ผลลัพธ์:

จัดแนวย่อหน้าข้อความ
ใช้ IParagraphFormat.setAlignment เพื่อตั้งค่าการจัดแนวย่อหน้าภายในกรอบข้อความ ค่าอาจเป็นการจัดกึ่งกลาง, จัดซ้าย, จัดขวา, ตรงขอบ, เป็นต้น
ตัวอย่างต่อไปนี้แสดงวิธีจัดแนวย่อหน้าให้ ศูนย์:
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
// ตั้งค่าการจัดแนวของย่อหน้าให้ศูนย์.
paragraph.getParagraphFormat().setAlignment(TextAlignment.Center);
presentation.save("aligned_paragraph.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
ผลลัพธ์:

จัดแนวฟอนต์ภายในบรรทัด
ใช้ IParagraphFormat.setFontAlignment เพื่อจัดแนวแนวตั้งของส่วนข้อความที่มีขนาดฟอนต์ต่างกันภายในบรรทัด การตั้งค่านี้ใช้กับย่อหน้าทั้งหมดและควบคุมการจัดแนวภายในแต่ละบรรทัดของย่อหน้า
ตัวอย่างต่อไปนี้สร้างกล่องข้อความที่มีป้ายกำกับสี่กล่องบนสไลด์เดียว แต่ละย่อหน้ามีข้อความเดียวกันที่ขนาด 18, 36, และ 54 พอยต์ พร้อมการจัดแนวฟอนต์ที่แตกต่างกัน ใช้ฟอนต์ Arial ปิดการทำ autofit และการห่อข้อความ และทำให้กรอบข้อความใหญ่พอที่จะบรรจุบรรทัดเดียว
import com.aspose.slides.*;
import android.graphics.Color;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
int[] alignments = { FontAlignment.Baseline, FontAlignment.Top, FontAlignment.Center, FontAlignment.Bottom };
String[] alignmentNames = { "Baseline", "Top", "Center", "Bottom" };
float[] fontSizes = { 18f, 36f, 54f };
for (int i = 0; i < alignments.length; i++) {
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 30, 20 + i * 130, 660, 120);
shape.getFillFormat().setFillType(FillType.NoFill);
shape.getLineFormat().getFillFormat().setFillType(FillType.NoFill);
ITextFrame textFrame = shape.getTextFrame();
textFrame.getTextFrameFormat().setAnchoringType(TextAnchorType.Top);
textFrame.getTextFrameFormat().setAutofitType(TextAutofitType.None);
textFrame.getTextFrameFormat().setWrapText(NullableBool.False);
IParagraph label = textFrame.getParagraphs().get_Item(0);
label.setText(alignmentNames[i]);
label.getParagraphFormat().setAlignment(TextAlignment.Left);
label.getParagraphFormat().getDefaultPortionFormat().setFontHeight(14);
label.getParagraphFormat().getDefaultPortionFormat().setLatinFont(new FontData("Arial"));
label.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid);
label.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.GRAY);
Paragraph paragraph = new Paragraph();
paragraph.getParagraphFormat().setFontAlignment(alignments[i]);
paragraph.getParagraphFormat().setAlignment(TextAlignment.Left);
paragraph.getParagraphFormat().getDefaultPortionFormat().setLatinFont(new FontData("Arial"));
paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid);
paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
for (float fontSize : fontSizes) {
Portion portion = new Portion("Ag ");
portion.getPortionFormat().setFontHeight(fontSize);
paragraph.getPortions().add(portion);
}
textFrame.getParagraphs().add(paragraph);
}
presentation.save("font_alignment.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
ผลลัพธ์:

การจัดแนวฟอนต์ใช้เมตริกของฟอนต์ ดังนั้นขอบของตัวอักษรแต่ละตัวอาจไม่ตรงกันอย่างสมบูรณ์ ตัวอย่างรวมอักษรพิมพ์ใหญ่และตัวที่มีส่วนลงล่างเพื่อแสดงความแตกต่างระหว่างการจัดแนว Baseline และ Bottom การใช้ฟอนต์และการแทนที่ฟอนต์ ตัวอักษรที่ใช้ และความแตกต่างของขนาดฟอนต์ส่งผลต่อผลลัพธ์ ขนาดกรอบ, ระยะขอบ, ระยะห่างบรรทัด, การห่อข้อความ และการทำ autofit ก็ส่งผลต่อการจัดวางเช่นกัน; ควรใช้ฟอนต์และการตั้งค่าเดียวกันเมื่อเปรียบเทียบโหมดต่างๆ
การตั้งค่านี้แตกต่างจาก IParagraphFormat.setAlignment ซึ่งควบคุมการจัดแนวแนวนอนของย่อหน้า และ ITextFrameFormat.setAnchoringType ซึ่งกำหนดตำแหน่งของบล็อกข้อความในแนวตั้งภายในรูปร่าง การจัดรูปแบบซูเปอร์สคริปต์และซับสคริปต์โดยใช้ IBasePortionFormat.setEscapement จะเลื่อนส่วนข้อความแต่ละส่วนสัมพันธ์กับ Baseline แทนการตั้งค่าการจัดแนวฟอนต์สำหรับบรรทัดของย่อหน้า
ตั้งค่าความโปร่งใสของข้อความ
ความโปร่งใสของข้อความควบคุมผ่านส่วนประกอบ alpha ของสีที่กำหนดให้กับ IBasePortionFormat.getFillFormat. ในตัวอย่างด้านล่าง alpha = 50 เป็นค่าช่อง alpha ของ ARGB ตั้งแต่ 0–255 ไม่ใช่เปอร์เซ็นต์ความโปร่งใส
ตัวอย่างโค้ดด้านล่างแสดงวิธีใช้ความโปร่งใสกับ ทั้งหมดของย่อหน้า:
import com.aspose.slides.*;
import android.graphics.Color;
int alpha = 50;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
// ตั้งค่าสีเติมของข้อความให้เป็นสีโปร่งใส.
paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid);
paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.argb(alpha, 0, 0, 0));
presentation.save("transparent_paragraph.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
ผลลัพธ์:

ตัวอย่างต่อไปนี้แสดงวิธีใช้ความโปร่งใสกับ ส่วนข้อความที่มีฟอนต์หนา:
import com.aspose.slides.*;
import android.graphics.Color;
int alpha = 50;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
for (IPortion portion : paragraph.getPortions()) {
if (portion.getPortionFormat().getEffective().getFontBold()) {
// ตั้งค่าความโปร่งใสของส่วนข้อความ.
portion.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
portion.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.argb(alpha, 0, 0, 0));
}
}
presentation.save("transparent_text_portions.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
ผลลัพธ์:

ตั้งค่าการเว้นระยะอักขระสำหรับข้อความ
ใช้ IBasePortionFormat.setSpacing เพื่อขยายหรือบีบระยะห่างระหว่างอักขระในกล่องข้อความ ตัวอย่างเพิ่มระยะห่าง 3 พอยต์; ค่าเป็นลบจะบีบข้อความ
โค้ด Java ด้านล่างแสดงวิธีขยายการเว้นระยะอักขระใน ทั้งหมดของย่อหน้า:
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
// หมายเหตุ: ใช้ค่าติดลบเพื่อบีบอัดระยะห่างของอักขระ.
paragraph.getParagraphFormat().getDefaultPortionFormat().setSpacing(3); // ขยายระยะห่างอักขระ.
presentation.save("character_spacing_in_paragraph.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
ผลลัพธ์:

ตัวอย่างโค้ดต่อไปนี้แสดงวิธีขยายการเว้นระยะอักขระใน ส่วนข้อความที่มีฟอนต์หนา:
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
for (IPortion portion : paragraph.getPortions()) {
if (portion.getPortionFormat().getEffective().getFontBold()) {
// หมายเหตุ: ใช้ค่าติดลบเพื่อบีบอัดระยะห่างของอักขระ.
portion.getPortionFormat().setSpacing(3); // ขยายระยะห่างอักขระ.
}
}
presentation.save("character_spacing_in_text_portions.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
ผลลัพธ์:

ปิดการใช้งาน Kerning สำหรับฟอนต์ที่ระบุ
ในบางกรณี ข้อความที่แสดงโดย Aspose.Slides อาจดูแคบกว่าข้อความเดียวกันที่แสดงใน PowerPoint นั่นอาจเกิดจาก PowerPoint เพิกเฉยต่อข้อมูล kerning ของฟอนต์บางตัว แม้ว่าฟอนต์จะมีข้อมูล kerning ที่ถูกต้องและเปิดใช้งาน kerning ในการตั้งค่าของ PowerPoint
เพื่อให้ผลลัพธ์ที่แสดงใกล้เคียงกับ PowerPoint มากขึ้น คุณสามารถปิดการใช้งาน kerning สำหรับส่วนข้อความที่ใช้ฟอนต์ที่มีผลกระทบได้ ตั้งค่า IBasePortionFormat.setKerningMinimalSize ให้มีค่ามากกว่าขนาดฟอนต์จริง ตัวอย่างนี้ต้องการไฟล์ “presentation.pptx” ที่มีกล่องข้อความเป็นรูปทรงแรกบนสไลด์แรก ตรวจสอบชื่อฟอนต์ที่มีผลรวมรวมถึงฟอนต์ที่สืบทอดมาและตั้งค่าเกณฑ์ 100 พอยต์สำหรับส่วนที่ใช้ Roboto การตั้งค่านี้จะปิด kerning สำหรับส่วนที่ใช้ฟอนต์ขนาดต่ำกว่า 100 พอยต์:
import com.aspose.slides.*;
Presentation presentation = new Presentation("presentation.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
String targetFont = "Roboto";
for (IParagraph paragraph : autoShape.getTextFrame().getParagraphs()) {
for (IPortion portion : paragraph.getPortions()) {
IPortionFormatEffectiveData portionFormat = portion.getPortionFormat().getEffective();
if ((portionFormat.getLatinFont() != null &&
portionFormat.getLatinFont().getFontName().equals(targetFont)) ||
(portionFormat.getEastAsianFont() != null &&
portionFormat.getEastAsianFont().getFontName().equals(targetFont)) ||
(portionFormat.getComplexScriptFont() != null &&
portionFormat.getComplexScriptFont().getFontName().equals(targetFont))) {
portion.getPortionFormat().setKerningMinimalSize(100);
}
}
}
presentation.save("output.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
สำหรับข้อความที่ตรงกับเกณฑ์นี้ การตั้งค่าจะปิดการทำ kerning และช่วยให้การแสดงผลของ Aspose.Slides ใกล้เคียงกับผลลัพธ์ภาพของ PowerPoint สำหรับฟอนต์ที่ได้รับผลกระทบจากพฤติกรรมเฉพาะของ PowerPoint นี้
จัดการคุณสมบัติฟอนต์ของข้อความ
คุณสมบัติฟอนต์สามารถกำหนดได้ระดับย่อหน้าโดยใช้ IParagraphFormat.getDefaultPortionFormat หรือบนส่วนข้อความแต่ละส่วนโดยใช้ IPortionFormat
ตัวอย่างต่อไปนี้ตั้งค่าฟอนต์เริ่มต้นของย่อหน้าแรกเป็น Times New Roman ขนาด 12 พอยต์ พร้อมการจัดรูปแบบหนา, เอน, และขีดเส้นใต้แบบจุดส่วนสีฟอนต์ส่วนข้อความที่กำหนดรูปแบบโดยตรงจะมีลำดับความสำคัญเหนือค่าเริ่มต้นเหล่านี้:
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
// ตั้งค่าคุณสมบัติฟอนต์สำหรับย่อหน้า.
paragraph.getParagraphFormat().getDefaultPortionFormat().setFontHeight(12);
paragraph.getParagraphFormat().getDefaultPortionFormat().setFontBold(NullableBool.True);
paragraph.getParagraphFormat().getDefaultPortionFormat().setFontItalic(NullableBool.True);
paragraph.getParagraphFormat().getDefaultPortionFormat().setFontUnderline(TextUnderlineType.Dotted);
paragraph.getParagraphFormat().getDefaultPortionFormat().setLatinFont(new FontData("Times New Roman"));
presentation.save("font_properties_for_paragraph.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
ผลลัพธ์:

ตัวอย่างต่อไปนี้ใช้ Times New Roman ขนาด 13 พอยต์, รูปแบบเอน, และขีดเส้นใต้แบบจุดกับส่วนข้อความที่มีการจัดรูปแบบที่เป็นหนา:
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
for (IPortion portion : paragraph.getPortions()) {
if (portion.getPortionFormat().getEffective().getFontBold()) {
// ตั้งค่าคุณสมบัติฟอนต์สำหรับส่วนข้อความ.
portion.getPortionFormat().setFontHeight(13);
portion.getPortionFormat().setFontItalic(NullableBool.True);
portion.getPortionFormat().setFontUnderline(TextUnderlineType.Dotted);
portion.getPortionFormat().setLatinFont(new FontData("Times New Roman"));
}
}
presentation.save("font_properties_for_text_portions.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
ผลลัพธ์:

ควบคุมการทำให้ความสูงข้อความเป็นปกติ
ใช้ IBasePortionFormat.setNormaliseHeight เมื่อทำสำเนาตัวอักษรตามแม่แบบหรือศึกษาความแตกต่างของความสูงอักขระ ใน PowerPoint การเปิดใช้งานการทำให้ความสูงเป็นปกติจะขยายหรือบีบอักขระแต่ละตัวในแนวตั้งให้มีความสูงที่มองเห็นได้สม่ำเสมอภายในส่วนข้อความนั้น ไม่ได้รับประกันว่าความสูงข้อความจะเท่ากันระหว่างฟอนต์ต่างๆ
ตั้งค่าเป็น NullableBool.True or False เพื่อเปิดหรือปิดการทำให้ความสูงเป็นปกติ NullableBool.NotDefined จะปล่อยให้การตั้งค่าท้องถิ่นไม่มีค่า เพื่อให้ส่วนข้อความสืบทอดค่าจาก getDefaultPortionFormat ของย่อหน้า ไม่ได้หมายถึง False. ใช้ IPortionFormat.getEffective และอ่าน IBasePortionFormatEffectiveData.getNormaliseHeight เพื่อรับค่าบูลีนที่ได้สรุปแล้ว
ตัวอย่างต่อไปนี้ต้องมีการติดตั้ง Arial สร้างสองบล็อกข้อความที่มีอักษรพิมพ์ใหญ่, ตัวพิมพ์เล็ก, ตัวลงล่าง, และอักขระมีสำเนียงเดียวกันที่ขนาด 54 พอยต์ ทั้งสองย่อหน้าเปิดการทำให้ความสูงเป็นปกติเป็นค่าเริ่มต้น ส่วนบนปิดการทำให้ความสูงเป็นปกติอย่างชัดเจน; ส่วนล่างสืบทอดการตั้งค่า ด้ามกรอบ, ระยะขอบ, และการเว้นระยะย่อหน้ามีค่าเดียวกัน โดยปิดการห่อและการทำ autofit เพื่อให้การเปรียบเทียบสอดคล้อง ตัวอย่างพิมพ์ False: false และ NotDefined: true แล้วบันทึกเป็น “text_height_normalization.pptx”.
import com.aspose.slides.*;
import android.graphics.Color;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
byte[] settings = { NullableBool.False, NullableBool.NotDefined };
String[] settingNames = { "False", "NotDefined" };
for (int i = 0; i < settings.length; i++) {
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 30, 60 + i * 200, 660, 150);
shape.getFillFormat().setFillType(FillType.NoFill);
shape.getLineFormat().getFillFormat().setFillType(FillType.NoFill);
ITextFrame textFrame = shape.getTextFrame();
textFrame.setText("Hxgjpq ÅÉ 0123");
textFrame.getTextFrameFormat().setAutofitType(TextAutofitType.None);
textFrame.getTextFrameFormat().setWrapText(NullableBool.False);
textFrame.getTextFrameFormat().setAnchoringType(TextAnchorType.Top);
textFrame.getTextFrameFormat().setMarginTop(0);
textFrame.getTextFrameFormat().setMarginLeft(0);
IParagraph paragraph = textFrame.getParagraphs().get_Item(0);
paragraph.getParagraphFormat().setAlignment(TextAlignment.Left);
paragraph.getParagraphFormat().setSpaceBefore(0);
paragraph.getParagraphFormat().setSpaceAfter(0);
paragraph.getParagraphFormat().setSpaceWithin(100);
paragraph.getParagraphFormat().getDefaultPortionFormat().setNormaliseHeight(NullableBool.True);
IPortion portion = paragraph.getPortions().get_Item(0);
FontData font = new FontData("Arial");
portion.getPortionFormat().setLatinFont(font);
portion.getPortionFormat().setFontHeight(54);
portion.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
portion.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
portion.getPortionFormat().setNormaliseHeight(settings[i]);
System.out.println(settingNames[i] + ": " + portion.getPortionFormat().getEffective().getNormaliseHeight());
}
presentation.save("text_height_normalization.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
การเปรียบเทียบด้านล่างส่งออกจากไฟล์งานที่บันทึกไว้ แถวบนปิดการทำให้ความสูงเป็นปกติ (False) แถวล่างสืบทอดการเปิดใช้งาน (NotDefined → True). ควรติดตั้ง Arial เพื่อให้ได้ลักษณะนี้

การทำให้ความสูงเป็นปกติเปลี่ยนความสูงของอักขระโดยไม่เปลี่ยนค่า getFontHeight ที่ระบุขนาดฟอนต์ในหน่วยพอยต์ ย่อหน้า setSpaceWithin ควบคุมระยะห่างบรรทัด ส่วน setAutofitType ของกรอบข้อความควบคุมว่าข้อความหรือคอนเทนเนอร์ปรับขนาดอย่างไร การตั้งค่าเหล่านี้มีจุดประสงค์ต่างกันและอาจส่งผลต่อการจัดวางโดยรวมอย่างอิสระ เพื่อเรียนรู้เพิ่มเติมเกี่ยวกับการจัดรูปแบบย่อหน้าและการสืบทอด ดูที่ จัดการย่อหน้า.
ใช้และลบเส้นขีดฆ่า
ใช้ IBasePortionFormat.setStrikethroughType บนส่วนข้อความเพื่อแสดงการแก้ไข, คำที่ถูกยกเลิก, หรือราคาก่อนหน้าโดยไม่ลบข้อความต้นฉบับ ตั้งค่าเป็น TextStrikethroughType.Single or Double เพื่อให้มีเส้นขีดฆ่าเดียวหรือสองเส้นผ่านข้อความ
เพื่อเอาเส้นขีดฆ่าออก ให้ใช้ TextStrikethroughType.None ซึ่งจะปิดผลกระทบโดยตรง แม้ว่าการจัดรูปแบบโดยรอบอาจกำหนดเส้นขีดฆ่า แต่ TextStrikethroughType.NotDefined จะปล่อยให้การตั้งค่าท้องถิ่นเป็นค่าไม่กำหนด เพื่อให้ส่วนข้อความสืบทอดการจัดรูปแบบ เช่น จากย่อหน้า ไม่ได้รับประกันว่าจะลบเส้นขีดฆ่าออก ใช้ IPortionFormat.getEffective เพื่ออ่านการจัดรูปแบบที่ได้รวมถึงค่าที่สืบทอด
ตัวอย่างต่อไปนี้สร้างการเปรียบเทียบราคาสามรายการ แต่ละย่อหน้ามีส่วนข้อความแยกสำหรับป้ายกำกับ, ราคาก่อนหน้า, และราคาปัจจุบัน ดังนั้นจึงมีผลต่อราคาก่อนหน้าเท่านั้น แถวแรกทำการเพิ่มและลบเส้นขีดฆ่า; แถวอื่น ๆ คงเส้นขีดฆ่าเดี่ยวและสองเส้น การเปลี่ยนการตั้งค่านี้ช่วยรักษาข้อความและการจัดรูปแบบอื่น ๆ รวมถึงการทำให้ราคาก่อนหน้าหนาเด่น
import com.aspose.slides.*;
import android.graphics.Color;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 50, 50, 620, 220);
shape.getFillFormat().setFillType(FillType.NoFill);
shape.getLineFormat().getFillFormat().setFillType(FillType.NoFill);
shape.getTextFrame().getParagraphs().clear();
String[] labels = { "None: ", "Single: ", "Double: " };
for (String label : labels) {
Paragraph paragraph = new Paragraph();
paragraph.getParagraphFormat().setAlignment(TextAlignment.Left);
paragraph.getParagraphFormat().setSpaceAfter(20);
IPortionFormat format = paragraph.getParagraphFormat().getDefaultPortionFormat();
format.setFontHeight(28);
FontData font = new FontData("Arial");
format.setLatinFont(font);
format.getFillFormat().setFillType(FillType.Solid);
format.getFillFormat().getSolidFillColor().setColor(Color.BLACK);
Portion labelPortion = new Portion(label);
paragraph.getPortions().add(labelPortion);
Portion previousPrice = new Portion("$100");
previousPrice.getPortionFormat().setFontBold(NullableBool.True);
paragraph.getPortions().add(previousPrice);
Portion currentPrice = new Portion(" → $80");
paragraph.getPortions().add(currentPrice);
shape.getTextFrame().getParagraphs().add(paragraph);
}
IParagraphCollection paragraphs = shape.getTextFrame().getParagraphs();
// ใช้การขีดฆ่าแล้วลบออกอย่างชัดเจนจากราคาก่อนหน้าตัวแรก.
paragraphs.get_Item(0).getPortions().get_Item(1).getPortionFormat().setStrikethroughType(TextStrikethroughType.Single);
paragraphs.get_Item(0).getPortions().get_Item(1).getPortionFormat().setStrikethroughType(TextStrikethroughType.None);
paragraphs.get_Item(1).getPortions().get_Item(1).getPortionFormat().setStrikethroughType(TextStrikethroughType.Single);
paragraphs.get_Item(2).getPortions().get_Item(1).getPortionFormat().setStrikethroughType(TextStrikethroughType.Double);
presentation.save("strikethrough.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
ผลลัพธ์จากบนลงล่าง: ไม่มีเส้นขีดฆ่า, เส้นขีดฆ่าเดียว, และเส้นขีดฆ่าสองเส้น

ตั้งค่าการหมุนข้อความ
ใช้ ITextFrameFormat.setTextVerticalType เพื่อตั้งค่าการวางแนวข้อความที่กำหนดล่วงหน้าในรูปทรง
ตัวอย่างต่อไปนี้ตั้งค่าการวางแนวข้อความในรูปทรงเป็น TextVerticalType.Vertical270, ซึ่งจะหมุนข้อความ 90 องศาทวนเข็มนาฬิกา:
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
autoShape.getTextFrame().getTextFrameFormat().setTextVerticalType(TextVerticalType.Vertical270);
presentation.save("text_rotation.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
ผลลัพธ์:

ตั้งค่าการหมุนแบบกำหนดเองสำหรับกรอบข้อความ
ใช้ ITextFrameFormat.setRotationAngle เพื่อตั้งค่ามุมการหมุนแบบกำหนดเองสำหรับ ITextFrame
ตัวอย่างโค้ดด้านล่างหมุนกรอบข้อความ 3 องศาตามเข็มนาฬิกา ภายในรูปทรง:
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
autoShape.getTextFrame().getTextFrameFormat().setRotationAngle(3);
presentation.save("custom_text_rotation.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
ผลลัพธ์:

ตั้งค่าการเว้นบรรทัดของย่อหน้า
Aspose.Slides มี IParagraphFormat.setSpaceAfter, IParagraphFormat.setSpaceBefore, และ IParagraphFormat.setSpaceWithin เพื่อควบคุมระยะห่างของย่อหน้า คุณสมบัติเหล่านี้ใช้ดังนี้:
- ใช้ค่าบวกเพื่อระบุระยะบรรทัดเป็นเปอร์เซ็นต์ของความสูงบรรทัด
- ใช้ค่าลบเพื่อระบุระยะบรรทัดเป็นพอยต์
ตัวอย่างต่อไปนี้ตั้งค่าการเว้นบรรทัดภายในย่อหน้าแรกเป็น 200% ของความสูงบรรทัด (การเว้นบรรทัดสองเท่า):
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
paragraph.getParagraphFormat().setSpaceWithin(200);
presentation.save("line_spacing.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
ผลลัพธ์:

ควบคุมการแบ่งบรรทัด
กฎการแบ่งบรรทัดของย่อมีประโยชน์ในบล็อกข้อความแคบและงานนำเสนอที่ผสมผสานข้อความละตินและเอเชียตะวันออก ตัวเลือกต่อไปนี้เป็นสมาชิกของ IParagraphFormat, ดังนั้นใช้ได้กับย่อหน้าทั้งหมด:
- setLatinLineBreak ควบคุมกฎการแบ่งบรรทัดของละติน ในข้อความผสม การเปลี่ยนอาจทำให้ตำแหน่งการห่อของข้อความเอเชียตะวันออกและเครื่องหมายวรรคตอนที่อยู่ติดกันเปลี่ยนไป
- setEastAsianLineBreak ควบคุมกฎการแบ่งบรรทัดของเอเชียตะวันออก รวมถึงข้อจำกัดเรื่องอักขระที่อยู่ต้นหรือปลายบรรทัด
กฎเหล่านี้ไม่ทดแทน ITextFrameFormat.setWrapText ซึ่งเปิดใช้งานการห่ออัตโนมัติภายในกรอบข้อความ แต่มีผลต่อการจัดวางเมื่อมีการห่อ ไม่ได้ใส่อักขระการขึ้นบรรทัดใหม่ การขึ้นบรรทัดอย่างชัดเจนบังคับให้สร้างบรรทัดใหม่ภายในย่อหน้าโดยไม่คำนึงถึงความกว้างที่มีอยู่
ตัวอย่างต่อไปนี้สร้างบล็อกข้อความแคบที่มีข้อความจีนและละติน ตั้งค่าตัวเลือกการแบ่งบรรทัดทั้งสองอย่างชัดเจนและบันทึกเป็น “line_breaking.pptx”. เพื่อทดลองกับกฎใดกฎหนึ่ง ให้เปลี่ยนค่าที่เกี่ยวข้องในขณะที่คงค่าที่เหลือคงเดิม ตัวอย่างใช้ Arial ขนาด 24 พอยต์และ SimSun พร้อมความกว้างกรอบ 160 พอยต์และระยะขอบกรอบข้อความศูนย์ตามแนวนอน ITextFrameFormat.setAutofitType ถูกเรียกด้วย TextAutofitType.None เพื่อให้ขนาดข้อความและมิติกรอบคงที่
import com.aspose.slides.*;
import android.graphics.Color;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 50, 50, 160, 300);
shape.getFillFormat().setFillType(FillType.NoFill);
ITextFrame textFrame = shape.getTextFrame();
textFrame.getTextFrameFormat().setWrapText(NullableBool.True);
textFrame.getTextFrameFormat().setAutofitType(TextAutofitType.None);
textFrame.getTextFrameFormat().setMarginLeft(0);
textFrame.getTextFrameFormat().setMarginRight(0);
IParagraph paragraph = textFrame.getParagraphs().get_Item(0);
paragraph.setText("中文排版测试,PowerPoint 中文演示。");
IParagraphFormat format = paragraph.getParagraphFormat();
format.setAlignment(TextAlignment.Left);
format.getDefaultPortionFormat().setFontHeight(24);
FontData latinFont = new FontData("Arial");
format.getDefaultPortionFormat().setLatinFont(latinFont);
FontData eastAsianFont = new FontData("SimSun");
format.getDefaultPortionFormat().setEastAsianFont(eastAsianFont);
format.getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid);
format.getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
format.setLatinLineBreak(NullableBool.False);
format.setEastAsianLineBreak(NullableBool.True);
presentation.save("line_breaking.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
ควบคุมเครื่องหมายวรรคตอนที่ลอย
IParagraphFormat.setHangingPunctuation อนุญาตให้เครื่องหมายวรรคตอนที่มีคุณสมบัติตรงตามเงื่อนไขขยายออกไปเหนือขอบขวาของบรรทัดข้อความแทนที่จะอยู่บนบรรทัดถัดไป ใช้กับย่อหน้าทั้งหมดและต่างจากการเยื้องบรรทัด
ตัวอย่างต่อไปนี้เปิดใช้เครื่องหมายวรรคตอนที่ลอยในกรอบข้อความกว้าง 100 พอยต์และบันทึกเป็น “hanging_punctuation.pptx”. ด้วย Arial ขนาด 24 พอยต์และระยะขอบกรอบศูนย์ เครื่องหมายจุดสุดท้ายจะอยู่หลัง “sentence” และขยายออกไปเหนือขอบขวาของข้อความ ตั้งค่าคุณสมบัติเป็น NullableBool.False เพื่อเปรียบเทียบ: ด้วยการตั้งค่านี้ จุดสุดท้ายจะอยู่บนบรรทัดแยกต่างหาก การห่อเปิดใช้งานและการทำ autofit ปิดเพื่อคงความกว้างที่ใช้ได้คงที่
import com.aspose.slides.*;
import android.graphics.Color;
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 50, 50, 100, 200);
shape.getFillFormat().setFillType(FillType.NoFill);
ITextFrame textFrame = shape.getTextFrame();
textFrame.getTextFrameFormat().setWrapText(NullableBool.True);
textFrame.getTextFrameFormat().setAutofitType(TextAutofitType.None);
textFrame.getTextFrameFormat().setMarginLeft(0);
textFrame.getTextFrameFormat().setMarginRight(0);
IParagraph paragraph = textFrame.getParagraphs().get_Item(0);
paragraph.setText("Simple text, next sentence.");
IParagraphFormat format = paragraph.getParagraphFormat();
format.setAlignment(TextAlignment.Left);
format.getDefaultPortionFormat().setFontHeight(24);
FontData latinFont = new FontData("Arial");
format.getDefaultPortionFormat().setLatinFont(latinFont);
format.getDefaultPortionFormat().getFillFormat().setFillType(FillType.Solid);
format.getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
format.setHangingPunctuation(NullableBool.True);
presentation.save("hanging_punctuation.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
ไม่ใช่เครื่องหมายวรรคตอนทุกตัวที่สามารถลอยได้ เงื่อนไขของฟอนต์และการจัดวางที่อธิบายไว้ข้างบน (ควบคุมการแบ่งบรรทัด) ยังใช้กับการเปรียบเทียบนี้: การเปลี่ยนฟอนต์, ความกว้างที่ใช้ได้, ระยะขอบ, หรือการตั้งค่า autofit อาจทำให้ความแตกต่างที่มองเห็นได้หายไป
ตั้งค่าชนิด Autofit สำหรับกรอบข้อความ
ITextFrameFormat.setAutofitType กำหนดวิธีที่ข้อความทำงานเมื่อเกินขอบเขตของคอนเทนเนอร์ ใช้เพื่อควบคุมว่าข้อความจะย่อ, ล้น, หรือปรับขนาดรูปร่างอัตโนมัติ ตัวอย่างต่อไปนี้กำหนดให้รูปร่างขยายเพื่อให้พอดีกับข้อความและบันทึกผลลัพธ์เป็น “autofit_type.pptx”.
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
autoShape.getTextFrame().getTextFrameFormat().setAutofitType(TextAutofitType.Shape);
presentation.save("autofit_type.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
เพื่อให้นับบรรทัดหลังการห่ออัตโนมัติและดูว่าความกว้างของข้อความหรือรูปร่างเปลี่ยนผลลัพธ์อย่างไร ดูที่ Count Rendered Lines. จำนวนบรรทัดเพียงอย่างเดียวไม่บ่งบอกว่าข้อความล้นคอนเทนเนอร์หรือไม่
ตั้งค่าจุดยึดของกรอบข้อความ
ITextFrameFormat.setAnchoringType กำหนดวิธีที่ข้อความถูกวางในแนวตั้งภายในรูปร่าง ตัวอย่างต่อไปนี้ยึดข้อความไว้ที่ด้านล่างของรูปทรงแรกและบันทึกผลลัพธ์เป็น “text_anchor.pptx”.
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
autoShape.getTextFrame().getTextFrameFormat().setAnchoringType(TextAnchorType.Bottom);
presentation.save("text_anchor.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
ตั้งค่าตารางแท็บของข้อความ
ใช้ IParagraphFormat.setDefaultTabSize และ IParagraphFormat.getTabs เพื่อกำหนดจุดหยุดแท็บในย่อหน้า ตัวอย่างต่อไปนี้ตั้งค่าช่วงแท็บเริ่มต้นเป็น 100 พอยต์และเพิ่มจุดหยุดแท็บแบบจัดซ้ายที่ 30 พอยต์ การตั้งค่าเหล่านี้มีผลกับข้อความที่มีอักขระแท็บ
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
paragraph.getParagraphFormat().setDefaultTabSize(100);
paragraph.getParagraphFormat().getTabs().add(30, TabAlignment.Left);
presentation.save("paragraph_tabs.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
ผลลัพธ์:

ตั้งค่าภาษา Proofing
Aspose.Slides มี IBasePortionFormat.setLanguageId ซึ่งอนุญาตให้คุณตั้งค่าภาษา proofing สำหรับส่วนข้อความ ภาษา proofing กำหนดภาษาที่ใช้สำหรับการตรวจสอบการสะกดและไวยากรณ์ใน PowerPoint
ตัวอย่างต่อไปนี้ต้องการ “presentation.pptx” ที่มีกล่องข้อความเป็นรูปทรงแรกบนสไลด์แรกและอย่างน้อยหนึ่งย่อหน้า แทนที่เนื้อหาของย่อหน้าแรกด้วย “1。”, ตั้งค่า SimSun เป็นฟอนต์ของมันและกำหนดภาษาการ proofing เป็นภาษาจีนตัวย่อ (zh-CN). บันทึกผลลัพธ์เป็น “proofing_language.pptx”:
import com.aspose.slides.*;
Presentation presentation = new Presentation("presentation.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IParagraph paragraph = autoShape.getTextFrame().getParagraphs().get_Item(0);
paragraph.getPortions().clear();
FontData font = new FontData("SimSun");
Portion textPortion = new Portion();
textPortion.getPortionFormat().setComplexScriptFont(font);
textPortion.getPortionFormat().setEastAsianFont(font);
textPortion.getPortionFormat().setLatinFont(font);
// ตั้งค่า Id ของภาษาตรวจสอบการพิมพ์.
textPortion.getPortionFormat().setLanguageId("zh-CN");
textPortion.setText("1。");
paragraph.getPortions().add(textPortion);
presentation.save("proofing_language.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
ตั้งค่าภาษาเริ่มต้น
ใช้ LoadOptions.setDefaultTextLanguage เพื่อกำหนดภาษาข้อความเริ่มต้นสำหรับข้อความที่สร้างขณะโหลดหรือสร้างงานนำเสนอ ตัวอย่างต่อไปนี้สร้างงานนำเสนอโดยตั้งค่าภาษาอังกฤษสหรัฐเป็นภาษาเริ่มต้นของข้อความ, เพิ่มกล่องข้อความ, และพิมพ์ en-US สำหรับส่วนข้อความแรกของมัน:
import com.aspose.slides.*;
LoadOptions loadOptions = new LoadOptions();
loadOptions.setDefaultTextLanguage("en-US");
Presentation presentation = new Presentation(loadOptions);
try {
ISlide slide = presentation.getSlides().get_Item(0);
// เพิ่มรูปสี่เหลี่ยมใหม่พร้อมข้อความ.
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 20, 20, 150, 50);
shape.getTextFrame().setText("Sample text");
// ตรวจสอบภาษาของส่วนข้อความแรก.
IPortion portion = shape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0);
System.out.println(portion.getPortionFormat().getLanguageId());
} finally {
presentation.dispose();
}
ตั้งค่าสไตล์ข้อความเริ่มต้น
เพื่อใช้การจัดรูปแบบข้อความเริ่มต้นในระดับงานนำเสนอ ใช้ IPresentation.getDefaultTextStyle
ตัวอย่างต่อไปนี้ตั้งค่าฟอนต์หนาขนาด 14 พอยต์เป็นค่าเริ่มต้นสำหรับย่อหน้าในระดับบนของงานนำเสนอใหม่และบันทึกเป็น “default_text_style.pptx”. ข้อความสามารถสืบทอดค่าเริ่มต้นเหล่านี้ได้เว้นแต่การจัดรูปแบบที่เจาะจงมากกว่าจะครอบคลุม
import com.aspose.slides.*;
Presentation presentation = new Presentation();
try {
// รับรูปแบบย่อหน้าระดับบนสุด.
IParagraphFormat paragraphFormat = presentation.getDefaultTextStyle().getLevel(0);
if (paragraphFormat != null) {
paragraphFormat.getDefaultPortionFormat().setFontHeight(14);
paragraphFormat.getDefaultPortionFormat().setFontBold(NullableBool.True);
}
presentation.save("default_text_style.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
ดึงข้อความที่มีเอฟเฟกต์ All-Caps
ใน PowerPoint การใช้เอฟเฟกต์ All Caps ทำให้ข้อความปรากฏเป็นตัวพิมพ์ใหญ่บนสไลด์แม้ว่าจะพิมพ์เป็นตัวพิมพ์เล็กก็ตาม เมื่อคุณเรียกข้อความส่วนนี้จาก Aspose.Slides ไลบรารีจะคืนข้อความตามที่พิมพ์ไว้ เพื่อตรงกับข้อความที่แสดง ให้ตรวจสอบ TextCapType และแปลงสตริงที่คืนค่ามาเป็นตัวพิมพ์ใหญ่อย่างเดียวเมื่อค่าคือ All
ตัวอย่างต้องใช้ “sample2.pptx” ที่มีกล่องข้อความเป็นรูปทรงแรกบนสไลด์แรก ย่อหน้าแรกของมันมีส่วนข้อความแรกเป็น “Hello, Aspose!” พร้อมเอฟเฟกต์ All Caps ดังแสดงด้านล่าง

ตัวอย่างโค้ดด้านล่างแสดงวิธีดึงข้อความที่มีเอฟเฟกต์ All Caps ออกมา:
import com.aspose.slides.*;
Presentation presentation = new Presentation("sample2.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape autoShape = (IAutoShape)slide.getShapes().get_Item(0);
IPortion textPortion = autoShape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0);
System.out.println("Original text: " + textPortion.getText());
IPortionFormatEffectiveData textFormat = textPortion.getPortionFormat().getEffective();
if (textFormat.getTextCapType() == TextCapType.All) {
String text = textPortion.getText().toUpperCase();
System.out.println("All-Caps effect: " + text);
}
} finally {
presentation.dispose();
}
ผลลัพธ์:
Original text: Hello, Aspose!
All-Caps effect: HELLO, ASPOSE!
คำถามที่พบบ่อย
ฉันจะแก้ไขข้อความในตารางบนสไลด์ได้อย่างไร?
เพื่อแก้ไขข้อความในตารางบนสไลด์ ใช้ ITable. ทำการวนลูปผ่านเซลล์และอัปเดตแต่ละเซลล์ผ่าน ICell.getTextFrame และการจัดรูปแบบย่อหน้าผ่าน IParagraph.getParagraphFormat.
ฉันจะใช้สีไล่ระดับให้กับข้อความบนสไลด์ PowerPoint ได้อย่างไร?
เพื่อใช้สีไล่ระดับให้กับข้อความ ใช้ IBasePortionFormat.getFillFormat. ตั้งค่า IFillFormat.setFillType เป็น FillType.Gradient แล้วกำหนดจุดไล่ระดับ, ทิศทาง, และความโปร่งใส.