HSSFWorkbook wk = new HSSFWorkbook();
HSSFSheet sheet = wk.createSheet("考生证书信息");
this.setSheetColumnWidth(sheet);
HSSFRow row = sheet.createRow((int) 0);

HSSFCellStyle style = wk.createCellStyle();
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);

HSSFCellStyle style2 = wk.createCellStyle();
style2.setAlignment(HSSFCellStyle.ALIGN_LEFT);
this.createCell(row, 0, style, HSSFCell.CELL_TYPE_STRING,"考生姓名");
this.createCell(row, 1, style, HSSFCell.CELL_TYPE_STRING,"性别");
this.createCell(row, 2, style, HSSFCell.CELL_TYPE_STRING,"出生日期");
this.createCell(row, 3, style, HSSFCell.CELL_TYPE_STRING,"文化程度");
this.createCell(row, 4, style, HSSFCell.CELL_TYPE_STRING,"颁证日期");
this.createCell(row, 5, style, HSSFCell.CELL_TYPE_STRING,"证书号");
this.createCell(row, 6, style, HSSFCell.CELL_TYPE_STRING,"身份证号");
this.createCell(row, 7, style, HSSFCell.CELL_TYPE_STRING,"职业(工种)");
this.createCell(row, 8, style, HSSFCell.CELL_TYPE_STRING,"鉴定级别");
this.createCell(row, 9, style, HSSFCell.CELL_TYPE_STRING,"理论成绩");
this.createCell(row, 10, style, HSSFCell.CELL_TYPE_STRING,"实操成绩");
this.createCell(row, 11, style, HSSFCell.CELL_TYPE_STRING,"综合成绩");
this.createCell(row, 12, style, HSSFCell.CELL_TYPE_STRING,"外语成绩");
this.createCell(row, 13, style, HSSFCell.CELL_TYPE_STRING,"评定成绩");
this.createCell(row, 14, style, HSSFCell.CELL_TYPE_STRING,"鉴定部门");
this.createCell(row, 15, style, HSSFCell.CELL_TYPE_STRING,"鉴定计划编号");

for (int i = 0; i < list.size(); i++) {
KsScoreListVO model=list.get(i);
HSSFRow row1 = sheet.createRow((short) (i + 1));// 建立新行

if(StringUtils.isNotBlank(model.getStuname()))

this.createCell(row1, 0, style,HSSFCell.CELL_TYPE_STRING, model.getStuname());

if(StringUtils.isNotBlank(model.getSex())){
if(model.getSex().equals("9")){
this.createCell(row1, 1, style,HSSFCell.CELL_TYPE_STRING, "未知");
}else{
this.createCell(row1, 1, style,HSSFCell.CELL_TYPE_STRING, model.getSex());
}
}

if(StringUtils.isNotBlank(model.getCredennum())){
String date=model.getCredennum().substring(6, 10)+"-"+model.getCredennum().substring(10, 12)+"-"
+model.getCredennum().substring(12, 14);
this.createCell(row1, 2, style,HSSFCell.CELL_TYPE_STRING, date);
}

if(StringUtils.isNotBlank(model.getEducation()))

this.createCell(row1, 3, style,HSSFCell.CELL_TYPE_STRING, model.getEducation());

if(model.getZsbftime()!=null)

this.createCell(row1, 4, style,HSSFCell.CELL_TYPE_STRING, DateUtils.format(model.getZsbftime(), "yyyy-MM-dd"));

if(StringUtils.isNotBlank(model.getZsnum()))

this.createCell(row1, 5, style,HSSFCell.CELL_TYPE_STRING, model.getZsnum());

if(StringUtils.isNotBlank(model.getCredennum()))

this.createCell(row1, 6, style,HSSFCell.CELL_TYPE_STRING, model.getCredennum());

if(StringUtils.isNotBlank(model.getZygzname()))

this.createCell(row1, 7, style,HSSFCell.CELL_TYPE_STRING, model.getZygzname());

if(StringUtils.isNotBlank(model.getJdrank()))

this.createCell(row1, 8, style,HSSFCell.CELL_TYPE_STRING, model.getJdrank());

if(StringUtils.isNotBlank(model.getLl_score()))

this.createCell(row1, 9, style,HSSFCell.CELL_TYPE_STRING, model.getLl_score());

if(StringUtils.isNotBlank(model.getSc_score()))

this.createCell(row1, 10, style,HSSFCell.CELL_TYPE_STRING, model.getSc_score());

if(StringUtils.isNotBlank(model.getZh_score()))

this.createCell(row1, 11, style,HSSFCell.CELL_TYPE_STRING, model.getZh_score());

if(StringUtils.isNotBlank(model.getWy_score()))

this.createCell(row1, 12, style,HSSFCell.CELL_TYPE_STRING, model.getWy_score());

if(StringUtils.isNotBlank(model.getPd_score()))

this.createCell(row1, 13, style,HSSFCell.CELL_TYPE_STRING, model.getPd_score());

if(StringUtils.isNotBlank(model.getBmdw()))

this.createCell(row1, 14, style2,HSSFCell.CELL_TYPE_STRING, model.getBmdw());

if(StringUtils.isNotBlank(model.getJdjhnum()))

this.createCell(row1, 15, style,HSSFCell.CELL_TYPE_STRING, model.getJdjhnum());

}

