本文介绍如何使用Spire.Presneatation for Java将简单的HTML字符串添加到幻灯片。
import com.spire.presentation.FileFormat;
import com.spire.presentation.IAutoShape;
import com.spire.presentation.Presentation;
import com.spire.presentation.ShapeType;
import com.spire.presentation.drawing.FillFormatType;
import java.awt.geom.Rectangle2D;
public class InsertHTML {
public static void main(String[] args) throws Exception {
//创建Presentation对象
Presentation ppt = new Presentation();
//添加图形到第一个幻灯片
IAutoShape shape = ppt.getSlides().get(0).getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle2D.Float(50, 50, 400, 100));
shape.getFill().setFillType(FillFormatType.NONE);
//清除图形中默认的段落
shape.getTextFrame().getParagraphs().clear();
//定义HTML字符串
String htmlString = "<ul>" +
"<li style=\"color:blue\">Spire.Presentation for Java</li>" +
"<li style=\"color:green\">Spire.PDF for Java</li>" +
"<li style=\"color:gray\">Spire.Doc for Java</li>" +
"<li style=\"color:red\">Spire.Barcode for Java</li>" +
"</ul>";
//添加HTML字符串到段落
shape.getTextFrame().getParagraphs().addFromHtml(htmlString);
//保存文档
ppt.saveToFile("InsertHtml.pptx", FileFormat.PPTX_2013);
}
}