武汉北大青鸟鲁广校区java技术
packagecom.yinbo.satisfy.web.struts;
importjavax.servlet.ServletOutputStream;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
importorg.apache.struts.action.Action;
importorg.apache.struts.action.ActionForm;
importorg.apache.struts.action.ActionForward;
importorg.apache.struts.action.ActionMapping;
//importcom.lowagie.text.List;
importjava.util.List;
importcom.yinbo.satisfy.service.satisfy.SatisfyManage;
importcom.yinbo.satisfy.service.sysmanage.BranchManage;
importcom.yinbo.satisfy.service.sysmanage.ParamManage;
importcom.yinbo.satisfy.util.CommonUtils;
importcom.yinbo.satisfy.vo.Branch;
importcom.yinbo.satisfy.vo.Suggestion;
importcom.yinbo.satisfy.vo.SysParam;
importjava.io.*;
importjxl.Workbook;
importjxl.write.Label;
importjxl.write.WritableSheet;
importjxl.write.WritableWorkbook;
importjxl.write.WriteException;
publicclassQuestionActionextendsAction{
privateSatisfyManagesatisfyManage;
privateBranchManagebranchManage;
privateParamManageparamManage;
/**
*Methodexecute
*@parammapping
*@paramform
*@paramrequest
*@paramresponse
*@returnActionForward
*/
publicActionForwardexecute(ActionMappingmapping,ActionFormform,
HttpServletRequestrequest,HttpServletResponseresponse){
StringexcelFileName="c:\\testaaa.xls";
//////////////////////
StringbranchId=request.getParameter("branchId");
Stringlevel=request.getParameter("level");
Listlist=satisfyManage.getQuestionData(branchId,level);
Stringresult[][]=newString[list.size()][5];
for(inti=0;i<list.size();i++){
Suggestionsug=(Suggestion)list.get(i);
result[i][0]=sug.getSugContent();
///System.out.println(sug.getSugContent());
}
//添加所在单位
Branchbranch=branchManage.getBranchById(branchId);
StringbranchName=branch.getBranchName();
if(CommonUtils.isEmpty(branchName))branchName="所有机构";
//添加级别
SysParamparam=paramManage.getParam("3",level);
StringparamName=param.getParamName();
if(CommonUtils.isEmpty(paramName))paramName="所有级别";
try{
StringstrFileName="question.xls";
strFileName=java.net.URLEncoder.encode(strFileName,"UTF-8");//处理中文文件名的问题
strFileName=newString(strFileName.getBytes("UTF-8"),"GBK");//处理中文文件名的问题
response.reset();
response.setCharacterEncoding("UTF-8");
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition","attachment;filename="+strFileName);
ByteArrayOutputStreambaos=newByteArrayOutputStream();
//创建可写入的Excel工作薄
//WritableWorkbookbook=Workbook.createWorkbook(newFile(excelFileName));
WritableWorkbookbook=Workbook.createWorkbook(baos);
//写工作表名字
WritableSheetsheet=book.createSheet("XXX建议",0);
//此处可以设置列的宽度
intcolumn=0;
sheet.setColumnView(column++,30);
sheet.setColumnView(column++,30);
sheet.setColumnView(column++,30);
sheet.setColumnView(column++,30);
sheet.addCell(newLabel(0,0,"建议("+branchName+")("+paramName+")"));//增加excel单元格
//sheet.addCell(newLabel(1,0,"部门名称"));//增加excel单元格
//sheet.addCell(newLabel(2,0,"部门类型"));//增加excel单元格
//sheet.addCell(newLabel(3,0,"综合成绩"));//增加excel单元格
//result=getSelectResultWithStringArray(ds,sql);
introws=result.length;
if(rows!=0){
intcols=result[0].length;
for(inti=0;i<rows;i++){
for(intj=0;j<cols;j++){
sheet.addCell(newLabel(j,i+1,result[i][j]));
}
}
}
book.write();//写入byte输出流数组
book.close();//jxl对象关闭
ServletOutputStreamout=response.getOutputStream();
baos.writeTo(out);
out.flush();
}catch(IOExceptione){
e.printStackTrace();
}catch(WriteExceptione){
e.printStackTrace();
}
returnnull;
}
publicSatisfyManagegetSatisfyManage(){
returnsatisfyManage;
}
publicvoidsetSatisfyManage(SatisfyManagesatisfyManage){
this.satisfyManage=satisfyManage;
}
publicBranchManagegetBranchManage(){
returnbranchManage;
}
publicvoidsetBranchManage(BranchManagebranchManage){
this.branchManage=branchManage;
}
publicParamManagegetParamManage(){
returnparamManage;
}
publicvoidsetParamManage(ParamManageparamManage){
this.paramManage=paramManage;
}
}
- 大学生学互联网技术好不好?武汉北大青鸟
- 武汉比较好的新媒体互联网运营培训学校学费情况
- 武汉全媒体短视频运营哪个培训机构好?全媒体运营专业
- 武汉新媒体运营培训班靠谱推荐?北大青鸟助你成就新媒体之路!
- 武汉北大青鸟2024年寒假招生火热启动!
- 北大青鸟:北大青鸟招生简章【2024新版】
- 武汉网络安全工程师学什么?计算机网络安全培训
- 武汉计算机职业培训学校哪家好?
- 在武汉学前端开发后的就业前景如何?
- 武汉北大青鸟全媒体直播培训:科技改变了世界
看过该Java开发的还看过
本文标题:#Java教程:Java Excel读写组件jxl使用#,宏鹏发布于北大青鸟鲁广校区。武汉北大青鸟鲁广校区java技术 packagecom.yinbo.satisfy.web.struts; importjavax.servlet.ServletOutputStream; importjavax.servlet.http.HttpServletRequest; importjavax.servlet.http.HttpServletResponse; importorg.apache.struts.action