Java 提取PPT SmartArt图形中的文本
1、通过e-iceblue官网下载jar包,下载后,解压将lib文件夹下的jar文件导入Java程序,或者通过maven仓库下载导入。
1、import com.spire.presentation.*;
import com.spire.presentation.diagrams.ISmartArt;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
public class GetTextOfSmartArt {
public static void main(String[] args) throws Exception{
//创建实例,加载测试文档
Presentation presentation = new Presentation();
presentation.loadFromFile("AddSmartArt.pptx");
//新建txt文档,用于写入提取出来的文本
String result = "extractTextOfSmartArt.txt";
File file=new File(result);
if(file.exists()){
file.delete();
}
file.createNewFile();
FileWriter fw =new FileWriter(file,true);
BufferedWriter bw =new BufferedWriter(fw);
//遍历所有幻灯片并获取SmartArt图形.
for (int i = 0; i < presentation.getSlides().getCount(); i++)
{
for (int j = 0; j < presentation.getSlides().get(i).getShapes().getCount(); j++)
{
if (presentation.getSlides().get(i).getShapes().get(j) instanceof ISmartArt)
{
ISmartArt smartArt = (ISmartArt)presentation.getSlides().get(i).getShapes().get(j);
//提取SmartArt形状中的文本,写入txt
for (int k = 0; k < smartArt.getNodes().getCount(); k++)
{
bw.write(smartArt.getNodes().get(k).getTextFrame().getText() + "\r\n");
}
}
}
}
bw.flush();
bw.close();
fw.close();
}
}
2、文本提取结果:

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:90
阅读量:89
阅读量:178
阅读量:153
阅读量:152