翻譯|使用教程|編輯:張瑩心|2021-11-24 09:29:01.363|閱讀 287 次
概述:當我們在演示文稿中添加商標、版權或其他符號時,我們可能希望該符號稍微高于或低于某個文本。在 Microsoft PowerPoint 中,我們可以簡單地通過對符號應用上標或下標格式來實現這種效果。在本文中,我們將演示如何使用Spire.Presentation for Java以編程方式在 Java 中實現此任務。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Spire.Presentation for Java 專業的 PowerPoint API,它允許開發人員在 Java 應用程序中創建、讀取、寫入、轉換和保存 PowerPoint 文檔,而無需安裝 Microsoft PowerPoint。
可點擊此處下載最新版測試。
當我們在演示文稿中添加商標、版權或其他符號時,我們可能希望該符號稍微高于或低于某個文本。在 Microsoft PowerPoint 中,我們可以簡單地通過對符號應用上標或下標格式來實現這種效果。在本文中,我們將演示如何使用Spire.Presentation for Java以編程方式在 Java 中實現此任務。
import com.spire.presentation.*; import com.spire.presentation.drawing.*; import java.awt.*; public class AddSuperscriptAndSubscript { public static void main(String []args) throws Exception { //Load a PowerPoint document Presentation presentation = new Presentation(); presentation.loadFromFile("template.pptx"); //Get the first slide ISlide slide = presentation.getSlides().get(0); //Add a shape to the slide IAutoShape shape = slide.getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle(150, 100, 200, 50)); shape.getFill().setFillType(FillFormatType.NONE); shape.getShapeStyle().getLineColor().setColor(Color.white); //Access the text frame of the shape ITextFrameProperties textFrame = shape.getTextFrame(); //Clear the default paragraph in the text frame textFrame.getParagraphs().clear(); //Create a paragraph with normal text ParagraphEx para = new ParagraphEx(); para.setText("E=mc"); //Create a portion with superscript text PortionEx tr = new PortionEx("2"); tr.getFormat().setScriptDistance(40); //Append the portion to the paragraph para.getTextRanges().append(tr); para.getTextRanges().append(new PortionEx("\n")); //Set text color, font and font size for the normal text tr = para.getTextRanges().get(0); tr.getFill().setFillType(FillFormatType.SOLID); tr.getFill().getSolidColor().setColor(new Color(128,0,128)); tr.setFontHeight(20); tr.setLatinFont(new TextFont("Arial")); //Set text color and font for the superscript text tr = para.getTextRanges().get(1); tr.getFill().setFillType(FillFormatType.SOLID); tr.getFill().getSolidColor().setColor(Color.BLUE); tr.setLatinFont(new TextFont("Arial")); //Append the paragraph to the text frame of the shape textFrame.getParagraphs().append(para); //Create another paragraph with normal text para = new ParagraphEx(); para.setText("X"); //Create a portion with subscript text tr = new PortionEx("100"); tr.getFormat().setScriptDistance(-25); //Append the portion to the paragraph para.getTextRanges().append(tr); //Set text color, font and font size for the normal text tr = para.getTextRanges().get(0); tr.getFill().setFillType(FillFormatType.SOLID); tr.getFill().getSolidColor().setColor(new Color(128,0,128)); tr.setFontHeight(20); tr.setLatinFont(new TextFont("Arial")); //Set text color and font for the subscript text tr = para.getTextRanges().get(1); tr.getFill().setFillType(FillFormatType.SOLID); tr.getFill().getSolidColor().setColor(Color.BLUE); tr.setLatinFont(new TextFont("Arial")); //Append the paragraph to the text frame of the shape textFrame.getParagraphs().append(para); //Save the result document presentation.saveToFile("AddSuperscriptAndSubscript.pptx", FileFormat.PPTX_2013); } }輸出:
慧都是E-iceblue官方友好合作伙伴,如果您對spire.Presentation感興趣,可以了解具體授權價格和使用機制。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn