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

搬瓦工的主机可以用来做网站吗济南seo排名搜索

搬瓦工的主机可以用来做网站吗,济南seo排名搜索,网页设计师自我介绍,深圳专业的网站制作公司一、导入maven依赖 &#xff08;很多旧项目自定义了一套Excel导出工具&#xff0c;poi版本可能不兼容&#xff0c;一般poi新旧版本不兼容分界线在3.17&#xff0c;选择3.17版本不会发生代码不兼容情况&#xff09; <dependency><groupId>com.alibaba</groupId&…

一、导入maven依赖

(很多旧项目自定义了一套Excel导出工具,poi版本可能不兼容,一般poi新旧版本不兼容分界线在3.17,选择3.17版本不会发生代码不兼容情况)

        <dependency><groupId>com.alibaba</groupId><artifactId>easyexcel</artifactId><version>2.2.6</version><exclusions><exclusion><groupId>org.apache.poi</groupId><artifactId>poi</artifactId></exclusion><exclusion><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId></exclusion><exclusion><groupId>org.apache.poi</groupId><artifactId>poi-ooxml-schemas</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>3.17</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>3.17</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>3.17</version><classifier>sources</classifier></dependency><dependency><groupId>org.apache.commons</groupId><artifactId>commons-collections4</artifactId><version>4.1</version></dependency>

二、重写easyExcel-自定义写入处理器


import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.write.merge.AbstractMergeStrategy;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellRangeAddress;import java.util.ArrayList;
import java.util.List;/*** 自定义合并策略 该类继承了AbstractMergeStrategy抽象合并策略,需要重写merge()方法* @author reshui* @date 2023/9/4**/
public class CustomMergeStrategy extends AbstractMergeStrategy {/*** 分组,每几行合并一次*/private List<Integer> exportFieldGroupCountList;/*** 目标合并列index*/private Integer targetColumnIndex;/*** 需要开始合并单元格的首行index*/private Integer rowIndex;/*** @param exportDataList exportDataList为待合并目标列的值* @param targetColumnIndex 需要合并的列* @return {@code  }* @author reshui* @date 2023/09/05*/public CustomMergeStrategy(List<String> exportDataList, Integer targetColumnIndex) {this.exportFieldGroupCountList = getGroupCountList(exportDataList);this.targetColumnIndex = targetColumnIndex;}@Overrideprotected void merge(Sheet sheet, Cell cell, Head head, Integer relativeRowIndex) {if (null == rowIndex) {rowIndex = cell.getRowIndex();}// 仅从首行以及目标列的单元格开始合并,忽略其他if (cell.getRowIndex() == rowIndex && cell.getColumnIndex() == targetColumnIndex) {mergeGroupColumn(sheet);}}private void mergeGroupColumn(Sheet sheet) {int rowCount = rowIndex;for (Integer count : exportFieldGroupCountList) {if (count == 1) {rowCount += count;continue;}// 合并单元格CellRangeAddress cellRangeAddress = new CellRangeAddress(rowCount, rowCount + count - 1, targetColumnIndex, targetColumnIndex);sheet.addMergedRegionUnsafe(cellRangeAddress);rowCount += count;}}/*** 该方法将目标列根据值是否相同连续可合并,存储可合并的行数* @param exportDataList* @return {@code List<Integer> }* @author reshui* @date 2023/09/05*/private List<Integer> getGroupCountList(List<String> exportDataList) {if (CollectionUtils.isEmpty(exportDataList)) {return new ArrayList<>();}List<Integer> groupCountList = new ArrayList<>();int count = 1;for (int i = 1; i < exportDataList.size(); i++) {if (exportDataList.get(i).equals(exportDataList.get(i - 1))) {count++;} else {groupCountList.add(count);count = 1;}}// 处理完最后一条后groupCountList.add(count);return groupCountList;}}

三、导出工具类封装

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.builder.ExcelWriterSheetBuilder;
import com.alibaba.excel.write.handler.WriteHandler;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;import org.slf4j.Logger;
import org.slf4j.LoggerFactory;import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.*;/*** 下载excel文件工具** @author reshui* @date 2023/09/05*/
public class DownloadExcelUtil {private static final Logger log = LoggerFactory.getLogger(DownloadExcelUtil.class);private final static String separatorChar = "-";public static <T> void downloadFile(HttpServletResponse response, Class<T> clazz, String data) throws IOException {String timeStamp = DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss");String fileName = timeStamp + "-log";downloadFile(response, clazz, data, fileName, "数据", null);}/*** @param response         响应请求* @param clazz            导出数据类型* @param data             数据源* @param customFileName   文件名* @param sheetName        页名* @param writeHandlerList 自定义写入处理器* @return {@code T }* @author reshui* @date 2023/09/05*/public static <T> T downloadFile(HttpServletResponse response, Class<T> clazz, String data, String customFileName, String sheetName, List<WriteHandler> writeHandlerList) throws IOException {// 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postmantry {response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");response.setCharacterEncoding("utf-8");// 这里URLEncoder.encode可以防止中文乱码 当然和easy-excel没有关系String fileName = URLEncoder.encode(customFileName, "UTF-8").replaceAll("\\+", "%20");response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");// 这里需要设置不关闭流ExcelWriterSheetBuilder writerSheetBuilder = EasyExcel.write(response.getOutputStream(), clazz).autoCloseStream(Boolean.FALSE).sheet(sheetName);if (CollUtil.isNotEmpty(writeHandlerList)) {for (WriteHandler writeHandler : writeHandlerList) {writerSheetBuilder.registerWriteHandler(writeHandler);}}writerSheetBuilder.doWrite(JSONObject.parseArray(data, clazz));} catch (Exception e) {// 重置responseresponse.reset();response.setContentType("application/json");response.setCharacterEncoding("utf-8");Map<String, String> map = new HashMap<>(2);map.put("status", "failure");map.put("message", "下载文件失败" + e.getMessage());response.getWriter().println(JSON.toJSONString(map));}return null;}/*** 出把excel** @param timeStamp       时间戳* @param excelFileName   excel文件名字* @param headClassType   头类类型* @param resultExcelList 结果excel表* @param filePath        文件路径* @author reshui* @date 2023/02/15*/public static void outputExcelToLocal(String timeStamp, String excelFileName, Class headClassType, List resultExcelList, String filePath) {//文件时间戳timeStamp = Objects.nonNull(timeStamp) ? timeStamp : StrUtil.EMPTY;String partFileName = filePath + File.separator + excelFileName + separatorChar + timeStamp + "-log.xlsx";FileUtil.touch(partFileName);EasyExcel.write(partFileName, headClassType).sheet("源数据").doWrite(resultExcelList);}/*** 简单把excel** @param excelFileName   excel文件名字* @param headClassType   头类类型* @param resultExcelList 结果excel表* @param filePath        文件路径* @author reshui* @date 2023/02/15*/public static void easyOutputExcelToLocal(String excelFileName, Class headClassType, List resultExcelList, String filePath) {String timeStamp = DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss");outputExcelToLocal(timeStamp, excelFileName, headClassType, resultExcelList, filePath);}public static void main(String[] args) {String timeStamp = DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss");String titleTmpDirPath = FileUtil.getTmpDirPath() + File.separator + "test" + File.separator + timeStamp + File.separator;try {System.out.println("日志存储地址-[" + titleTmpDirPath + "]");log.info("日志存储[" + titleTmpDirPath + "]");String partFileName = titleTmpDirPath + timeStamp + "-log.xlsx";FileUtil.touch(partFileName);EasyExcel.write(partFileName, String.class).sheet("源数据").doWrite(null);} catch (Exception e) {log.error("日志存储[" + titleTmpDirPath + "]" + "-error:", e);}}
}

四、运行

@RestController
@RequestMapping("/check")
public class TestController {@RequestMapping(value = "/run1",method = {RequestMethod.GET})public void run1(HttpServletResponse response) throws IOException {List<DemoData> demoDataList = data1();List<WriteHandler> customMergeStrategies = Arrays.asList(new CustomMergeStrategy(demoDataList.stream().map(DemoData::getName).collect(Collectors.toList()), 1));DownloadExcelUtil.downloadFile(response,DemoData.class, JSONObject.toJSONString(demoDataList),"测试","页1", customMergeStrategies);}public static List<DemoData> data1(){List<DemoData> demoDataList = new ArrayList<>();DemoData demoData0 = new DemoData();demoData0.setId("0");demoData0.setName("hello0");demoDataList.add(demoData0);DemoData demoData1 = new DemoData();demoData1.setId("1");demoData1.setName("hello1");demoDataList.add(demoData1);DemoData demoData11 = new DemoData();demoData11.setId("1");demoData11.setName("hello1");demoDataList.add(demoData11);DemoData demoData2 = new DemoData();demoData2.setId("2");demoData2.setName("hello2");demoDataList.add(demoData2);return demoDataList;}
}

http://www.yidumall.com/news/28812.html

相关文章:

