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 ());}}