一,通过POI接口,将从数据库中查出的信息以excel的形式存储
1.首先写一个Utils类
public class DownPOIUtils {
/**
*
* @param response:响应对象,类型是HttpServletResponse
* @param map:要封装的信息的map容器,其中key为Student,value为String类型的,在这里代表分数
* @throws Exception:代表异常对象
*/
public static void downPoi(HttpServletResponse response,
Map<Student, String> map) throws Exception {
String fname = "detial" + getTimeStamp();// Excel文件名
OutputStream os = response.getOutputStream();// 取得输出流
response.reset();// 清空输出流
response.setHeader("Content-disposition", "attachment; filename="
+ fname + ".xls"); // 设定输出文件头,该方法有两个参数,分别表示应答头的名字和值。
response.setContentType("application/msexcel");
try {
new DownPOIUtils().new POIS().createFixationSheet(os, map);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 该方法用来产生一个时间字符串