我的代码:
public static void main(String[] args) throws IOException, Docx4JException, Pptx4jException, JAXBException
{
String inputfilepath = "C:\\Work\\SampleTemplate.pptx";
PresentationMLPackage pptPackage
= PresentationMLPackage.load(new File(inputfilepath));
ThemePart themeSlidePart = (ThemePart)
pptPackage.getParts().getParts().get(new PartName("/ppt/theme/theme1.xml"));
Theme themeOfSlides = (Theme)themeSlidePart.getJaxbElement();
SlidePart slide = pptPackage.getMainPresentationPart().getSlide(0);
HashMap h = new HashMap<String, String>();
h.put("SlideTitleName", "SARANYA");
slide.variableReplace(h);
String outputfilepath = "C:\\Work\\24Jan2018_CheckOut\\dhl\\PPT-TRAILS\\SampleTemplate.pptx";
PresentationMLPackage pptPackagetoApply
= PresentationMLPackage.load(new File(outputfilepath));
ThemePart themeSlidePartToApply
= (ThemePart) pptPackagetoApply.getParts().getParts()
.get(new PartName("/ppt/theme/theme1.xml"));
themeSlidePartToApply.setJaxbElement(themeOfSlides);
SaveToZipFile saver = new SaveToZipFile(pptPackagetoApply);
saver.save(outputfilepath);
}
但文字仍未被取代。我尝试了一个新的PPTX文件,其中只有文本“$ {SlideTitleName}”。但仍然无法正常工作。
发布于 2018-05-29 07:59:50
发布于 2018-05-29 09:18:14
以下代码取代了所有的字符串值,但在VariableReplace()中它只接受String。
1)有没有办法取代Integer的值
2)我想在本地下载文件,但我的下面的代码下载文件都在我的服务器路径和本地文件downaload发生但显示空ppt。
String outputfilepath = projectName +"_"+ reportId+".pptx";
PresentationMLPackage ppt = (PresentationMLPackage) OpcPackage
.load(inputfilepath);
if (save) {
SaveToZipFile saver = new SaveToZipFile(ppt);
saver.save(new FileOutputStream(outputfilepath));
response.setContentType("application/ppt");
response.setHeader("Content-Disposition", "attachment;filename="+ outputfilepath);
System.out.println("Saved");
}
请问为什么会报错?
https://stackoverflow.com/questions/-100004562
复制相似问题