
已解决问题
谷歌aa957098qy用户在2013.06.24提交了关于“于朦胧j**a如何另存导出Excel”的提问,欢迎大家涌跃发表自己的观点。目前共有1个回答,最后更新于2024-12-13T12:01:00。希望大家能够帮助她。详细问题描述及疑问:期待您的答案,你就是当代的活雷锋,太感谢了 !
详细问题描述及疑问:期待您的答案,你就是当代的活雷锋,太感谢了 !
1./**
*出
*@parammap
*@paramform
*@paramrequest
*@paramresponse
*@throwsIOE
*/
publicvoidexportActoExcel(
h**ttpServletRequestrequest,h**ttpServletResponseresponse)throwsIOException{
A
AcExcelBus
AccidentRec
AccidentRecordBusiarBusi=newAccidentRec
////
FwUserssessUser=(FwUsers)request.ge
Map<String,Object>cisMap=arBusi.getTod
ListAcList=**ll;//党的记录
if(**ll!=cisMap
AcList=(List)cisMap.get("list");
//导出excel的路径、文
Stringuuid=U
Stringpath=reque
response
}
2./
*导出出险信息fc
*
*@paramjzForm
*查询条件
*@paramsessionUser
*当
*@paramerrors
*Action错误
*@return
*/
publi
try{
Writ
W
//内容(居中)单元格样式
WritableCellFormatcontentStyle
contentStyle.setAli
contentSt
jxl.format.BorderLineStyle.Th**IN);//设置边框
//一级标题单元格样式
WritableFontwf1=newWritableFont(WritableFont.ARIAL,15,
WritableFont.BOLD,false);//定义格式字体下划线斜体粗体颜色
WritableCellFormattitleStyle1=newWritableCellFormat(wf1);//
titleStyle1.setBackground(jxl.***.GREEN);//设置单元格的背景颜色
titleStyle1.setAlignment(jxl.format.Alignment.CENTRE);//设置对齐方式
titleStyle1.setBorder(jxl.format.Border.ALL,
jxl.format.BorderLineStyle.Th**IN);//设置边框
//二级标题单元格样式
WritableFontwf2=newWritableFont(WritableFont.ARIAL,11,
WritableFont.BOLD,false);//定义格式字体下划线斜体粗体颜色
WritableCellFormattitleStyle2=newWritableCellFormat(wf2);//
titleStyle2.setBackground(jxl.format.Colour.GREY_25_PERCENT);//设置单元格的背景颜色
titleStyle2.setAlignment(jxl.format.Alignment.CENTRE);//设置水平对齐方式
titleStyle2
.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);//设置垂直对齐方式
titleStyle2.setBorder(jxl.format.Border.ALL,
jxl.format.BorderLineStyle.Th**IN);//设置边框
WritableCellFormattitleStyle3=newWritableCellFormat(wf1);//
titleStyle3.setBackground(jxl.format.Colour.BRIGh**T_GREEN);//设置单元格的背景颜色
titleStyle3.setAlignment(jxl.format.Alignment.CENTRE);//设置对齐方式
titleStyle3.setBorder(jxl.format.Border.ALL,
jxl.format.BorderLineStyle.Th**IN);//设置边框
//设置冻结单元格
sheet.getSettings().setVerticalFreeze(2);
sheet.getSettings().seth**orizontalFreeze(5);
sheet.setColumnView(0,8);//设置列的宽度
sheet.setColumnView(1,10);//设置列的宽度
sheet.setRowView(0,0);
sheet.addCell(newLabel(0,0,"hysj5800294*#",titleStyle1));//标题
sheet.addCell(newLabel(0,1,"出险信息",titleStyle2));//标题
sheet.mergeCells(0,2,33,2);//合并单元格
sheet.addCell(newLabel(0,2,"出险信息",titleStyle1));//标题
sheet.addCell(newLabel(0,3,"序号",titleStyle2));//往单元格中填写**
sheet.addCell(newLabel(1,3,"省内/省外",titleStyle2));//往单元格中填写**
if(list!=**ll&&list.size()>0){
for(inti=0;i<list.size();i++){
sheet.setRowView(i+3,300);//设置行高
//转换**信息
//Object[]obj=(Object[])list.get(i);
AccidentRecordar=(AccidentRecord)list.get(i);
sheet.addCell(newLabel(0,i+4,String.valueOf(i+1),contentStyle));//往单元格中填写**序号
sheet.addCell(newLabel(1,i+4,ar.getLicenceProvince().toString(),contentStyle));//省内/省外
}
}
workbook.write();//书写到工作簿
workbook.close();//关闭工作簿,输出完成
}catch(Exceptione){
e.printStackTrace();
}
}
}
3.功能可以实现,可以到处,点击下载确定。
4.打开已经下载的excel,如图显示结果。得到想要的结构。