Upload--//1 Save data to Excel, corresponding sheet header header,body data type LIST//2 upload file to server//download--//1 Get file path//2 Export data to persisted path (or browser path)/** * Save data to Excel * @param listbody * @param sheetname */public void Saveexceldata (list<doclibbrowseorgvo> listbody, Strin G sheetname) {Xssfworkbook wb = new Xssfworkbook (); Xssfsheet sheet = wb.createsheet (sheetname); Xssfrow row = Sheet.createrow (0), Row.createcell (0). Setcellvalue (""); Row.createcell (1). Setcellvalue (""); Row.createcell (2). Setcellvalue (""); int i = 0;for (Doclibbrowseorgvo doc:listbody) {i++;row = Sheet.createrow (i); Row.createcell (0). Setcellvalue (Doc.getdoclibid ()), Row.createcell (1). Setcellvalue (Doc.getdoclibname ()); Row.createcell (2). Setcellvalue (Doc.getcount ()); Row.createcell (4). Setcellvalue (Doc.getstatisticdate ());}} /** * Upload file to server specified path * * @param destpath * @param fileName */public void UploadFile (String destpath, String fileName, Xssfwo Rkbook WB) throws IOException {file Pathfile = new File (destpath); if (!pathfile.exists ()) {pathfile.mkdirs ();} File destfile = new File (DestPath + fileName); Bufferedoutputstream buffer = new Bufferedoutputstream (new FileOutputStream (DestFile)); wb.write (buffer); Buffer.close ();} /** * Download * * @param srcpath * @param fileName */public void DownLoadFile (String srcpath, String fileName, Httpservletreque St request, httpservletresponse Response) {File File = new file (Srcpath + fileName), if (File.exists ()) {Response.setconten Ttype ("Application/force-download");//Setting mandatory download does not open Setfiledownloadheader (request, response, fileName); Address Chinese name byte[] buffer = new byte[1024]; FileInputStream FIS = null; Bufferedinputstream bis = Null;outputstream os = null;try {fis = new FileInputStream (file); bis = new Bufferedinputstream (f is); OS = Response.getoutputstream ();//to browser download path int i;while ((i=bis.read (buffer))! =-1) {os.write (buffer, 0, i); i = Bis.read (buffer);}} catch (Exception e) {e.printstacktrace ();} finally {if (bis! = null) {try {bis.close ();} catch (IOException e) {E.printsta Cktrace ();}} if (FIS! = null) {try {fis.close ();} catch (IoexceptiOn e) {e.printstacktrace ();}}}} /** * Resolve Chinese name * @param request * @param response * @param fileName */public void Setfiledownloadheader (HttpServletRequest r Equest, httpservletresponse response, string filename) {try {//Chinese file name supports String encodedfilename; String Agent = Request.getheader ("user-agent"); if (null! = Agent && agent.contains ("MSIE")) {// Ieencodedfilename = Java.net.URLEncoder.encode (FileName, "UTF-8");} else if (null! = Agent && agent.contains ("Mozilla")) {encodedfilename = new String (filename.getbytes ("UTF-8"), "I So-8859-1 ");} else {encodedfilename = Java.net.URLEncoder.encode (FileName, "UTF-8");} Response.setheader ("Content-disposition", "attachment; Filename=\ "" + encodedfilename + "\" ");} catch (Unsupportedencodingexception e) {e.printstacktrace ();}}
Chinese name issue during file upload and download