Jxls build Excel and download

Source: Internet
Author: User
Jxl.jar jxls-core-0.9. 9. Jar jxls-reader-0.9. 9. Jar Poi-3.5-final.jar (must be more than 3.5 version) other jars are prompted to go to http://jarvana.com/jarvana/Find//Generate Excel Incoming template file The content generation file to generate returns the build file The full path
public static string Doexcel (string from, Map beans, string to) {
ServletContext sc = (ServletContext) actioncontext.g Etcontext (). Get (
servletactioncontext.servlet_context);
String Path = Sc.getrealpath ("/model");
Xlstransformer transformer = new Xlstransformer ();
String sfrom = path + "\ \" + from;//template file
String sto = path + "\" + to;//file to be generated
try {
transformer.transformx LS (Sfrom, beans, sto);
} catch (Parsepropertyexception e) {
//TODO auto-generated catch block
e.printstacktrace ();
} catch ( IOException e) {
//TODO auto-generated catch block
e.printstacktrace ();
}
return sto;
}

Download public static void Dodownload (string path, string name, httpservletresponse response) {try {response.reset (); RESP
Onse.setheader ("Content-disposition", "attachment;success=true;filename =" + Urlencoder.encode (name, "Utf-8"));
Bufferedinputstream bis = null;
Bufferedoutputstream BOS = NULL;
OutputStream fos = null;
InputStream FIS = null;
File UploadFile = new file (path);
FIS = new FileInputStream (uploadfile);
bis = new Bufferedinputstream (FIS);
FOS = Response.getoutputstream ();
BOS = new Bufferedoutputstream (FOS);
Pop-up download dialog box int bytesread = 0;
byte[] buffer = new byte[8192];
while ((bytesread = bis.read (buffer, 0, 8192))!=-1) {bos.write (buffer, 0, bytesread);} bos.flush ();
Fis.close ();
Bis.close ();
Fos.close ();
Bos.close ();
catch (Exception e) {e.printstacktrace ();}}
Call: List resultlist=new ArrayList ();
for (int i = 0; i < list.size (); i++) {...
Inspectionstisfaction vo=new inspectionstisfaction (); Vo.setxjrq (Systemutil.gettimestr2str (string.valueof map.get ("appLy_date ")));
Vo.setxjsl (LXJSL);
Vo.setfcmy (LFCMY);
Vo.setmy (Lmy);
Vo.setyb (LYB);
Vo.setbmy (lbmy);
Vo.setfcbmy (lfcbmy);
Resultlist.add (VO);
}//Generate Excel Map beans = new HashMap ();
Beans.put ("Resultlist", resultlist);
String Path=systemutil.doexcel ("Patrol Merchant Satisfaction Report template. xls", beans, "Patrol merchant satisfaction report. xls");
Systemutil.dodownload (Path, "Patrol merchant satisfaction report. xls", this.response); return null;

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.