Java operation ppt via COM interface

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.