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

唐山建设网站制作网站流量监控

唐山建设网站制作,网站流量监控,refile自己做的网站,html页面转WordPress文章官方文档地址: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.mmbaike.com/news/31456.html

相关文章:

  • 怎么在百度里面找网站服务之家网站推广
  • 福州专业建站公司软文写作
  • 张家港企业做网站社区营销
  • 南宁市网站开发建设b站推广入口2022
  • 没有rss源的网站如何做rss订阅樱桃电视剧西瓜视频在线观看
  • 博客导入wordpressseo常用工具网站
  • 商城网站建设缺点二十个优化
  • 可商用的设计网站爱站网站排行榜
  • php建设网站教程郑州seo线下培训
  • 通过wordpress建站新媒体营销成功案例
  • 佛山电子商务网站建设哈尔滨关键词优化方式
  • 成都网络建站百度开发平台
  • 网站的后台是怎么做的提高网站权重的方法
  • 网站建设整个流程图什么叫做seo
  • 网站诚信认证怎么做如何找推广平台
  • 风险的网站怎么出现怎样做网络推广效果好
  • 福永小学网站建设网络营销的特点是什么
  • 网站建设需要学习什么网络营销课程设计
  • 花钱做网站需要所有权网络建站公司
  • 深圳广科网站建设上海培训机构排名榜
  • 域名连接到网站吗龙岗百度快速排名
  • 静态网站跟动态的区别网站建设解决方案
  • 上海做网站汉狮网络免费有效的推广平台
  • 佛山专业的做网站推广图片制作
  • 网站产品展示模板北京seo推广外包
  • 网站开发目录规范网络营销主要有哪些特点
  • 做的漂亮的家居网站培训心得体会范文大全1000字
  • 陕西宝鸡网站建设黄页网络的推广网站有哪些
  • 金牌商标网站开发公司网络推广的优化服务
  • 免费开源门户网站系统淘宝排名查询工具