欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Java實(shí)現(xiàn)將html字符串插入到PPT幻燈片

 更新時(shí)間:2021年11月26日 14:34:31   作者:E-iceblue  
Java后端代碼操作PPT幻燈片時(shí),可直接在幻燈片中繪制形狀,并在形狀中添加文本字符串內(nèi)容。本篇文章主要介紹通過java實(shí)現(xiàn)將html字符串添加到PPT幻燈片的的方法,可添加文字、圖片、視頻、音頻等。以下是具體方法和步驟。

通過Java后端代碼操作PPT幻燈片時(shí),可直接在幻燈片中繪制形狀,并在形狀中添加文本字符串內(nèi)容。本篇文章,介紹一種通過html字符串來添加內(nèi)容到PPT幻燈片的的方法,可添加文字、圖片、視頻、音頻等。下面是具體方法和步驟。

一、 環(huán)境配置

IntelliJ IDEA

Free Spire.Presentation for Java

關(guān)于如何導(dǎo)入jar:

1.Maven倉(cāng)庫(kù)下載導(dǎo)入。參考如下配置內(nèi)容:

<repositories>

        <repository>

            <id>com.e-iceblue</id>

            <url>https://repo.e-iceblue.cn/repository/maven-public/</url>

        </repository>

    </repositories>

<dependencies>

    <dependency>

        <groupId> e-iceblue </groupId>

        <artifactId>spire.presentation</artifactId>

        <version>3.9.0</version>

    </dependency>

</dependencies>

2.手動(dòng)從本地導(dǎo)入。下載Jar包到本地,解壓文件,找到lib文件夾下的jar文件。然后在IDEA中執(zhí)行如圖操作:

二、代碼示例

代碼步驟解析:

  • 實(shí)例化Presentation類的對(duì)象。
  • 通過Presentation.getSlides().get(int)方法獲取指定幻燈片。
  • 通過ISlide.getShapes().appendShape()添加形狀到幻燈片。
  • 通過html字符串定義需要在形狀中添加的內(nèi)容。
  • 通過IAutoShape.getTextFrame().getParagraphs().addFromHtml()方法將html字符串添加到幻燈片。
  • 最后通過Presentation.saveToFile()方法保存文檔。

Java

import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;

import java.awt.*;

public class AddHtmlCode {
    public static void main(String[] args)throws Exception {
        //實(shí)例化一個(gè)Presentation類的對(duì)象
        Presentation ppt = new Presentation();

        //獲取第一張幻燈片
        ISlide slide = ppt.getSlides().get(0);

        //添加一個(gè)shape幻燈片
        IAutoShape shape = slide.getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle(80, 50, 520, 180));
        shape.getTextFrame().getParagraphs().clear();
        shape.getFill().setFillType(FillFormatType.SOLID);
        shape.getFill().getSolidColor().setColor(Color.white);
        shape.getShapeStyle().getLineColor().setColor(Color.gray);

        //插入HTML到段落
        String code = "<html>"
                + "<body>"
                + "<h1 style=\" color:darkGray \"> Hyper Text Markup Language (HTML) </h1>"
                + "<p style=\" color:darkGray ;font-size:20px \">即超文本標(biāo)記語(yǔ)言。HTML是由Web的發(fā)明者 Tim Berners-Lee和同事 Daniel W. Connolly于1990年創(chuàng)立的一種標(biāo)記語(yǔ)言,它是標(biāo)準(zhǔn)通用化標(biāo)記語(yǔ)言SGML的應(yīng)用。用HTML編寫的超文本文檔稱為HTML文檔,它能獨(dú)立于各種操作系統(tǒng)平臺(tái)(如UNIX, Windows等)。</p>"
                + "</body>"
                + "</html>";
        shape.getTextFrame().getParagraphs().addFromHtml(code);

        //保存文檔
        String outputFile = "Result.pptx";
        ppt.saveToFile(outputFile, FileFormat.PPTX_2013);
    }
}

三、效果圖

到此這篇關(guān)于Java實(shí)現(xiàn)將html字符串插入到PPT幻燈片的文章就介紹到這了,更多相關(guān)Java 字符串內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論