easyexcel实现web端下载excel

@RequestMapping( value = "/get",
                     method = { RequestMethod.GET } )
    public void getOrder( HttpServletRequest request, HttpServletResponse response ) {

        ServletOutputStream out = null;
        try {
            out = response.getOutputStream();
        } catch( IOException e ) {
            e.printStackTrace();
        }
        ExcelWriter writer = new ExcelWriter( out, ExcelTypeEnum.XLSX, true );
        String filename;
        String fileName = null;
        try {
            filename = new Date().toLocaleString();
            fileName = new String( ( filename ).getBytes(), "UTF-8" );
            Sheet sheet1 = new Sheet( 1, 0, WriteModel.class );
            sheet1.setSheetName( "第一个sheet" );
            writer.write( DataUtil.createTestListJavaMode(), sheet1 );
            response.setCharacterEncoding( "utf-8" );
            response.setContentType( "application/vnd.ms-excel" );
            response.setHeader( "content-Disposition",
                                "attachment;filename=" + URLEncoder.encode( fileName + ".xlsx", "utf-8" ) );
            out.flush();
        } catch( Exception e ) {
            e.printStackTrace();
        } finally {
            writer.finish();
            try {
                out.close();
            } catch( IOException e ) {
                e.printStackTrace();
            }
        }
    }

你可能感兴趣的:(学习,easyexcel)