1、Java封装导出类: package com.boonya.excel;import javax.servlet.http. HttpServletRequest;import javax.servlet.http. HttpServletResponse;.............................. ................import org.apache.commons.codec. binary.Base64;public class CExportTableManager { private String getDates(Date time) { Calendar cal = Calendar.getInstance(); cal.setTime(time); long tm; tm = cal.getTimeInMillis(); Date time1 = new Date(tm); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String tms = sdf.format(time1); return tms; } public void exportExcel(HttpServletRequest request, HttpServletResponse response, String title, String[] header, String[] name, List
2、 在servlet中设置header和name属性对应数组等属 性等 ExportTableManager ex=new ExportTableManager(); ex.exportExcel(request, response, title, header,name, list,time,username);
注意:setTitle方法的agent 判断部分是处理浏览器问题不兼容的{ 在chrome和opera下不能正常导出}。