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;