Use poi to generate an Excel report

Source: Internet
Author: User

First, paste the Report Template

The following is the report generation class excelreport. Java written by poi.

Package COM. jadyer. report; import Java. io. filenotfoundexception; import Java. io. fileoutputstream; import Java. io. ioexception; import Java. io. outputstream; import Java. text. simpledateformat; import Java. util. date; import Java. util. hashmap; import Java. util. map; import Org. apache. poi. openxml4j. exceptions. invalidformatexception; import Org. apache. poi. SS. usermodel. cell; import Org. apache. poi. SS. usermodel. cellstyl E; import Org. apache. poi. SS. usermodel. row; import Org. apache. poi. SS. usermodel. sheet; import Org. apache. poi. SS. usermodel. workbook; import Org. apache. poi. SS. usermodel. workbookfactory; /*** use poi to generate an Excel report * @ see the report it generates is generated according to the Excel module File * @ see here to use poi-3.9-20121203.jar and poi-ooxml-3.9-20121203.jar * @ see another template file <<reporttemplate.xls> for http://download.csdn.net/detail/jadyer/5736263 * @ create Jul 5, 9:54:46 2013 Pm * @ author Xuan Yu 

Finally, the unit test class excelreporttest. Java (that is, to demonstrate the actual call steps)

Package COM. jadyer. report; import Java. io. file; import Org. JUnit. assert; import Org. JUnit. test; import COM. jadyer. report. excelreport; public class excelreporttest {@ testpublic void testexcelreportutil () {excelreport ERU = excelreport. instance; ERU. createnewrow (); ERU. buildcell ("AA"); ERU. buildcell ("Xuan Yu"); ERU. buildcell ("cc"); ERU. buildcell ("DD"); ERU. createnewrow (); ERU. buildcell ("AA"); ERU. buildcell ("http://blog.csdn.net/jadyer"); ERU. buildcell ("cc"); ERU. buildcell ("DD"); ERU. createnewrow (); ERU. buildcell ("AA"); ERU. buildcell ("active storage"); ERU. buildcell ("cc"); ERU. buildcell ("DD"); ERU. writetofile ("D:/test.xls"); assert. asserttrue (new file ("D:/test.xls "). exists ());}}

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.