Easypoi-based Word and Excel template operations

Source: Internet
Author: User

Preface: In the project needs to use the contract template and so on Word template operation, through the Check Network data blog, discovers Easypoi is a good third party storehouse, and has carried on the use in the project, the special edition.

1, first, into the Easypoi Official Guide Blog for document reading, reference links: http://easypoi.mydoc.io/

2, Gradle import maven version warehouse:

Compile ' org.jeecg:easypoi-base:2.1.3 '
compile ' org.jeecg:easypoi-web:2.1.3 '
compile ' ORG.JEECG: easypoi-annotation:2.1.3 '

3, coding implementation:

Jsp:<a href= "mapexportwordtest.do" class= "btn btn-primary Btn-quirk" ><i class= "fa Fa-check" ></i> Export Word </a>

4, Controller Code implementation: (Demo)

/** * Export Word Test * @param request * @param response * @param modelmap * @return * * @Reques Tmapping (value = "mapexportwordtest") public String Simplewordexport (httpservletrequest request, HttpServletResponse R Esponse, Modelmap modelmap) {String FilePath = Request.getsession (). Getservletcontext (). Getrealpat
        H ("/export/" + "Simpleexcel.docx");
        map<string, object> map = new hashmap<string, object> ();
        Map.put ("department", "Easypoi");
        Map.put ("Person", "Jueyue");
        Map.put ("Time", Format.format (New Date ());
        list<person> list = new arraylist<person> ();
        Person p = new person ();
        P.setname ("Xiaoming");
        P.settel ("18711111111");
        P.setemail ("18711111111@139.com");
        List.add (P);
        p = new person ();
        P.setname ("Little Red");
        P.settel ("18711111112");
        P.setemail ("18711111112@139.com");
        List.add (P); Map.put ("plist", New Excellistentity (list, person.class));
        Modelmap.put (Templatewordconstants.file_name, "word test");
        Modelmap.put (TEMPLATEWORDCONSTANTS.MAP_DATA,MAP);
        Modelmap.put (Templatewordconstants.url,filepath);
    return templatewordconstants.jeecg_template_word_view; }

5, Project application: (from the database to check the associated data inserted into Word {demandname} identity data)

/** * Download Contract * * @param contractid * @param request * @param response * @param modelmap * @return */@RequestMapping (value = "downloadcontract") public String downloadcontract (@RequestParam ("Contrac  TId ") int contractid, httpservletrequest request, HttpServletResponse response, HttpSession session, Modelmap
        Modelmap) {Contract Contract = Contractservice.getcontractdetailbyid (Contractid);
        Templet Templet = Contract.gettemplet (); String dir = uploadtempletdir + templet.gettemplettype (). Name () + "/" + templet.gettempletname () + "/" + Contract.getversi

        Onno ();
        String Realfilepath = Request.getsession (). Getservletcontext (). Getrealpath (dir); arraylist<templetlogvo> Filetempletlogvos = Scandirutils.getfiletempletlogvos (RealFilePath,

        Templet.gettemplettype (), Templet.gettempletname ()); if (Collectionutils.isempty (Filetempletlogvos)) {String url = ' Demand/viewfinisheddeMand.do?demandid "+contract.getdemand (). Getdemandid (); Return "Redirect: ...
        /common/failure.do?msg=error_download_failure&&url= "+url;
        } Demand Demand = Contract.getdemand (); If you have won the bid, check the winning record//if (demand.getdemandstate () = demandstate.bidded| | Demand.getdemandstate () = = Demandstate.edit_contract) {//query winning record Bid Bid = Bidservice.getwinbiddingbydema
        Ndid (Demand.getdemandid ());
Modelmap.addattribute ("bid", bid);
        Company Company = Demand.getcompany ();


        String datestr = Format.format (Contract.getcreatetime ());
        String Downfilepath = realfilepath+ "/" +filetempletlogvos.get (0). GetFileName ();
        map<string, object> map = new hashmap<string, object> ();
        Map.put ("CompanyName", Company.getcompanyname ());
        Map.put ("Designername", Bid.getcustomer (). Getcustomername ());

        Map.put ("Createtime", datestr); Modelmap.put (templatewordconstants.file_name, Contract.getcontractname ());
        Modelmap.put (Templatewordconstants.map_data, MAP);
        Modelmap.put (Templatewordconstants.url, Downfilepath);
    return templatewordconstants.jeecg_template_word_view; }
6: Finished.




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.