@ Requestmapping ("/dealer/chargebook/exportv.htm ")
Public void getchargebooklist (INT epmkey, string bdakey, int year, int month, httpservletrequest request, httpservletresponse response ){
List <chargebook> List = chargebookservice. getepmchargebooklist (epmkey, year, month, bdakey );
String filename = year + "year" + month + "month" + list. Get (0). getcbkbdacaption () + "billing statistics. xls ";
Filename = encodefilename (filename, request); // sets the Excel name of the client during download.
Response. setheader ("content-disposition", "attachment; filename =" + filename );
Response. setcontenttype ("application/vnd. MS-excel ");
String Config = "/WEB-INF/chargebook/balance.xls ";
Excelutils. addvalue ("month", month );
Excelutils. addvalue ("year", year );
Excelutils. addvalue ("bdacaption", list. Get (0). getcbkbdacaption ());
For (chargebook: List ){
Chargebook. setcbkremark (rdstatus (chargebook. getcbkstatus ()));
}
Excelutils. addvalue ("list", list );
Excelutils. addvalue ("service", rdstatus (0 ));
Try {
Excelutils. Export (request. getsession (). getservletcontext (), config, response. getoutputstream ());
} Catch (excelexception e ){
E. printstacktrace ();
} Catch (ioexception e ){
E. printstacktrace ();
}
}
Public static string encodefilename (string filename, httpservletrequest request ){
/**
* Obtain client browser and operating system information
* In IE browser, the following information is obtained: User-Agent = Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; sv1; Maxthon; Alexa toolbar)
* In Firefox, User-Agent = Mozilla/5.0 (windows; U; Windows NT 5.1; ZH-CN; RV: 1.7.10) Gecko/20050717 Firefox/1.0.6
*/
String agent = request. getheader ("User-Agent ");
Try {
If (agent! = NULL) & (-1! = Agent. indexof ("MSIE "))){
String newfilename = urlencoder. encode (filename, "UTF-8 ");
Newfilename = stringutils. Replace (newfilename, "+", "% 20 ");
If (newfilename. Length ()> 150 ){
Newfilename = new string (filename. getbytes ("gb2312"), "ISO8859-1 ");
Newfilename = stringutils. Replace (newfilename, "", "% 20 ");
}
Return newfilename;
}
If (agent! = NULL) & (-1! = Agent. indexof ("Mozilla ")))
Return mimeutility. encodetext (filename, "UTF-8", "B ");
Return filename;
} Catch (exception ex ){
Return filename;
}
}
Excel value: # foreach CB in $ {list} # End