I. BACKGROUND notes
In the eclipse environment, the development of Java code operation PPT, support the modification of PPT template. This includes modifying text labels, charts, and tables. Meet the requirements of most software to generate PPT reports, that is, the first call to create a good template, modify the template data in the program.
Second, the development environment construction
Download the Jacob Open Source component, unzip and add the Jacob.jar to the project. Copy the corresponding DLL file to path. The 32-bit system uses the X86 DLL, and the 64-bit system uses the X64 DLL.
III. realization of merging PPT function 1.1 Merge ppt
/** * Merge multiple ppt files. Both the output file and the merge file are required to exist, and no new files are created. * @param outputpptpath The file path of the output after merging. * @param mergepptpathlist to append the merged files in turn. */ Public synchronized Static void Merge(String Outputpptpath, list<string> mergepptpathlist) {//Start Office PowerPoint programActivexcomponent Pptapp =NewActivexcomponent ("PowerPoint.Application"); Dispatch.put (Pptapp,"Visible",NewVariant (true)); Dispatch presentations = Pptapp.getproperty ("Presentations"). Todispatch ();//Open output fileDispatch outputpresentation = Dispatch.call (presentations,"Open", Outputpptpath,false,false,true). Todispatch ();//Loop add merge file for(String mergefile:mergepptpathlist) {Dispatch mergepresentation = Dispatch.call (presentations,"Open", Mergefile,false,false,true). Todispatch (); Dispatch mergesildes = Dispatch.get (Mergepresentation,"Slides"). Todispatch ();intMergepagenum = Dispatch.get (Mergesildes,"Count"). ToInt ();//Close merge filesDispatch.call (Mergepresentation,"Close"); Dispatch outputslides = Dispatch.call (Outputpresentation,"Slides"). Todispatch ();intOutputpagenum = Dispatch.get (Outputslides,"Count"). ToInt ();//Append the file contents to the end of the output fileDispatch.call (Outputslides,"InsertFromFile", Mergefile, Outputpagenum,1, Mergepagenum); }//Save output file, close exit Powerponit.Dispatch.call (Outputpresentation,"Save"); Dispatch.call (Outputpresentation,"Close"); Dispatch.call (Pptapp,"Quit"); }
1.2 Calling test code
publicstaticvoidmainthrows OpenXML4JException, IOException, XmlException { "D:\\TEMP\\template\\1.pptx"; new ArrayList<String>(); mergePPTPathList.add("D:\\TEMP\\template\\2.pptx"); mergePPTPathList.add("D:\\TEMP\\template\\3.pptx"); MergePPT.merge(outPutPPTPath, mergePPTPathList);; }
Java operation ppt via COM interface