本文将介绍如何使用spire.presentation for java在powerpoint文档中查找和高亮指定文本。
import com.spire.presentation.fileformat;
import com.spire.presentation.iautoshape;
import com.spire.presentation.presentation;
import com.spire.presentation.texthighlightingoptions;
import java.awt.*;
public class searchandhighlighttext {
public static void main(string[] args) throws exception {
//创建presentation实例
presentation presentation = new presentation();
//加载powerpoint文档
presentation.loadfromfile("input.pptx");
//获取第一张幻灯片上的第一个形状
iautoshape shape = (iautoshape)presentation.getslides().get(0).getshapes().get(0);
//设置高亮选项
texthighlightingoptions options = new texthighlightingoptions();
options.setwholewordsonly(true);
options.setcasesensitive(true);
//使用hightlighttext方法高亮指定文本
shape.gettextframe().highlighttext("spire", color.yellow, options);
//保存结果文档
presentation.savetofile("highlightspecifiedtext.pptx", fileformat.pptx_2013);
}
}
结果文档: