Spire.Presentation for JAVA 提供两种方式插入HTML字符串到PowerPoint文档。
插入HTML格式的文本到presentation
import java.awt.Color;
import java.awt.Rectangle;
import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;
public class appendHTML {
    public static void main(String[] args) throws Exception {
        //实例化一个PPT对象
        Presentation ppt = new Presentation();
        //添加一个shape到第一张幻灯片
        IAutoShape shape = ppt.getSlides().get(0).getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle(50, 50, 320, 80));
        //清除默认段落
        shape.getTextFrame().getParagraphs().clear();
        //设置shape的样式
        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 \">Spire.Presentation for JAVA </h1><p style=\" color:darkGray ;font-size:15px \">专业的JAVA PowerPoint 组件涵盖创建 编辑 打印 转换等功能。</p></body></html>";
        shape.getTextFrame().getParagraphs().addFromHtml(code);
        //保存文档
        String outputFile = "output/result1.pptx";
        ppt.saveToFile(outputFile, FileFormat.PPTX_2010);
    }
}
如下方式也支持插入HTML(包含文本、图片、视频、音频等元素)到presentation。
import com.spire.presentation.*;
import com.spire.presentation.collections.ShapeList;
public class appendHTML {
    public static void main(String[] args) throws Exception {
        //实例化一个PPT对象
        Presentation ppt = new Presentation();
        //获取第一张幻灯片中的shapes
        ShapeList shapes = ppt.getSlides().get(0).getShapes();
        //插入HTML到shapes
        String code ="<html><body><p>Spire.Presentation for JAVA</p><img src='data/Logo.png'/></body></html>";
        shapes.addFromHtml(code);
        //保存文档
        String outputFile = "output/result2.pptx";
        ppt.saveToFile(outputFile,FileFormat.PPTX_2010);
    }
}
 



 
					



