简单导出功能

数据封装格式

public List<List<Object>> trendExcel(AdminCrystalTrendReq adminCrystalTrendReq) {CrystalTrendReq crystalTrendReq = new CrystalTrendReq();BeanUtils.copyProperties(adminCrystalTrendReq, crystalTrendReq);crystalTrendReq.setIsAsc(false);List<CrystalTResp> crystalTResps = crystalDataApiService.trendExcel(crystalTrendReq);return Optional.ofNullable(crystalTResps).orElse(Collections.emptyList()).stream().map(d -> {List<Object> res = new ArrayList<>();res.add(d.getStatDate());res.add(d.getGetCrystalTotal());res.add(d.getGiveCrystalTotal());res.add(d.getExpendCrystalTotal());res.add(d.getPlatLaveCrystalTotal());return res;}).collect(Collectors.toList());}

代码具体导出操作

/*** 水晶数据-趋势分析数据导出接口** @param adminCrystalTrendReq 管理水晶趋势要求* @param httpServletResponse  http servlet响应*/@PostMapping("/trend/excel")@Permission(value = "data.crystal:trendExcel", name = "水晶数据-趋势分析数据导出接口")public void trendExcel(@RequestBody @Valid AdminCrystalTrendReq adminCrystalTrendReq, HttpServletResponse httpServletResponse) {try {List<List<Object>> sheet1 = crystalDataService.trendExcel(adminCrystalTrendReq);sheet1.add(0, Arrays.asList("日期", "用户获得水晶数", "平台赠送水晶数", "用户支出水晶数", "平台剩余水晶数"));// 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postmanhttpServletResponse.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");httpServletResponse.setCharacterEncoding("utf-8");// 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日HH时mm分ss秒");String fileName = URLEncoder.encode("水晶数据趋势分析数据列表" + LocalDateTime.now(ZoneOffset.ofHours(8)).format(dateTimeFormatter), "UTF-8").replaceAll("\\+", "%20");httpServletResponse.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");EasyExcel.write(httpServletResponse.getOutputStream()).autoCloseStream(Boolean.TRUE).excelType(ExcelTypeEnum.XLSX).sheet("Sheet1").doWrite(sheet1);} catch (IOException e) {log.error("水晶数据-趋势分析数据导出接口", e);}}

效果如下:


如何合并表格呢

编写表格处理工具

package app.woya.service.admin.utils;import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.write.merge.AbstractMergeStrategy;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellRangeAddress;import java.util.*;public class MergeStrategyUtil extends AbstractMergeStrategy {// 合并的列编号,从0开始,指定的index或自己按字段顺序数private Set<Integer> mergeCellIndex = new HashSet<>();// 数据集大小,用于区别结束行位置private Integer maxRow = 0;// 禁止无参声明private MergeStrategyUtil() {}public MergeStrategyUtil(Integer maxRow, int... mergeCellIndex) {Arrays.stream(mergeCellIndex).forEach(item -> {this.mergeCellIndex.add(item);});this.maxRow = maxRow;}// 记录上一次合并的信息private Map<Integer, MergeRange> lastRow = new HashMap<>();@Overrideprotected void merge(Sheet sheet, Cell cell, Head head, Integer relativeRowIndex) {int currentCellIndex = cell.getColumnIndex();// 判断该列是否需要合并if (mergeCellIndex.contains(currentCellIndex)) {String currentCellValue = cell.getStringCellValue();int currentRowIndex = cell.getRowIndex();if (!lastRow.containsKey(currentCellIndex)) {// 记录首行起始位置lastRow.put(currentCellIndex, new MergeRange(currentCellValue, currentRowIndex, currentRowIndex, currentCellIndex, currentCellIndex));return;}//有上行这列的值了,拿来对比.MergeRange mergeRange = lastRow.get(currentCellIndex);if (!(mergeRange.lastValue != null && mergeRange.lastValue.equals(currentCellValue))) {// 结束的位置触发下合并.// 同行同列不能合并,会抛异常if (mergeRange.startRow != mergeRange.endRow || mergeRange.startCell != mergeRange.endCell) {sheet.addMergedRegionUnsafe(new CellRangeAddress(mergeRange.startRow, mergeRange.endRow, mergeRange.startCell, mergeRange.endCell));}// 更新当前列起始位置lastRow.put(currentCellIndex, new MergeRange(currentCellValue, currentRowIndex, currentRowIndex, currentCellIndex, currentCellIndex));}// 合并行 + 1mergeRange.endRow += 1;// 结束的位置触发下最后一次没完成的合并if (relativeRowIndex.equals(maxRow - 1)) {MergeRange lastMergeRange = lastRow.get(currentCellIndex);// 同行同列不能合并,会抛异常if (lastMergeRange.startRow != lastMergeRange.endRow || lastMergeRange.startCell != lastMergeRange.endCell) {sheet.addMergedRegionUnsafe(new CellRangeAddress(lastMergeRange.startRow, lastMergeRange.endRow, lastMergeRange.startCell, lastMergeRange.endCell));}}}}}class MergeRange {public int startRow;public int endRow;public int startCell;public int endCell;public String lastValue;public MergeRange(String lastValue, int startRow, int endRow, int startCell, int endCell) {this.startRow = startRow;this.endRow = endRow;this.startCell = startCell;this.endCell = endCell;this.lastValue = lastValue;}
}

数据格式依旧是List<List>格式

public List<List<Object>> trendExcel(AUnionDailyReq aUnionDailyReq) {aUnionDailyReq.setPageNo(1);aUnionDailyReq.setPageSize(999999);AppPageResp<AUnionDailyTreeResp> dataList = getDataList(aUnionDailyReq);List<List<Object>> all = new ArrayList<>();if (Objects.nonNull(dataList) && !CollectionUtils.isEmpty(dataList.getList())) {List<AUnionDailyTreeResp> list = dataList.getList();list.forEach(l -> {if (!CollectionUtils.isEmpty(l.getDailyResps())) {List<AUnionDailyResp> dailyResps = l.getDailyResps();dailyResps.forEach(d2 -> {List<Object> res = new ArrayList<>();res.add(d2.getNickName() + "(" + d2.getImNumber() + ")");res.add(d2.getDate());res.add(d2.getOnlineTime());res.add(d2.getCallCount());res.add(d2.getCallPeopleCount());res.add(d2.getCallTime());res.add(d2.getSendCount());res.add(d2.getReceiveCount());res.add(d2.getGreetCount());res.add(d2.getBeGreetCount());res.add(d2.getSendMsgScale());res.add(d2.getCrystal());all.add(res);});}});}return all;

导出代码

/*** 导出公会每日数据数据** @param aUnionDailyReq 工会的日常需要* @return {@link ApiResult}<{@link AppPageResp}<{@link AUnionDailyResp}>>*/@PostMapping("/data/export")@Permission(value = "union.daily:trendExcel", name = "导出公会每日数据数据")public void trendExcel(@RequestBody @Valid AUnionDailyReq aUnionDailyReq, HttpServletResponse httpServletResponse) {try {List<List<Object>> sheet1 = unionDailyService.trendExcel(aUnionDailyReq);sheet1.add(0,Arrays.asList("主播昵称(im)","日期", "在线时长","主动呼叫次数","主动呼叫人数","通话时长","发送消息数","接收消息数","主动打招呼","被打招呼","发送消息率","水晶收益"));// 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postmanhttpServletResponse.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");httpServletResponse.setCharacterEncoding("utf-8");// 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日HH时mm分ss秒");String fileName = URLEncoder.encode("导出公会每日数据数据" + LocalDateTime.now(ZoneOffset.ofHours(8)).format(dateTimeFormatter), "UTF-8").replaceAll("\\+", "%20");httpServletResponse.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");EasyExcel.write(httpServletResponse.getOutputStream()).registerWriteHandler(new MergeStrategyUtil(sheet1.size(), 0)).autoCloseStream(Boolean.TRUE).excelType(ExcelTypeEnum.XLSX).sheet("Sheet1").doWrite(sheet1);} catch (IOException e) {log.error("导出公会每日数据数据接口", e);}

效果图:


详细合并(自己指定某行某列合并)

使用ExcelWriterSheetBuilder

/*** 每日用户数据统计-导出接口*/@PostMapping("/statExport")@Permission(value = "data.new_user_stat:statexp", name = "每日用户数据统计-导出接口")public void statExport(@RequestBody @Valid GetCountryDayStatDetailListReq getCountryDayStatDetailListReq, HttpServletResponse httpServletResponse) {try {ExcelWriterSheetBuilder excelWriterSheetBuilder = EasyExcel.write(httpServletResponse.getOutputStream()).autoCloseStream(Boolean.TRUE).excelType(ExcelTypeEnum.XLSX).sheet("Sheet1");List<List<Object>> sheet1 = dayStatService.statDetailExport(getCountryDayStatDetailListReq, excelWriterSheetBuilder);sheet1.add(0, Arrays.asList("日期", "国家", "渠道", "登录人数", "新增人数", "充值人数", "充值笔数", "新增充值人数", "新增充值笔数", "充值金额", "官网充值", "新增充值金额", "付费率", "新增付费率"));// 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postmanhttpServletResponse.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");httpServletResponse.setCharacterEncoding("utf-8");// 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系String fileName = URLEncoder.encode("每日用户新增数据统计报表", "UTF-8").replaceAll("\\+", "%20");httpServletResponse.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");excelWriterSheetBuilder.doWrite(sheet1);} catch (IOException e) {log.error("公会待结算报表导出发生异常", e);}}
public List<List<Object>> statDetailExport(GetCountryDayStatDetailListReq getCountryDayStatDetailListReq, ExcelWriterSheetBuilder excelWriterSheetBuilder) {ApiResult<AppPageResp<DayStatData>> appPageRespApiResult = countryDayStatsApiService.statDetail(getCountryDayStatDetailListReq);if (!appPageRespApiResult.resultIsSuccess()) {return Collections.emptyList();}if (StringUtils.isEmpty(appPageRespApiResult.getData().getList())) {return Collections.emptyList();}List<List<Object>> allRowData = new ArrayList<>();AtomicInteger rowIndex = new AtomicInteger(1);appPageRespApiResult.getData().getList().forEach(dayStatData -> {//日期 国家 渠道 登录人数 新增人数 充值人数 充值笔数 新增充值人数 新增充值笔数 充值金额 官网充值 新增充值金额 付费率 新增付费率if (dayStatData.getCountryList().size() > 0) {int lastRowIndex = rowIndex.get() + dayStatData.getCountryList().stream().map(cd -> cd.getSubDeviceDatas().size()).reduce(Integer::sum).orElse(0) - 1;excelWriterSheetBuilder.registerWriteHandler(new OnceAbsoluteMergeStrategy(rowIndex.get(), lastRowIndex, 0, 0));}dayStatData.getCountryList().forEach(countryStatData -> {if (countryStatData.getSubDeviceDatas().size() > 0) {int lastRowIndex = rowIndex.get() + countryStatData.getSubDeviceDatas().size() - 1;excelWriterSheetBuilder.registerWriteHandler(new OnceAbsoluteMergeStrategy(rowIndex.get(), lastRowIndex, 1, 1));excelWriterSheetBuilder.registerWriteHandler(new OnceAbsoluteMergeStrategy(rowIndex.get(), lastRowIndex, 10, 10));}countryStatData.getSubDeviceDatas().forEach(subDeviceStatDataResp -> {List<Object> rowData = new ArrayList<>();rowData.add(dayStatData.getDate());rowData.add(countryStatData.getCountryName());rowData.add(subDeviceStatDataResp.getSubDeviceType() == 11 ? "安卓" : "ios");rowData.add(subDeviceStatDataResp.getTotalSignInUser());rowData.add(subDeviceStatDataResp.getTotalNewUser());rowData.add(subDeviceStatDataResp.getTotalRechargeUsers());rowData.add(subDeviceStatDataResp.getTotalRechargeOrders());rowData.add(subDeviceStatDataResp.getTotalNewUserRechargeUsers());rowData.add(subDeviceStatDataResp.getTotalNewUserRechargeOrders());rowData.add(subDeviceStatDataResp.getTotalRechargeAmount());rowData.add(countryStatData.getTotalThirdPartyRechargeAmount());rowData.add(subDeviceStatDataResp.getTotalNewUserRechargeAmount());rowData.add(subDeviceStatDataResp.getTotalSignInUser().intValue() == 0 ? 0L : BigDecimal.valueOf(subDeviceStatDataResp.getTotalRechargeUsers()).divide(BigDecimal.valueOf(subDeviceStatDataResp.getTotalSignInUser()), 2, RoundingMode.DOWN));rowData.add(subDeviceStatDataResp.getTotalNewUser() == 0 ? 0L : BigDecimal.valueOf(subDeviceStatDataResp.getTotalNewUserRechargeUsers()).divide(BigDecimal.valueOf(subDeviceStatDataResp.getTotalNewUser()), 2, RoundingMode.DOWN));allRowData.add(rowData);rowIndex.incrementAndGet();});});});return allRowData;}

导出效果

如何制作模板并添加批注

jar包及版本

<!--hutool工具包-->
<dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.5.1</version>
</dependency>
<!-- EasyExcel文档处理工具 -->
<dependency><groupId>com.alibaba</groupId><artifactId>easyexcel</artifactId><version>2.2.8</version>
</dependency>
@ApiOperation("获取批量导入会员模板")@GetMapping("/get/excel/template")@ApiImplicitParams({@ApiImplicitParam(name = "type", value = "类型: 1个人,2企业", required = true, dataType = "Integer")})public void getExcelTemplate(@RequestParam("type") Long type, HttpServletResponse httpServletResponse) {try {List<List<Object>> dataList = new ArrayList<>();dataList.add(new ArrayList<>(Collections.singletonList("注意:")));dataList.add(new ArrayList<>(Collections.singletonList("1、请勿修改表格中的注意事项、字段顺序,或随意增加、删除表格字段")));dataList.add(new ArrayList<>(Collections.singletonList("2、申请职务请务必保持与本商协会职务列表内的相同")));dataList.add(new ArrayList<>(Collections.singletonList(" ")));dataList.add(new ArrayList<>(Collections.singletonList(" ")));dataList.add(new ArrayList<>(type == 1 ?Arrays.asList("姓名(必填)","出生日期(必填)","性别(必填)","学历(选填)","身份证号码(必填)","申请职务(必填)","联系电话(必填)","公司名称(必填)","担任职位(必填)","所属行业(必填)") :Arrays.asList("企业名称(必填)","企业成立时间(必填)","所属行业(必填)","企业员工数量(必填)","统一社会信用代码(必填)","法人姓名(必填)","法人身份证号码(必填)","法人联系电话(必填)","联系人姓名(必填)","联系人电话(必填)","担任职位(必填)","申请职位(必填)")));String sheetName = "模板";List<CommentModel> commentList = new ArrayList<>();//查询行业List<CategoryDto> categoryDtoList = memberService.getIndustryList();String industryNotation = "注:\n";if (!CollectionUtils.isEmpty(categoryDtoList)) {industryNotation = industryNotation.concat(categoryDtoList.stream().map(CategoryDto::getName).collect(Collectors.joining("、")));}if (type == 1) {commentList.add(CommentModel.createCommentModel(sheetName, 5, 1, "注:\n1999/09/09\n"));commentList.add(CommentModel.createCommentModel(sheetName, 5, 2, "注:\n男/女\n"));commentList.add(CommentModel.createCommentModel(sheetName, 5, 3, "注:\n博士、通硕士、本科、专科、普通中专、其它\n"));commentList.add(CommentModel.createCommentModel(sheetName, 5, 5, "注:\n商协会职务\n"));commentList.add(CommentModel.createCommentModel(sheetName, 5, 9, industryNotation));} else {commentList.add(CommentModel.createCommentModel(sheetName, 5, 1, "注:\n1999/09/09\n"));commentList.add(CommentModel.createCommentModel(sheetName, 5, 2, industryNotation));commentList.add(CommentModel.createCommentModel(sheetName, 5, 3, "注:\n" +"20-99人\n" +"100-499人\n" +"500-999人\n" +"1000-9999人\n"));commentList.add(CommentModel.createCommentModel(sheetName, 5, 9, "注:\n" +"手机号码\n"));commentList.add(CommentModel.createCommentModel(sheetName, 5, 11, "注:\n" +"商协会职务\n"));}// 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postmanhttpServletResponse.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");httpServletResponse.setCharacterEncoding("utf-8");// 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日HH时mm分ss秒");String fileName = URLEncoder.encode((type == 1 ? "个人" : "企业") + "模板" + LocalDateTime.now(ZoneOffset.ofHours(8)).format(dateTimeFormatter), "UTF-8").replaceAll("\\+", "%20");httpServletResponse.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");ExcelWriter excelWriter = EasyExcel.write(httpServletResponse.getOutputStream()).inMemory(Boolean.TRUE).registerWriteHandler(new CommentWriteHandler(commentList, "xlsx")).build();WriteSheet writeSheet = EasyExcel.writerSheet(sheetName).build();excelWriter.write(dataList, writeSheet);//千万别忘记finish 会帮忙关闭流excelWriter.finish();} catch (IOException e) {log.error("批量导入会员模板-生成接口异常", e);}}

批注信息类

package com.ljq.cca.lib.ccadmin.api.domain.dto.easyExcel;import lombok.Getter;/*** 批注信息类** @author 刘俊秦*/
@Getter
public class CommentModel {/*** sheet页名称*/private String sheetName;/*** 列索引*/private int colIndex;/*** 行索引*/private int rowIndex;/*** 行索引*/private String commentContent;private void setSheetName(String sheetName) {this.sheetName = sheetName;}private void setColIndex(int colIndex) {this.colIndex = colIndex;}private void setRowIndex(int rowIndex) {this.rowIndex = rowIndex;}private void setCommentContent(String commentContent) {this.commentContent = commentContent;}private CommentModel() {}/*** 生成批注信息** @param sheetName      sheet页名称* @param rowIndex       行号* @param columnIndex    列号* @param commentContent 批注内容* @return*/public static CommentModel createCommentModel(String sheetName, int rowIndex, int columnIndex, String commentContent) {CommentModel commentModel = new CommentModel();//sheet页名称commentModel.setSheetName(sheetName);//行号commentModel.setRowIndex(rowIndex);//列号commentModel.setColIndex(columnIndex);//批注内容commentModel.setCommentContent(commentContent);return commentModel;}}

自定义批注处理器

package com.ljq.cca.service.ccadmin.util;import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.write.handler.AbstractRowWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import com.ushangxie.cca.lib.ccadmin.api.domain.dto.easyExcel.CommentModel;
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;/*** 自定义批注处理器** @author 刘俊秦* @date 2022/07/12*/
public class CommentWriteHandler extends AbstractRowWriteHandler {/*** sheet页名称列表*/private List<String> sheetNameList;List<CommentModel> commentList = new ArrayList<>();/*** 自定义批注适配器构造方法** @param commentList 批注信息* @param extension   文件后缀(xlsx、xls)*/public CommentWriteHandler(List<CommentModel> commentList, String extension) {if (CollUtil.isEmpty(commentList)) {return;}//文件不为指定的格式时,默认为Xlsxif (!StrUtil.equals(extension, "xlsx") && !StrUtil.equals(extension, "xls")) {extension = "xlsx";}this.commentList = commentList.stream().filter(x ->StrUtil.isNotBlank(x.getSheetName()) && x.getColIndex() >=0 && x.getRowIndex() >= 0 && StrUtil.isNotBlank(x.getCommentContent())).collect(Collectors.toList());sheetNameList = this.commentList.stream().map(x -> x.getSheetName()).distinct().collect(Collectors.toList());this.extension = extension;}/*** 文档后缀名*/private String extension;@Overridepublic void afterRowDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row,Integer relativeRowIndex, Boolean isHead) {Sheet sheet = writeSheetHolder.getSheet();//不需要添加批注,或者当前sheet页不需要添加批注if (CollUtil.isEmpty(commentList) || sheetNameList.contains(sheet.getSheetName()) == false) {return;}//获取当前行的批注信息List<CommentModel> rowCommentList = commentList.stream().filter(x ->StrUtil.equals(x.getSheetName(), sheet.getSheetName())&& EqualsUtilEquals(relativeRowIndex, x.getRowIndex())).collect(Collectors.toList());//当前行没有批注信息if (CollUtil.isEmpty(rowCommentList)) {return;}List<Integer> colIndexList = rowCommentList.stream().map(x -> x.getColIndex()).distinct().collect(Collectors.toList());for (Integer colIndex : colIndexList) {//同一单元格的批注信息List<CommentModel> cellCommentList = rowCommentList.stream().filter(x ->EqualsUtilEquals(colIndex, x.getColIndex())).collect(Collectors.toList());if (CollUtil.isEmpty(cellCommentList)) {continue;}//批注内容拼成一条String commentContent = cellCommentList.stream().map(x -> x.getCommentContent()).collect(Collectors.joining());Cell cell = row.getCell(colIndex);POIUtilAddComment(cell, commentContent, extension);}//删除批注信息commentList.remove(rowCommentList);//重新获取要添加的sheet页姓名sheetNameList = commentList.stream().map(x -> x.getSheetName()).distinct().collect(Collectors.toList());}/*** 判断相等** @param num1* @param num2* @return true相等,false不相等*/public static boolean EqualsUtilEquals(Object num1, Object num2) {if (num1 == null && num2 == null) {return true;}if (num1 == null || num2 == null) {return false;}//==比较比equals比较性能更好if (num1 == num2) {return true;}return num1.equals(num2);}/*** 给Cell添加批注** @param cell 单元格* @param value 批注内容* @param extension 扩展名*/public static void POIUtilAddComment(Cell cell, String value, String extension) {Sheet sheet = cell.getSheet();cell.removeCellComment();if ("xls".equals(extension)) {ClientAnchor anchor = new HSSFClientAnchor();// 关键修改anchor.setDx1(0);anchor.setDx2(0);anchor.setDy1(0);anchor.setDy2(0);anchor.setCol1(cell.getColumnIndex());anchor.setRow1(cell.getRowIndex());anchor.setCol2(cell.getColumnIndex() + 5);anchor.setRow2(cell.getRowIndex() + 6);// 结束Drawing drawing = sheet.createDrawingPatriarch();Comment comment = drawing.createCellComment(anchor);// 输入批注信息comment.setString(new HSSFRichTextString(value));// 将批注添加到单元格对象中cell.setCellComment(comment);} else if ("xlsx".equals(extension)) {ClientAnchor anchor = new XSSFClientAnchor();// 关键修改anchor.setDx1(0);anchor.setDx2(0);anchor.setDy1(0);anchor.setDy2(0);anchor.setCol1(cell.getColumnIndex());anchor.setRow1(cell.getRowIndex());anchor.setCol2(cell.getColumnIndex() + 5);anchor.setRow2(cell.getRowIndex() + 6);// 结束Drawing drawing = sheet.createDrawingPatriarch();Comment comment = drawing.createCellComment(anchor);// 输入批注信息comment.setString(new XSSFRichTextString(value));// 将批注添加到单元格对象中cell.setCellComment(comment);}}}

easyexcel的使用-个人笔记相关推荐

  1. EasyExcel和POI学习笔记

    EasyExcel和POI使用详解 一.Poi-Excel 写 1.常规入门 POI是Apache软件基金会的,POI为"Poor Obfuscation Implementation&qu ...

  2. EasyExcel 学习笔记 - 读Excel

    EasyExcel 学习笔记 - 读Excel pom.xml 添加依赖 测试数据 实体类 自定义转换器 最简单的读 写法1 写法2 写法3 写法4 多行头(跳过N行) 读多个sheet 读全部 sh ...

  3. EasyExcel学习笔记——本地excel的导入导出、Web端excel的导入导出

    EasyExcel学习笔记 EasyExcel 用于 Java解析.生成Excel,是一个基于Java的简单.省内存的读写Excel的开源项目.在尽可能节约内存的情况下支持读写百M的Excel. 官方 ...

  4. EasyExcel(笔记)

    常用场景 1.将用户信息导出为excel表格(导出数据-) 2.将Excel表中的信息录入到网站数据库(习题上传-) 开发中经常会设计到excel的处理,如导出Excel,导入Excel到数据库中! ...

  5. EasyExcel学习笔记

    一.初识EasyExcel 1. Apache POI 有过报表导入导出经验的同学,应该有听说或使用过POI. Apache POI是Apache软件基金会的开源函式库,提供跨平台的Java API实 ...

  6. poi和easyExcel基于Java操作Excel学习笔记

    1 学习前言 Excel和读写和文件的读写没有本质的区别,都是属于IO操作,我们使用原生的IO就能解决Excel的导入和导出,当然操作起来比较麻烦,性能也不高,这次我们就学习poi和easyExcel ...

  7. 谷粒学院项目笔记6——oss、EasyExcel、课程分类、nginx

    尚硅谷谷粒学院项目第六天内容之对象存储oss服务.使用EasyExcel添加课程分类功能.课程列表分类.ningx的使用 对象存储oss 打开阿里云官网--对象存储--oss管理控制台 创建bucke ...

  8. 学习EasyExcel实现excel文件的批量上传的笔记

    参考官网上的内容 ​ 官网地址如下: ​ https://yuque.com/easyexcel ​ git地址: ​ https://gitcode.net/mirrors/alibaba/easy ...

  9. 【笔记】Spring整合EasyExcel

    EasyExcel EasyExcel 由五部分组成,分别是配置读取类(EasyExcelHalper).导出Excel类(EasyExcelExportUtil).导入Excel类(EasyExce ...

最新文章

  1. Atlas study:使用Accordion实现页面多个块状区域的显隐
  2. idea springBoot 配置devtools实现热部署
  3. php搜索数据库设计,PHP数据库搜索功能设计
  4. c语言冒泡排序法程序填空_【C语言】两种方式实现冒泡排序算法
  5. java runtime类 heap_Java 进阶(一) JVM运行时内存模型
  6. 计算机网络之数据链路层:6、后退N帧协议(GBN)
  7. app分发源码_第三方苹果企业签名源码
  8. [物理学与PDEs]第2章第4节 激波 4.2 熵条件
  9. Java Json字符串或Json对象属性查找工具类
  10. C语言实验报告册中级进步,C语言实验报告册
  11. 三星S7edge番茄花园ROM
  12. 【BBF系列协议】TR104 VoIP CPE的配置参数
  13. 【爬虫进行时】手机客户端app爬虫抓包(Fiddler)
  14. word制作员工手册教学
  15. WinPE下安装ISO格式Win系统
  16. 星期五计算机,黑色星期五之夜电脑人
  17. 你了解kafka的Reblance机制吗?
  18. 集训二报告:简易电子秤1
  19. python中enumerate()函数
  20. 4. coding=utf-8 的作用

热门文章

  1. 如何自学黑客?自学黑客技术需要学多久?
  2. 联想电脑计算机无法正常启动怎么办,电脑蓝屏无法启动怎么办
  3. C++判断素数(求素数)
  4. CPU使用率达到100%
  5. python爬虫------从丁香园疫情首页提取世界各国的疫情数据
  6. Chatbot 聊天机器人页面交互设计
  7. #java #web jsp开发入门(web应用概述、tomcat简介、编写步骤)
  8. python与数据分析结合_将Python和R整合进一个数据分析流程
  9. 正确使用数字化仪前端信号调理功能
  10. H264学习笔记(1):视频压缩编码的基本原理