j**a如何另存导出Excel

时间:2013.06.24 发布人:aa957098qy

j**a如何另存导出Excel

已解决问题

谷歌aa957098qy用户在2013.06.24提交了关于“于朦胧j**a如何另存导出Excel”的提问,欢迎大家涌跃发表自己的观点。目前共有1个回答,最后更新于2024-12-13T12:01:00。希望大家能够帮助她。

详细问题描述及疑问:期待您的答案,你就是当代的活雷锋,太感谢了 !

希望以下的回答,能够帮助你。

第1个回答

用户名:eggcong  

1./**

*出险信息导出到excel(fc)

*@parammap问答ping

*@paramform

*@paramrequest

*@paramresponse

*@throwsIOE飞体居xception

*/

publicvoidexportActoExcel(ActionMappingmapping,ActionFormform,

h**ttpServletRequestrequest,h**ttpServletResponseresponse)throwsIOException{

ActionErrorserrors=newA买印后究针绝容区参印磁ctionErrors();

AcExcelBus史iacBusi=newAcExcelBusi定铁特司六关集();

AccidentRec免则块ordFormarForm=(拿师AccidentRecordForm)form;

AccidentRecordBusiarBusi=newAccidentRec段燃兵察就冷ordBusi();

//////查询条件

FwUserssessUser=(FwUsers)request.getSession().getAttribute(ConstValues.**SS_USER_MANAGE);

Map<String,Object>cisMap=arBusi.getTod伟际虽肉oPageList(arForm,sessUser,errors);

ListAcList=**ll;//党的记录

if(**ll!=cisMap){

AcList=(List)cisMap.get("list");

}


//导出excel的路径、文件名

Stringuuid=U混气UID.create("exp");

Stringpath=request.getSession().getServletContext().getRealPath("/")+ConstValues.EXP_PATh**_EXCEL+uuid+".xls";

积代货属acBusi.exprotAcExcel(AcList,path,request);


response次.sendRedirect("stdownload.jsp?path="+path);


}

2./受优绿袁述法草升啊**

*导出出险信息fc

*

*@paramjzForm

*查询条件

*@paramsessionUser

*当前登录session用户

*@paramerrors

*Action错误

*@return

*/

publicvoidexprotAcExcel成型杨步家弱(Listlist,Stringpath,h**ttpServletRequestrequest){


try{

Writ*长厚须扩从移ableWorkbookworkbook=Workbook.createWork坐己接乎建坚型省茶沉三book(newFile(path));//创建工作簿(filePos为excel文件的路径)

WritableSheetsheet生款位良孩的况评晶翻后=workbook.createSheet("出险信息",0);//创建工作


//内容(居中)单元格样式

WritableCellFormatcontentStyle把石它千盟门积课蛋相苦=newWritableCellFormat();//

contentStyle.setAlignment(jxl.format.Alignment.CENTRE);//设置对齐方式

contentSt概yle.setBorder(jxl.format.Border.ALL,

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,如图显示结果。得到想要的结构。