欢迎访问北大青鸟鲁广校区~

  1. 加入收藏
  2. 设为主页
  3. 学校简介
北大青鸟鲁广校区

17740513250

三分钟了解北大青鸟

×
  • 数据加载中...

Java教程:Java Excel读写组件jxl使用

责任编辑:宏鹏来源:武汉北大青鸟鲁广校区发布时间:2015-10-09 10:06:33
导读:武汉北大青鸟鲁广校区java技术 packagecom.yinbo.satisfy.web.struts; importjavax.servlet.ServletOutputStream; importjavax.servlet.http.HttpServletRequest; importjavax.servlet.http.HttpServletResponse; importorg.apache.struts.action

武汉北大青鸟鲁广校区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;

}

}

本文标题:#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

专业老师指导

专业老师指导

赵老师

从事IT教育培训十年有余,致力于帮助广大学子找到适合自己的专业。

培训咨询客服

培训咨询客服

陈老师

IT培训专业客服,用自己的真诚解决了无数学子的困惑。

本文地址:https://www.027hpedu.com/wenda/java/55.html

大家都在看的大家都在看的Java开发

热门课程

更多>>
  • 数据加载中...
7天免费试学

7天课程免费试学

实战学习干货限时领取

行业解读+大咖授课+项目实操
10年以上业内强师集结,手把手带你蜕变精英!

点我咨询
×
在线咨询更多问题

如您有任何疑问
在线咨询随时为您解答或拨打咨询热线:13125006136

×
  • 姓 名*
  • 手 机*
  • QQ号/微信号
  • 所报学科 *
  • 其他备注
  • 验证码 获取验证码 *
  • 温馨提示:请保持手机畅通,咨询老师将为您提供专属的一对一报名服务。