JAVA uses the COM interface to operate PPT

Source: Internet
Author: User

JAVA uses the COM interface to operate PPT
I. background description

In the Eclipse environment, you can develop a JAVA code operation PPT and modify the PPT template. Including modifying text labels, charts, and tables. To meet the requirements of most software to generate a PPT report, you must first create a template and modify the template data in the program.

2. Development Environment Construction

Download the open-source components of jacob, decompress the package, and add jacob. jar to the project. Copy the corresponding dll file to the Path. The 32-bit system uses X86 dll and the 64-bit system uses X64 dll.

Iii. Merge PPT function 1.1 merge PPT
/*** Merge multiple ppts. The output file and merged file must already exist. No new file is created. * @ Param outPutPPTPath: the output file path after merging. * @ Param mergePPTPathList: append the merged files in sequence. */Public synchronized static void merge (String outPutPPTPath, List
  
   
MergePPTPathList) {// start the office PowerPoint program ActiveXComponent pptApp = new ActiveXComponent ("PowerPoint. application "); Dispatch. put (pptApp, "Visible", new Variant (true); Dispatch presentations = pptApp. getProperty ("Presentations "). toDispatch (); // open the output file Dispatch outputPresentation = Dispatch. call (presentations, "Open", outPutPPTPath, false, false, true ). toDispatch (); // cyclically Add the merged file for (String mergeFile: mergePPTPathList) {Dispatch mergePresentation = Dispatch. call (presentations, "Open", mergeFile, false, false, true ). toDispatch (); Dispatch mergeSildes = Dispatch. get (mergePresentation, "Slides "). toDispatch (); int mergePageNum = Dispatch. get (mergeSildes, "Count "). toInt (); // close the Dispatch of the merged file. call (mergePresentation, "Close"); Dispatch outputSlides = Dispatch. call (outputPresentation, "Slides "). toDispatch (); int outputPageNum = Dispatch. get (outputSlides, "Count "). toInt (); // append the content of the file to be merged to the end of the output file. call (outputSlides, "InsertFromFile", mergeFile, outputPageNum, 1, mergePageNum);} // Save the output file and close and exit PowerPonit. dispatch. call (outputPresentation, "Save"); Dispatch. call (outputPresentation, "Close"); Dispatch. call (pptApp, "Quit ");}
  
1.2 call the test code
public static void main(String[] args) throws OpenXML4JException, IOException, XmlException     {               String outPutPPTPath = "D:\\TEMP\\template\\1.pptx";        List
  
    mergePPTPathList = new ArrayList
   
    ();        mergePPTPathList.add("D:\\TEMP\\template\\2.pptx");        mergePPTPathList.add("D:\\TEMP\\template\\3.pptx");        MergePPT.merge(outPutPPTPath, mergePPTPathList);;    }
   
  

Related Article

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.