Java list print Excel report

Source: Internet
Author: User
Tags dateformat

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

 

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.