ByteArrayOutputStream out=new ByteArrayOutputStream();
try {
wk.write(out);
servletRequest.setAttribute("excelStream",new ByteArrayInputStream(out.toByteArray()));
servletRequest.setAttribute("filename", new String(vo.getJdjh().getBytes("GBK"),"ISO-8859-1")+".xls");//设置文件名
return SUCCESS;
} catch (IOException e) {
e.printStackTrace();
ExceptionLogHandler.saveExceptionLog(e,(String) getSession().get(SessionConstants.WSSIP_OPERATOR_ID));
return ERROR;
}finally{
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
ExceptionLogHandler.saveExceptionLog(e,(String) getSession().get(SessionConstants.WSSIP_OPERATOR_ID));
}
}

private void setSheetColumnWidth1(HSSFSheet sheet) {

// 根据你数据里面的记录有多少列,就设置多少列

sheet.setColumnWidth((short)0, (short)6000);

sheet.setColumnWidth((short)1, (short)6000);

sheet.setColumnWidth((short)2, (short)3000);

sheet.setColumnWidth((short)3, (short)2000);

sheet.setColumnWidth((short)4, (short)4000);

sheet.setColumnWidth((short)5, (short)4000);

sheet.setColumnWidth((short)6, (short)4000);
sheet.setColumnWidth((short)7,(short) 4000);
sheet.setColumnWidth((short)8,(short) 4000);
sheet.setColumnWidth((short)9,(short) 4000);
sheet.setColumnWidth((short)10,(short) 6000);
sheet.setColumnWidth((short)11,(short) 4000);
sheet.setColumnWidth((short)12,(short) 4000);

}

private void createCell(HSSFRow row, int column, HSSFCellStyle style,

int cellType, Object value) {

HSSFCell cell = row.createCell((short)column);

if (style != null) {

cell.setCellStyle(style);
}
switch (cellType) {
case HSSFCell.CELL_TYPE_BLANK: {
}
break;
case HSSFCell.CELL_TYPE_STRING: {
cell.setCellValue(value.toString());
}
break;
case HSSFCell.CELL_TYPE_NUMERIC: {
cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
cell.setCellValue(Double.parseDouble(value.toString()));
}
break;
default:
break;
}
}

private String fileName;

public String getFileName() {
return fileName;
}

public void setFileName(String fileName) throws UnsupportedEncodingException {
this.fileName = new String(fileName.getBytes("iso8859-1"), "utf-8");
}

//获取输出流
public InputStream getInputExcel()
{
return (InputStream)servletRequest.getAttribute("excelStream");
}

--------------------------------------------------------
jsp页面

function zs_export(type){
var row =grid2.getSelected();
if(!row){
mini.alert("请选择一条记录!");
return;
}
$("#id_xls").val(row.id);
$("#types_xls").val(type);
$("#jdjh_xls").val(row.jdjh);
var excelForm = document.getElementById("excelForm");
excelForm.action="${pageContext.request.contextPath}/osta/zsgl/exportexcel.action";
excelForm.submit();
}
----------------参数和from表单
<iframe id="exportIFrame" style="display:none;"></iframe>
<!--导出Excel相关HTML-->
<form id="excelForm" method="post" target="excelIFrame">
<input type="hidden" name="id" id="id_xls" />
<input type="hidden" name="types" id="types_xls" />
<input type="hidden" name="jdjh" id="jdjh_xls" />
</form>
<iframe id="excelIFrame" name="excelIFrame" style="display:none;"></iframe>

