请看excel分类,其他的博客,下面的博客写的比较早,没啥太大利用价值,纯粹是复制代码

springMVC,

但是,原理应该是一样的,直接贴代码。

因为最近要写一个excel上传数据的,所以,先把下载excel的代码贴上来。

@SuppressWarnings({ "unchecked", "rawtypes" })@RequestMapping(value = "/form/downs/downloadExcel")public ResponseEntity<byte[]> downloadExcelCopy(PProductForm form) throws Exception {byte[] data = null;HttpHeaders header = new HttpHeaders();try {Map<String, Object> condition = new HashMap<>();Map<String, Object> accountInfo = (HashMap) this.request.getSession().getAttribute("pt_accountInfo");String employeeId = (String) accountInfo.get("employeeId");if (Strings.isNullOrEmpty(employeeId)) {} else {List<String> proids = new ArrayList<>();for (String taskId : form.getSubIds().split(",")) {proids.add(taskId);}System.out.println("*************************IDS是:"+form.getSubIds());WritableWorkbook workbook;String absolutePath = Param.getParam("ebmep.root.path").get("dir").replace("-", ":");String folder = Param.getParam("download.directory.config").get("product");Properties props = new Properties();InputStream in = this.getClass().getResourceAsStream("/product_custom_code.properties");props.load(in);String fileName = props.getProperty("excel_tsjbdc_name");String path = folder + File.separator + fileName;FileUtil.newFolder(absolutePath + folder);File file = new File(absolutePath + path);workbook = jxl.Workbook.createWorkbook(file);WritableSheet sheet = workbook.createSheet(fileName, 0);String[] title = {UploadConstants.PRO_EXPORT_ORDER,//序号 0UploadConstants.PRO_EXPORT_TIT,//图书名称1UploadConstants.PRO_EXPORT_THDH,//是否中国标准书号2UploadConstants.PRO_EXPORT_THWLDH,//CIP分类号3UploadConstants.PRO_EXPORT_ISBN,//ISBN编码4UploadConstants.PRO_EXPORT_THDZ,//新出或重印或租型5UploadConstants.PRO_EXPORT_ZS,//字数(千字)6UploadConstants.PRO_EXPORT_SFTS,//是否套书7UploadConstants.PRO_EXPORT_BCYSC,//本次印数(册)8UploadConstants.PRO_EXPORT_MCDJ,//每册、张定价(元)9UploadConstants.PRO_EXPORT_MCYZ,//每册、张印张(印张)10UploadConstants.PRO_EXPORT_FZB,//分装部(卷张册)11UploadConstants.PRO_EXPORT_BCYST,//本次印数(套)12UploadConstants.PRO_EXPORT_MTDJ,//每套定价(元)13UploadConstants.PRO_EXPORT_MTYZ,//每套印张(印张)14UploadConstants.PRO_EXPORT_DJZJE,//定价总金额(元)15UploadConstants.PRO_EXPORT_CYGG,//常用规格16UploadConstants.PRO_EXPORT_ZDY,//自定义17UploadConstants.PRO_EXPORT_BCZYZ,//本次总印张(千印张)18UploadConstants.PRO_EXPORT_BOOK,//是否课本19UploadConstants.PRO_EXPORT_SFJF,//是否教辅读物20UploadConstants.PRO_EXPORT_SFSE,//是否少儿读物21UploadConstants.PRO_EXPORT_SFGJ,//是否古籍整理图书22UploadConstants.PRO_EXPORT_TRAN,//是否翻译图书23UploadConstants.PRO_EXPORT_SIZE,//开本24UploadConstants.PRO_EXPORT_LANG,//文种(字)25UploadConstants.PRO_EXPORT_PACO,//页码26UploadConstants.PRO_EXPORT_FIA,//著(编、绘)译者27UploadConstants.PRO_EXPORT_REM,//备注28};for (int i = 0; i < title.length; i++) {sheet.addCell(new Label(i, 0, title[i]));}int line = 1;for (String proId : proids) {PProduct product = this.productService.getProduct(proId);condition.clear();condition.put("productId", product.getId());List<PProductStylebook> productPropList = this.productStylebookService.getProductPropList(condition, null);Map<String, Object> productStylebookMap = new HashMap<>();for (PProductStylebook pProductStylebook : productPropList) {productStylebookMap.put(pProductStylebook.getSubjectCode(), pProductStylebook.getBookPage());}if (product != null && productPropList.size() > 0) {/*******************************************************************************************///序号0sheet.addCell(new Label(0, line, Integer.toString(line)));//图书名称1if (product.getTitle() != null) {sheet.addCell(new Label(1, line, product.getTitle()));} else {sheet.addCell(new Label(1, line, ""));}//是否中国标准书号2sheet.addCell(new Label(2, line, ""));//CIP分类号3if (productPropList.get(0).getSubjectCode() != null) {sheet.addCell(new Label(3, line, productPropList.get(0).getSubjectCode()));} else {sheet.addCell(new Label(3, line, ""));}//ISBN编码4if (product.getIsbn() != null) {sheet.addCell(new Label(4, line, product.getIsbn()));} else {sheet.addCell(new Label(4, line, ""));}//新出或重印或租型5if (productPropList.get(0).getBookRent() != null) {//2c9080904c53df44014c540fce60001dif(this.dicClassService.getDic(productPropList.get(0).getBookRent()) != null){sheet.addCell(new Label(5, line, this.dicClassService.getDic(productPropList.get(0).getBookRent()).getName()));}else{sheet.addCell(new Label(5, line, productPropList.get(0).getBookRent()));}} else {sheet.addCell(new Label(5, line, ""));}//sheet.addCell(new Label(, line, "新出或重印或租型"));   bookRent//字数(千字)6if (productPropList.get(0).getPageNum() != null) {sheet.addCell(new Label(6, line, Integer.toString(productPropList.get(0).getPageNum())));} else {sheet.addCell(new Label(6, line, ""));}//套书7if (productPropList.get(0).getBooksFlg() != null) {if(this.dicClassService.getDic(productPropList.get(0).getBooksFlg())!=null ){sheet.addCell(new Label(7, line, this.dicClassService.getDic(productPropList.get(0).getBooksFlg()).getName()));}else{sheet.addCell(new Label(7, line, productPropList.get(0).getBooksFlg()));}} else {sheet.addCell(new Label(7, line, ""));}//本次印数(册)8sheet.addCell(new Label(8, line, ""));//每册、张定价(元)9if (product.getPrice() != null) {sheet.addCell(new Label(9, line, String.valueOf(product.getPrice())));} else {sheet.addCell(new Label(9, line, ""));}//sheet.addCell(new Label(, line, "每册、张定价(元)"));  //每册、张印张(印张)10sheet.addCell(new Label(10, line, ""));//分装部(卷张册)11sheet.addCell(new Label(11, line, ""));//本次印数(套)12sheet.addCell(new Label(12, line, ""));//每套定价(元)13sheet.addCell(new Label(13, line, ""));//每套印张(印张)14sheet.addCell(new Label(14, line, ""));//定价总金额(元)15if (product.getPrice() != null) {sheet.addCell(new Label(15, line, String.valueOf(product.getPrice())));} else {sheet.addCell(new Label(15, line, ""));}//sheet.addCell(new Label(15, line, "定价总金额(元)")); getPrice//常用规格16   pageSpecif (productPropList.get(0).getPageSpec() != null) {sheet.addCell(new Label(16, line, productPropList.get(0).getPageSpec()));} else {sheet.addCell(new Label(16, line, ""));}//自定义17sheet.addCell(new Label(17, line, ""));//本次总印张(千印张)18if (product.getTotalNum() != null) {sheet.addCell(new Label(18, line, Integer.toString(product.getTotalNum())));} else {sheet.addCell(new Label(18, line, ""));}//是否课本19if (productPropList.get(0).getBook() != null) {if(this.dicClassService.getDic(productPropList.get(0).getBook())!=null){sheet.addCell(new Label(19, line,this.dicClassService.getDic(productPropList.get(0).getBook()).getName() ));}else{sheet.addCell(new Label(19, line,productPropList.get(0).getBook()));}} else {sheet.addCell(new Label(19, line, ""));}//是否教辅读物20sheet.addCell(new Label(20, line, ""));//是否少儿读物21if (productPropList.get(0).getChildBook() != null) {if(this.dicClassService.getDic(productPropList.get(0).getChildBook())!=null){sheet.addCell(new Label(21, line, this.dicClassService.getDic(productPropList.get(0).getChildBook()).getName()));}else{sheet.addCell(new Label(21, line, productPropList.get(0).getChildBook()));    }} else {sheet.addCell(new Label(21, line, ""));}//是否古籍整理图书22sheet.addCell(new Label(22, line, ""));//是否翻译图书23if (productPropList.get(0).getTranslateBook() != null) {if(this.dicClassService.getDic(productPropList.get(0).getTranslateBook())!=null){sheet.addCell(new Label(23, line,this.dicClassService.getDic(productPropList.get(0).getTranslateBook()).getName() ));  }else{sheet.addCell(new Label(23, line,productPropList.get(0).getTranslateBook()  ));}} else {sheet.addCell(new Label(23, line, ""));}//开本24if (product.getSize() != null) {sheet.addCell(new Label(24, line, product.getSize()));} else {sheet.addCell(new Label(24, line, ""));}//文种(字)25if (productPropList.get(0).getLanguage() != null) {if(this.dicClassService.getDic(productPropList.get(0).getLanguage())!=null){sheet.addCell(new Label(25, line, this.dicClassService.getDic(productPropList.get(0).getLanguage()).getName()));}else{sheet.addCell(new Label(25, line, productPropList.get(0).getLanguage()));  }} else {sheet.addCell(new Label(25, line, ""));}//页码26if (productPropList.get(0).getPageCount() != null) {sheet.addCell(new Label(26, line, Integer.toString(productPropList.get(0).getPageCount())));} else {sheet.addCell(new Label(26, line, ""));}//著(编、绘)译者27if (product.getFirstAuthor() != null) {sheet.addCell(new Label(27, line, product.getFirstAuthor()));} else {sheet.addCell(new Label(27, line, ""));}//备注28if ( productPropList.get(0).getRemark()!= null) {sheet.addCell(new Label(28, line, productPropList.get(0).getRemark()));} else {sheet.addCell(new Label(28, line, ""));}line++;}else{/*******************************************************************************************///序号0sheet.addCell(new Label(0, line, Integer.toString(line)));//图书名称1if (product.getTitle() != null) {sheet.addCell(new Label(1, line, product.getTitle()));} else {sheet.addCell(new Label(1, line, ""));}//是否中国标准书号2sheet.addCell(new Label(2, line, ""));//CIP分类号3sheet.addCell(new Label(3, line, ""));//ISBN编码4if (product.getIsbn() != null) {sheet.addCell(new Label(4, line, product.getIsbn()));} else {sheet.addCell(new Label(4, line, ""));}//新出或重印或租型5sheet.addCell(new Label(5, line, ""));//字数(千字)6sheet.addCell(new Label(6, line, ""));//套书7sheet.addCell(new Label(7, line, ""));//本次印数(册)8sheet.addCell(new Label(8, line, ""));//每册、张定价(元)9if (product.getPrice() != null) {sheet.addCell(new Label(9, line, String.valueOf(product.getPrice())));} else {sheet.addCell(new Label(9, line, ""));}//sheet.addCell(new Label(, line, "每册、张定价(元)"));  //每册、张印张(印张)10sheet.addCell(new Label(10, line, ""));//分装部(卷张册)11sheet.addCell(new Label(11, line, ""));//本次印数(套)12sheet.addCell(new Label(12, line, ""));//每套定价(元)13sheet.addCell(new Label(13, line, ""));//每套印张(印张)14sheet.addCell(new Label(14, line, ""));//定价总金额(元)15if (product.getPrice() != null) {sheet.addCell(new Label(15, line, String.valueOf(product.getPrice())));} else {sheet.addCell(new Label(15, line, ""));}//常用规格16   pageSpecsheet.addCell(new Label(16, line, ""));//自定义17sheet.addCell(new Label(17, line, ""));//本次总印张(千印张)18if (product.getTotalNum() != null) {sheet.addCell(new Label(18, line, Integer.toString(product.getTotalNum())));} else {sheet.addCell(new Label(18, line, ""));}//是否课本19sheet.addCell(new Label(19, line, ""));//是否教辅读物20sheet.addCell(new Label(20, line, ""));//是否少儿读物21sheet.addCell(new Label(21, line, ""));//是否古籍整理图书22sheet.addCell(new Label(22, line, ""));//是否翻译图书23sheet.addCell(new Label(23, line, ""));//开本24if (product.getSize() != null) {sheet.addCell(new Label(24, line, product.getSize()));} else {sheet.addCell(new Label(24, line, ""));}//文种(字)25sheet.addCell(new Label(25, line, ""));//页码26sheet.addCell(new Label(26, line, ""));//著(编、绘)译者27if (product.getFirstAuthor() != null) {sheet.addCell(new Label(27, line, product.getFirstAuthor()));} else {sheet.addCell(new Label(27, line, ""));}//备注28sheet.addCell(new Label(28, line, ""));line++;}}workbook.write();workbook.close();//下载header.setContentType(MediaType.parseMediaType("application/x-msdownload"));header.set("Content-Disposition", "attachment; filename=" + new String(fileName.getBytes("utf-8"), "ISO8859-1"));data = FileUtils.readFileToByteArray(new File(absolutePath + path));}} catch (Exception e) {e.printStackTrace();}return new ResponseEntity<byte[]>(data, header, HttpStatus.OK);}

先贴代码,过几天再写代码注释,讲解,啥啥的。

转载于:https://my.oschina.net/wswhr/blog/709836

java导出excel相关推荐

  1. java导出excel设置行高列宽_使用POI生成Excel文件,可以自动调整excel列宽

    //autoSizeColumn()方法自动调整excel列宽 importjava.io.FileOutputStream; importorg.apache.poi.hssf.usermodel. ...

  2. java导出excel文件名_怎么解决java导出excel时文件名乱码

    怎么解决java导出excel时文件名乱码 发布时间:2020-06-19 16:59:00 来源:亿速云 阅读:137 作者:元一 java解决导出Excel时文件名乱码的方法示例:String a ...

  3. java 导出excel教程_Java导出Excel表格

    Java导出Excel表格 导出Excel表格需要一个poi-3.9.jar的包,该包在网上可以找到. 第一步,创建Excel对象. HSSFWorkbook workbook = new HSSFW ...

  4. java 浏览器 excel导出excel_使用Java导出Excel表格并由浏览器直接下载——基于POI框架...

    非异步方法 /** * 使用Java导出Excel表格并由浏览器直接下载--基于POI框架 * * @param response * @return * @throws IllegalAccessE ...

  5. java文件无法导出excel文件,【excel表格文件格式无效】java导出excel,excel打不开,报文件格式无效,怎么解决!...

    excel提示 打开的文件.xls的格式与文件扩展名不一致怎么办 如果打开文件的格式与文件的扩展名不一致,只要能够打开就不用去管他. java导出excel,excel打不开,报文件格式无效,怎么解决 ...

  6. Java 导出excel进行换行

    java 导出Excel进行换行 String.valueOf((char)10) 在导出excel 的时候,如果原始文字中含有 \n 字符, 如果把 \n 替换为<br/>,excel不 ...

  7. java导出Excel(POI模式 Ajax下载 Post传参) bootstrap table getVisibleColumns获取显示的列

    工具类 (正式使用) package com.qyj.utils;import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson. ...

  8. java 导出excel 附带图片

    java 导出excel 附带图片,思路将后台数据里保存的图片url转为file ,添加到excel里导出 代码示例 String imgPath = filePath +item.getFilePa ...

  9. Java导出excel文件以.xlsx后缀结尾,可设置部分单元格只读

    前言 最近在做一个小项目,有个模块的功能涉及到excel的导入导出,并且要求对导出的excel文件部分列和单元格设置为只读不可更改,在网上到处查找了一番资料,结合自己的想法,发现也并不难,这里整理记录 ...

  10. Java导出excel文件

    需求 将每个xmpp机房的在线/离线用户信息导出到Excel表格中(定时任务+网页按钮),并在网页上提供下载按钮进行下载. 效果预览 导出文件效果 点击下载弹出框效果 代码总览 /** ". ...

最新文章

  1. 互联网协议 — HTTP/2 超文本传输协议第 2 版
  2. 深入理解最大池化为什么能够实现不变性?
  3. 网络与IO知识扫盲(七):仿照Netty工作架构图,手写多路复用模型
  4. 关于昌平100度健身俱乐部全民健身情况调查报告
  5. 微信升级最新版本后,可在一对一聊天场景中访问外部链接
  6. 使用mysql命令还原student表_自用mysql自带命令实现数据库备份还原的方法
  7. python基础教程期末考试题库_PYTHON语言应用试题题目及答案,课程2020最新期末考试题库,章节测验答案...
  8. python2.x提示这个错误:UnicodeDecodeError: 'ascii' codec can't decode byte 0xe8 in position
  9. android音乐播放器歌词乱码,手机听歌显示乱码 没歌词 教你如何一键解决
  10. 51单片机学习入门(三):串口
  11. c语言kill暂停和恢复进程,Linux暂停和恢复进程
  12. MDK中编译报错 Error: L6218E: Undefined symbol SystemInit (referred from startup_cmsdk_cm0.o).
  13. glsl中uniform,attribute和varying详解
  14. 先吃奶油还是先吃蛋糕--推迟满足感
  15. aa44444444444
  16. 线性回归实战---Abalone鲍鱼年龄预测
  17. 第三章 变量和数据类型_C语言中的小数(float,double)
  18. 关于千兆交换机,你必须知道的几个点,建议收藏!
  19. 1688采源宝的商家靠谱吗 怎么入驻成为阿里采源宝商家
  20. PHPExcel中文开发手册翻译版(2)

热门文章

  1. HTML5+CSS3期末大作业:电影网站设计——黑色扁平的电影工作室静态网页 学生DW网页设计作业成品 web课程设计网页规划与设计 计算机毕设网页设计源码
  2. 计算机网络的发展及其现状分析,计算机网络技术的发展现状和趋势分析
  3. iPhone手机使用:iPhone XR的双卡双待设置
  4. P3303 [SDOI2013]淘金
  5. 如何用计算机模拟光的传播,一种模拟激光辐射颗粒的数值建模方法与流程
  6. 2021届 联发科技视频二面 嵌入式软件
  7. 方向gravity_两种对齐方式,layout_gravity和gravity大不同
  8. ThinkPHP5.1批量删除
  9. A5931三相无传感器 BLDC 风扇驱动器 IC
  10. hive 常用正则表达式