/**
* 打印数据
* @return
*/
public void PrintExcel(WritableSheet sheet,WritableWorkbook wwb,String fileName,String cityName){
try {
// 获得开始时间
long start = System.currentTimeMillis();
// 写入数据
wwb.write();
// 关闭文件
wwb.close();
getResponse().reset();
getResponse().setContentType("application/x-msdownload;charset=GBK"); //设置响应类型为下载
getResponse().setCharacterEncoding("UTF-8");
//SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
String docName=java.net.URLEncoder.encode(cityName+".xls","UTF-8");
getResponse().setHeader("Content-Disposition", "attachment; filename=" +new String(docName.getBytes("UTF-8"),"GBK"));
BufferedInputStream br = new BufferedInputStream(new FileInputStream(fileName));
byte[] buf = new byte[1024];
int len = 0;
OutputStream out = getResponse().getOutputStream();
while((len = br.read(buf)) >0)
out.write(buf,0,len);
out.close();
br.close();
long end = System.currentTimeMillis();
System.out.println("----完成该操作共用的时间是:"+(end-start)/1000);
} catch (Exception e) {
System.out.println("---出现异常---");
e.printStackTrace();
}
}
/**
* 得到数据表头格式
* @return
*/
public WritableCellFormat getTitleCellFormat(){
WritableCellFormat wcf = null;
try {
//字体样式
WritableFont wf = new WritableFont(WritableFont.TIMES,12, WritableFont.NO_BOLD,false);//最后一个为是否italic
wf.setColour(Colour.RED);
wcf = new WritableCellFormat(wf);
//对齐方式
wcf.setAlignment(Alignment.CENTRE);
wcf.setVerticalAlignment(VerticalAlignment.CENTRE);
//边框
wcf.setBorder(Border.ALL,BorderLineStyle.THIN);
//背景色
wcf.setBackground(Colour.GREY_25_PERCENT);
} catch (WriteException e) {
e.printStackTrace();
}
return wcf;
}
* 打印数据
* @return
*/
public void PrintExcel(WritableSheet sheet,WritableWorkbook wwb,String fileName,String cityName){
try {
// 获得开始时间
long start = System.currentTimeMillis();
// 写入数据
wwb.write();
// 关闭文件
wwb.close();
getResponse().reset();
getResponse().setContentType("application/x-msdownload;charset=GBK"); //设置响应类型为下载
getResponse().setCharacterEncoding("UTF-8");
//SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
String docName=java.net.URLEncoder.encode(cityName+".xls","UTF-8");
getResponse().setHeader("Content-Disposition", "attachment; filename=" +new String(docName.getBytes("UTF-8"),"GBK"));
BufferedInputStream br = new BufferedInputStream(new FileInputStream(fileName));
byte[] buf = new byte[1024];
int len = 0;
OutputStream out = getResponse().getOutputStream();
while((len = br.read(buf)) >0)
out.write(buf,0,len);
out.close();
br.close();
long end = System.currentTimeMillis();
System.out.println("----完成该操作共用的时间是:"+(end-start)/1000);
} catch (Exception e) {
System.out.println("---出现异常---");
e.printStackTrace();
}
}
/**
* 得到数据表头格式
* @return
*/
public WritableCellFormat getTitleCellFormat(){
WritableCellFormat wcf = null;
try {
//字体样式
WritableFont wf = new WritableFont(WritableFont.TIMES,12, WritableFont.NO_BOLD,false);//最后一个为是否italic
wf.setColour(Colour.RED);
wcf = new WritableCellFormat(wf);
//对齐方式
wcf.setAlignment(Alignment.CENTRE);
wcf.setVerticalAlignment(VerticalAlignment.CENTRE);
//边框
wcf.setBorder(Border.ALL,BorderLineStyle.THIN);
//背景色
wcf.setBackground(Colour.GREY_25_PERCENT);
} catch (WriteException e) {
e.printStackTrace();
}
return wcf;
}