转载于:https://www.cnblogs.com/wanghongwei123/p/7168454.html

纯java生成excel相关推荐

  1. 超详细的java生成excel文件并下载

    在网上随手一搜,可以搜到很多java生成excel文件相关的博客,但每个都有不同,核心点说清楚了,但具体运用的时候,相信大家或多或少都没法一次直接运用,这样每次去找并且运用的时候很费时间,所以这也是我 ...

  2. vue3.0 + xlsx 实现纯前端生成excel表格

    vue3.0 + xlsx 实现纯前端生成excel表格 1.安装依赖 npm install xlsx --save 2.导入依赖 import * as XLSX from 'xlsx' // V ...

  3. html5生成excel,H5纯前端生成Excel表格

    H5纯前端生成Excel表格方法如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 var arr = [ 14 { 15 "姓名":"喵喵喵" ...

  4. Java生成Excel加密

    Java生成Excel加密文件 导入poi包 <!-- POI --> <dependency> <groupId>org.apache.poi</group ...

  5. 使用Java生成excel文件:apache-poi

    使用办公文档插件: 文件-------HSSFWorkbook 页----------HSSFSheet 行----------HSSFRow 列----------HSSFCell 样式------ ...

  6. java生成 excel 并导出文件

    给大家介绍一个代码在线自动生成的网站:www.5ceo.cn 技术之家    或者加qq群: 527796869 目前,比较常用的实现Java导入.导出Excel的技术有两种Jakarta POI和J ...

  7. Java POI Excel( pio:纯java操作excel的api )

    2010-03-17 21:35 POI官方网址:http://poi.apache.org/ POI的功能实在很强大,而且是apache的子项目,它下面又包含一些Component,比如处理Exce ...

  8. java excel生成_两种方式实现java生成Excel

    Web应用中难免会遇到需要将数据导出并生成excel文件的需求.同样,对于本博客中的总结,也是建立在为了完成这样的一个需求,才开始去了解其实现形式,并且顺利完成需求的开发,先将实现过程总结于此.本博文 ...

  9. 使用java生成Excel表格

    依赖 <!-- excel表格 --> <dependency><groupId>org.apache.poi</groupId><artifac ...

最新文章

  1. linux tc打造ip流量限制
  2. 为什么阿里巴巴禁止使用存储过程?
  3. Fedora 23 将默认使用 Wayland – 多监视器支持
  4. Uber开源TensorFlow框架工具箱Ludwig,无需编码即可进行深度学习开发
  5. 关闭占用某一端口号的进程 win10
  6. 小白的算法初识课堂(part2)--选择排序
  7. pycharm是不是python编程_使用PyCharm进行python开发的简介
  8. C#:Md5和Sha1两种加密方式
  9. 【蓝桥杯历年题】2020蓝桥杯A组省赛第二场(10.17)【含蓝桥杯官网提交地址】
  10. 计算机分区格式转换,硬盘GPT分区与MBR分区如何转换
  11. 蓝桥杯备赛第一天-138译码器
  12. 思科交换机配置链路聚合
  13. 115套精品简历.zip
  14. NexT主题添加音乐
  15. 计算机初始化,win7怎么初始化电脑_手把手教你初始化win7电脑
  16. 通信协议:CAN总线
  17. echarts关系图
  18. Muti-Similarity Loss:考虑了batch中整体距离分布的对比损失函数
  19. 【CAN】 PCAN Explorer5 常用操作使用简介
  20. CDN还有这么多衍生品?! 云帆加速借技术创新笑傲短视频新蓝海

热门文章

  1. 确保您的物联网部署具备5G功能
  2. 如何将FPGA资源平民化?阿里工程师有了新突破
  3. .NET Core 实例接口代理转发
  4. FunPlus特效专家张韶勇:如何利用跨平台工具快速制作像素动画?
  5. 5年,14款近满分神作,这个独立团队打造了他们的游戏宇宙
  6. GameMaker Studio 之中的攻击与受击判定盒
  7. 街霸2的CPU是怎么对玩家作弊的?
  8. 如何跟面试公司谈论薪资?
  9. 九零后程序员心塞大哭:“我累的心脏疼,父母却说我工作很轻松”
  10. Python编程专属骚技巧7