jexcel导出 excel表 如何添加导出时间实例介绍。想早导出的EXCEL表中 加上 导出时间。 不知道该如何 写入呢。
datatime() 不是很熟悉 请各位看看了 谢谢!
public void createEXL(IRequestCycle cycle) throws IOException, WriteException{
String spath = getServletContext().getRealPath(“/excel/”) + “/”;
String newfilename = new Date().getTime() + “.xls”;
String fileFullName = spath + newfilename;
// 创建excel文件夹
File dirPath = new File(spath);
if (!dirPath.exists()) {
dirPath.mkdirs();
}
List result = this.getPlanList();
WritableWorkbook wwb = Workbook.createWorkbook(new File(fileFullName));
WritableSheet sheet = wwb.createSheet(“接待来访计划信息表”, 0);// 组织excel文件的内容
sheet.setRowView(0,900);
sheet.setColumnView(0,6);//设置0列宽
sheet.setColumnView(1,15);//组团单位
sheet.setColumnView(2,25);//团组名称
sheet.setColumnView(3,13);//团组类别
sheet.setColumnView(4,15);//月份
sheet.setColumnView(5,6);//天数
sheet.setColumnView(6,6);//人数
sheet.setColumnView(7,6);//经费来源
sheet.setColumnView(8,10);//国家
sheet.setColumnView(9,10);//费用
sheet.setColumnView(10,15);//备注
sheet.setColumnView(11,15);
sheet.setColumnView(12,15);
sheet.setColumnView(13,13);
sheet.setColumnView(14,13);
sheet.setColumnView(15,13);
sheet.mergeCells(0,0,14,0); // 合并单元格,0行0-10列
jxl.write.Label label = null;
int excelCol = 0;
int row = 1;
try {
VsitReception pl=new VsitReception();
Iterator fiter=pl.getVsitReceptionNames().iterator();
WritableFont font1=new WritableFont(WritableFont.createFont(“仿宋_GB2312″),16,WritableFont.BOLD);
WritableCellFormat format1=new WritableCellFormat(font1);
format1.setAlignment(jxl.format.Alignment.CENTRE);
format1.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
format1.setWrap(true);
label = new jxl.write.Label(0,0, “接待来访计划明细表”,format1);
sheet.addCell(label);
while(fiter.hasNext()){
label = new jxl.write.Label(excelCol++, row, fiter.next().toString(),format1);
sheet.addCell(label);
}
font1=new WritableFont(WritableFont.createFont(“仿宋_GB2312″),12,WritableFont.BOLD);//WritableFont(WritableFont.createFont(“楷体_GB2312″)
format1=new WritableCellFormat(font1);
format1.setAlignment(jxl.format.Alignment.CENTRE);
format1.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
format1.setWrap(true);
format1.setBorder(Border.ALL,BorderLineStyle.THIN); //加入边框
int t=0;
for(int i=0;i<result.size();i++){
//////System.out.println(“result.size()”+result.size());
excelCol = 0;
VsitReception rr = (VsitReception) result.get(i);
rr.getVsitReception();
List iter=rr.getVsitReception();
for(int j=0;j<iter.size();j++){
row = i + 2;
Object obj=iter.get(j);
if(obj!=null&&obj!=”"){
if(excelCol==0){
try{
font1=new WritableFont(WritableFont.createFont(“仿宋_GB2312″),12,WritableFont.BOLD);
format1=new WritableCellFormat(font1);
format1.setAlignment(jxl.format.Alignment.CENTRE);
format1.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
format1.setWrap(true);
format1.setBorder(Border.ALL,BorderLineStyle.THIN); //加入边框
label = new jxl.write.Label(excelCol++, row,Integer.toString(row-1),format1);
}catch(Exception ex){
}
sheet.addCell(label);
}
// WritableFont font2=new WritableFont(WritableFont.createFont(“楷体_GB2312″),11,WritableFont.BOLD);//WritableFont(WritableFont.createFont(“楷体_GB2312″)
format1=new WritableCellFormat();
format1.setAlignment(jxl.format.Alignment.LEFT);
// if(excelCol==5||excelCol==6||excelCol==9){
// format1.setAlignment(jxl.format.Alignment.RIGHT);
// }
format1.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
format1.setWrap(true);
format1.setBorder(Border.ALL,BorderLineStyle.THIN); //加入边框
label = new jxl.write.Label(excelCol++, row,obj.toString(),format1);
sheet.addCell(label);
//////System.out.println(“j3=”+j);
}else{
label = new jxl.write.Label(excelCol++, row,”");
sheet.addCell(label);
}
}
t=row ;
}
font1=new WritableFont(WritableFont.createFont(“仿宋_GB2312″),14,WritableFont.BOLD);//WritableFont(WritableFont.createFont(“楷体_GB2312″)
format1=new WritableCellFormat(font1);
format1.setAlignment(jxl.format.Alignment.LEFT);
label = new jxl.write.Label(0, t+1,”共计”+this.getTzsum()+”个团组,天数”+this.getZwts()+”天,我部总人数”+this.getWbrs()+”,总费用”+this.getFy()+”元”,format1);
sheet.addCell(label);
} catch (Exception e) {
e.printStackTrace();
} finally{
// 生成excel文件
wwb.write();
wwb.close();
}
OutputStream os=null;
BufferedInputStream br=null;
try {
HttpServletResponse response = getResponse();
os= response.getOutputStream();
File f = new File(fileFullName);
System.out.println(f.getName());
br = new BufferedInputStream(
new FileInputStream(f));
byte buf[] = new byte[1024*500];
int len = 0;
response.setContentType(“application/x-msdownload”);
response.setHeader(“Content-Disposition”, (new StringBuilder())
.append(“attachment;filename=\”").append(
new String(“接待来访”.getBytes(“gb2312″), “iso8859-1″)
+ “.xls”).append(“\”").toString());
while ((len = br.read(buf)) > 0) {
os.write(buf, 0, len);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
os.close();
br.close();
os = null;
br=null;
}