  • 哪个网站专做民宿广告推广平台网站
  • 做网站需要什么功能百度入口
  • 南宁有本地租房做网站吗惠州短视频seo
  • 广西南宁建设职业学图书馆网站seo范畴有哪些
  • 网站与网页的区别济南seo网站关键词排名
  • 什么网站做顶置便宜免费站推广网站2022
  • 做注册任务的网站有哪些国内新闻最新消息简短
  • 有没有做吉祥物的网站网站创建免费用户
  • 如何做百度推广网站b站推广网站mmmnba
  • 上海有哪些做网站的西安seo服务商
  • 西安 网站建设 1如何注册自己的网站
  • 做网站需要购买服务器吗公司的seo是什么意思
  • 温州网络公司网站建设摘抄一则新闻
  • 网站怎么做第二个页面百度网盟推广
  • 现在有男的做外围女网站客服吗免费平台推广
  • 建设行业的门户网站想做seo哪里有培训的
  • 如何用网站做推广最新实时新闻
  • 制作论文招聘网站的如何快速推广app
  • 网站建设中的主要功能手机网页链接制作
  • 大型电商网站开发宁波网络营销推广公司
  • 辛集seo网站优化品牌营销策略案例
  • 广西住房建设厅网站首页一键优化清理加速
  • 网页ui设计教程深圳债务优化公司
  • 网站建设要不要学编码网站宣传文案
  • 广州网站优化实战电商平台开发需要多少钱
  • 建筑资质证书查询网站网上培训
  • 浏览器网页版在线seo入门教程
  • 中国建设银行网官方网站深圳最新消息今天
  • 怎么用织梦做网站前台seo任务
  • 自己怎样建设网站北京百度seo