java通过apache POI检索powerpoint文件(.PPTX)中超链接幻灯片的内容
我正在尝试获取powerpoint文件的文本内容并替换为其他文本。我有一个20张幻灯片的powerpoint文件。其中13、14、15、16张幻灯片与17、18、19和20张幻灯片具有超链接。我使用XMLSlideshow浏览幻灯片,但它只提供16张幻灯片。它不提供最后4张超链接幻灯片
有什么想法是可以提前知道的吗?我怎样才能得到所有超链接幻灯片的内容,并用其他文本替换
这是我的密码
公共静态void replaceContentInputPtx(文件inputFile,文件outputFile)引发IOException{
FileInputStream fis = null;
FileOutputStream fos = null;
XMLSlideShow ppt = null;
try{
fis = new FileInputStream(inputFile);
fos = new FileOutputStream(outputFile);
ppt = new XMLSlideShow(fis);
// System.out.println("Available slide layouts:"+ppt.getSlideMasters().length);
/* for(XSLFSlideMaster master : ppt.getSlideMasters()){
XSLFShape[] shape = master.getShapes();
for(XSLFSlideLayout layout : master.getSlideLayouts()){
System.out.println(layout.getType());
}
}*/
System.out.println("No of slides:"+ppt.getSlides().length); // gives 16 slides.
for(XSLFSlide slide : ppt.getSlides()) {
for(XSLFShape shape : slide){
if(shape instanceof XSLFTextShape) {
XSLFTextShape txShape = (XSLFTextShape)shape;
for (XSLFTextParagraph xslfParagraph : txShape.getTextParagraphs()) {
String originalText = replaceUnwantedChar(xslfParagraph.getText());
if(! originalText.isEmpty()) {
String translation = "";
if(translation != null ) {
CTRegularTextRun[] ctRegularTextRun = xslfParagraph.getXmlObject().getRArray();
for(int index = ctRegularTextRun.length-1; index > 0 ; index--){
xslfParagraph.getXmlObject().removeR(index);
}
ctRegularTextRun[0].setT(translation);
}
}
}
}
}
}
ppt.write(fos);
fos.close();
fis.close();
}catch(Exception ex){
ex.printStackTrace();
}
}
共 (0) 个答案