I have learned how to print an Excel report using Java in the past two days. I would like to share this with you. It will be of great help to new users ~~
Jxl
Public class printelx {envinfmanageraction EMA = new envinfmanageraction (); // The printed list source is this class, including the parameter information such as temperature and humidity, illumination, public void prixls (string name, string pathn) {system. out. println ("test printing"); List <envinf> listprint = new arraylist <envinf> (); listprint. addall (EMA. getlist (); pathn = pathn + "// aa.xls"; // This is the path try {jxl. write. writableworkbook WWB = workbook. createworkbook (new file (pathn); jxl. write. writablesheet Ws = NULL; Ws = WWB. createsheet ("test sheet 1", 0); jxl. write. label id = new jxl. write. label (0, 0, "Number"); jxl. write. label time = new jxl. write. label (1, 0, "Time"); jxl. write. label temp = new jxl. write. label (2, 0, "temperature"); jxl. write. label light = new jxl. write. label (3, 0, "illumination"); jxl. write. label hum = new jxl. write. label (4,0, "humidity"); jxl. write. label CO2 = new jxl. write. label (5, 0, "CO2"); jxl. write. label grain = new jxl. write. label (6, 0, "dust"); jxl. write. label noise = new jxl. write. label (7,0, "noisy"); try {ws. addcell (ID); ws. addcell (time); ws. addcell (temp); ws. addcell (light); ws. addcell (HUM); ws. addcell (CO2); ws. addcell (grain); ws. addcell (Noise); For (Int J = 0; j <listprint. size (); j ++) {jxl. write. label Id2 = new jxl. write. label (0, J + 1, listprint. get (j ). GETID (); ws. addcell (Id2);} jxl. write. dateformat df = new jxl. write. dateformat ("yyyy/mm/dd hh: mm: SS"); For (Int J = 0; j <listprint. size (); j ++) {jxl. write. writablecellformat wcfdf = new jxl. write. writablecellformat (DF); jxl. write. datetime labeldtf = new jxl. write. datetime (1, J + 1, listprint. get (j ). gettime (), wcfdf); ws. addcell (labeldtf) ;}for (INT I = 0; I <listprint. size (); I ++) {jxl. write. number labeln = new jxl. write. number (2, I + 1, listprint. get (I ). gettemp (); ws. addcell (labeln) ;}for (INT I = 0; I <listprint. size (); I ++) {jxl. write. number labeln = new jxl. write. number (3, I + 1, listprint. get (I ). getlight (); ws. addcell (labeln) ;}for (INT I = 0; I <listprint. size (); I ++) {jxl. write. number labeln = new jxl. write. number (4, I + 1, listprint. get (I ). gethum (); ws. addcell (labeln) ;}for (INT I = 0; I <listprint. size (); I ++) {jxl. write. number labeln = new jxl. write. number (5, I + 1, listprint. get (I ). getco2 (); ws. addcell (labeln) ;}for (INT I = 0; I <listprint. size (); I ++) {jxl. write. number labeln = new jxl. write. number (6, I + 1, listprint. get (I ). getgrain (); ws. addcell (labeln) ;}for (INT I = 0; I <listprint. size (); I ++) {jxl. write. number labeln = new jxl. write. number (7, I + 1, listprint. get (I ). getnoise (); ws. addcell (labeln);} WWB. write (); WWB. close ();} catch (rowsexceededexception e) {// todo auto-generated Catch Block E. printstacktrace ();} catch (writeexception e) {// todo auto-generated Catch Block E. printstacktrace () ;}} catch (ioexception e) {// todo auto-generated Catch Block E. printstacktrace () ;}return ;}}