当前位置: 首页 > news >正文

唐山建设网站制作网站优化费用报价明细

唐山建设网站制作,网站优化费用报价明细,怎样做中考成绩查询网站,专做外贸的网站有哪些资料官方文档地址:easypoi官网,官方仅供参考,部分描述有问题 excel模板预览 准备工作 事先将整理好的excel模板存在项目中,如图 excel模板预览代码 GetMapping("excel")ApiOperation("excel预览")NoLogpubli…

官方文档地址:easypoi官网,官方仅供参考,部分描述有问题

excel模板预览

准备工作

事先将整理好的excel模板存在项目中,如图
在这里插入图片描述

excel模板预览代码

	@GetMapping("excel")@ApiOperation("excel预览")@NoLogpublic void excel07(HttpServletResponse response) throws IOException {//读取文件 templates/学生信息表.xlsx是相对路径InputStream inputStream = POICacheManager.getFile("templates/学生信息表.xlsx");//创建工作簿Workbook workbook = WorkbookFactory.create(inputStream);//设置为true防止中文乱码 sheetNum默认从0开始ExcelToHtmlParams params=new ExcelToHtmlParams(workbook,true,0,"");//解析成htmlString excelToHtml = ExcelXorHtmlUtil.excelToHtml(params);response.getOutputStream().write(excelToHtml.getBytes());}

excel模板下载

准备工作

事先将整理好的excel模板存在项目中,如图
在这里插入图片描述

excel模板下载代码

	@GetMapping("downTemplate")@ApiOperation("下载模板")@NoLogpublic void downTemplate(HttpServletResponse response) throws IOException {//指定下载模板的哪个sheet页 templates/学生信息表.xlsx是相对路径TemplateExportParams template=new TemplateExportParams("templates/学生信息表.xlsx","模板2");//保证模板里面没有域占位行HashMap hashMap = new HashMap();hashMap.put("mapList",Lists.newArrayList());Workbook workbook = ExcelExportUtil.exportExcel(template,hashMap);ExcelUtils.exportExcel(response,workbook,"学生信息模板表.xlsx");}

excel模板导出简单数据代码

可以用模板指令设置导出内容的

准备工作

在这里插入图片描述
注:模板指令如下:
空格分割
三目运算 {{test ? obj:obj2}}
n: 表示 这个cell是数值类型 {{n:}}
le: 代表长度{{le:()}} 在if/else 运用{{le:() > 8 ? obj1 : obj2}}
fd: 格式化时间 {{fd:(obj;yyyy-MM-dd)}}
fn: 格式化数字 {{fn:(obj;###.00)}}
fe: 遍历数据,创建row
!fe: 遍历数据不创建row
$fe: 下移插入,把当前行,下面的行全部下移.size()行,然后插入
#fe: 横向遍历
v_fe: 横向遍历值
!if: 删除当前列 {{!if:(test)}}
单引号表示常量值 ‘’ 比如’1’ 那么输出的就是 1
&NULL& 空格
&INDEX& 表示循环中的序号,自动添加
]] 换行符 多行遍历导出
sum: 统计数据
cal: 基础的±X% 计算
dict: 字典
i18n: 国际化

excel模板导出简单数据代码

	@GetMapping("exportDataSimple")@ApiOperation("模板导出数据-简单")@NoLogpublic void exportDataSimple(HttpServletResponse response) throws IOException {TemplateExportParams template=new TemplateExportParams("templates/学生信息表.xlsx");String [] sexArr=new String[]{"男","女"};String [] subArr=new String[]{"语文","数学","英语"};List<Map<String,Object>> list= Lists.newArrayList();Map<String,Object> contentMap;for (int i = 0; i < NUM; i++) {contentMap=Maps.newHashMap();contentMap.put("name",UUID.randomUUID().toString());contentMap.put("sex",sexArr[i%2]);contentMap.put("age", new Random().nextInt(90)+10);contentMap.put("subject",subArr[i%3]);contentMap.put("score", ThreadLocalRandom.current().nextInt(40)+60);list.add(contentMap);}Map<String,Object> map= Maps.newHashMap();map.put("mapList", list);map.put("class", "一年级");map.put("date", new Date());Workbook workbook = ExcelExportUtil.exportExcel(template, map);ExcelUtils.exportExcel(response,workbook,"学生数据.xlsx");}

一些模板导出知识参考

注意事项以及常见错误参考
springboot集成easypoi并使用其模板导出功能和遇到的坑
详细easypoi导出参考
EasyPoi基本用法

excel模板导出复杂数据

用不了模板指令设置导出内容的,样式中性别那一列有下拉框,通过模板指令设置不了,所以考虑手动插入数据

excel模板导出复杂数据代码

	@GetMapping("exportDataComplex")@ApiOperation("模板导出数据-复杂")@NoLogpublic void exportDataComplex(HttpServletResponse response) throws IOException {//读取模板TemplateExportParams template=new TemplateExportParams("templates/学生信息表.xlsx",1);//模拟数据String [] sexArr=new String[]{"男","女"};String [] subArr=new String[]{"语文","数学","英语"};List<StudentTemplate> list=Lists.newArrayList();StudentTemplate student;for (int i = 0; i < NUM; i++) {student=new StudentTemplate();student.setId(i+1);student.setName(UUID.randomUUID().toString());student.setAge(new Random().nextInt(90)+10);student.setSex(sexArr[i%2]);student.setSubject(subArr[i%3]);student.setScore(ThreadLocalRandom.current().nextInt(40)+60);list.add(student);}Map<String,Object> map= Maps.newHashMap();map.put("class", "一年级");map.put("date", new Date());//导出工作簿Workbook workbook = ExcelExportUtil.exportExcel(template, map);//获取第一个sheet页Sheet sheet = workbook.getSheetAt(0);//设置列宽自适应for (int i = 0; i < 6 ; i++) {sheet.autoSizeColumn(i);sheet.setColumnWidth(i,sheet.getColumnWidth(i)*17/10);}//设置指定列宽sheet.setColumnWidth(1,21*256);//数据首行int num = sheet.getLastRowNum();//行Row row;//列Cell cell;StudentTemplate studentTemplate;//单元格样式CellStyle cellStyle = ExcelUtils.setCellStyle(workbook);//写入数据for (int i = num; i < NUM+num; i++) {row= sheet.createRow(i);studentTemplate = list.get(i - num);for (int j = 0; j < 6; j++) {cell= row.createCell(j);cell.setCellStyle(cellStyle);if (j==0) {cell.setCellValue(studentTemplate.getId());}else if(j==1){cell.setCellValue(studentTemplate.getName());}else if(j==2){cell.setCellValue(studentTemplate.getAge());}else if(j==3){cell.setCellValue(studentTemplate.getSex());}else if(j==4){cell.setCellValue(studentTemplate.getSubject());}else if(j==5){cell.setCellValue(studentTemplate.getScore());}}}ExcelUtils.exportExcel(response,workbook,"学生数据.xlsx");}

附录

ExcelUtils类

import org.apache.poi.ss.usermodel.*;import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;/*** excel工具类* @author leishen*/
public class ExcelUtils {/*** 下载文件到客户端* @param response* @param workbook* @param fileName 文件名* @throws IOException*/public static void exportExcel(HttpServletResponse response, Workbook workbook, String fileName) throws IOException {response.setCharacterEncoding("UTF-8");// 设置响应输出的头类型response.setHeader("content-Type", "application/vnd.ms-excel");// 下载文件的默认名称response.setHeader("Content-Disposition", "attachment;filename="+ URLEncoder.encode(fileName, "UTF-8"));OutputStream out = response.getOutputStream();workbook.write(out);out.flush();out.close();}/*** 设置单元格样式* @param workbook*/public static CellStyle setCellStyle(Workbook workbook){CellStyle cellStyle = workbook.createCellStyle();//水平居中cellStyle.setAlignment(HorizontalAlignment.CENTER);//垂直居中cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//上边框cellStyle.setBorderTop(BorderStyle.THIN);//下边框cellStyle.setBorderBottom(BorderStyle.THIN);//左边框cellStyle.setBorderLeft(BorderStyle.THIN);//右边框cellStyle.setBorderRight(BorderStyle.THIN);//设置字体Font font = workbook.createFont();font.setFontName("宋体");//设置样式cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);cellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());cellStyle.setFont(font);//设置自动换行cellStyle.setWrapText(true);return cellStyle;}
}
http://www.ds6.com.cn/news/96759.html

相关文章:

  • 怎样在凡科网站做网页百度关键词点击价格查询
  • 阿里云 cdn wordpress济南做seo外包
  • 做外贸的都有那些网站seo排名优化联系13火星软件
  • 品牌百度网站建设2345网址导航是病毒吗
  • 视频网站开发报告网络公司seo推广
  • 做任务推广网站电商推广和网络推广的策略
  • 大学选修课网站建设免费推广的网站
  • 厦门建网站网络运营和网络营销的区别
  • wordpress情侣博客模板下载刷移动关键词优化
  • 重庆响应式网站建设找哪家宁波网站关键词优化公司
  • 网站外的seo关键词搜索趋势
  • 郑州专业网站建设今日国内新闻最新消息大事
  • 广东网站制作报价设计培训学院
  • 外管局网站上做预收登记北京seo服务商找行者seo
  • 房天下怎样快速做网站网络营销方法有哪几种
  • 嘉兴免费网站建站模板烟台网络推广
  • 网站开发发展前景十大免费货源网站免费版本
  • 做网站需要的条件百度关键词点击器
  • 湖南省建设安监局官网站怎么快速优化关键词
  • 阳江市做网站成都seo公司排名
  • 怎么用vs2010做网站网站生成app
  • 重庆网站建设公司有哪些合肥网络推广服务
  • 便捷网站建设网站品牌推广公司
  • 做网站都有哪些软件网站运营推广的方法有哪些
  • 检察 门户网站建设北京seo站内优化
  • 广东网站开发公司爱网站
  • 手机访问wordpress网站卡免费网站外链推广
  • wordpress上传apk广州seo工资
  • 成都网络公司有哪些windows7系统优化工具
  • 个人做的好的淘宝客网站搜索排名优化公司