POI 给单元格添加批注
图中红框框是处理单元格内容和批注的地方。
参考:https://blog.csdn.net/qq_38974638/article/details/114837631
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | //SXSSFWorkbook public static void createExcelMergeSetCellColor1(SXSSFWorkbook workbook, SXSSFSheet sheet, String title, final String[] headers, List<List<String>> dataset, boolean isSortDataSet, final Integer[] mergeBasis, final Integer[] mergeCells, final Integer[] sumCells, final Integer[] timeCells) { sheet.setDefaultColumnWidth( 15 ); // 设置表格默认列宽度为15个字节 sheet.setDefaultRowHeight(( short ) 20 ); sheet.setDefaultRowHeightInPoints( 20 ); CellStyle headStyle = createHeadStyle(workbook); // 生成头部样式 CellStyle commonDataStyle = createCommonDataStyle(workbook); // 生成一般数据样式 commonDataStyle.setWrapText( true ); CellStyle commonDataStyleRed = createCommonDataStyleRed(workbook); //生成红色文本样式 commonDataStyleRed.setWrapText( true ); CellStyle numStyle = createNumStyle(workbook); //生成数字类型保留两位小数样式 CellStyle sumRowStyle = createSumRowStyle(workbook); //生成合计行样式 if (headers == null || headers.length <= 0 ) { return ; } SXSSFDrawing drawing = sheet.createDrawingPatriarch(); SXSSFRow row = sheet.createRow( 0 ); // 产生表格标题行 row.setHeightInPoints( 30 ); //标题行的行高为25 for ( int index = 0 ; index < headers.length; index++) { SXSSFCell cell = row.createCell(index); cell.setCellStyle(headStyle); XSSFRichTextString text = new XSSFRichTextString(headers[index]); cell.setCellValue(text); String str = text.toString(); if (str.contains( "雇员唯一号" ) || str.contains( "雇员姓名" ) || str.contains( "证件号" ) || str.contains( "缴金地" ) || str.contains( "社保额" )) { Comment comment = drawing.createCellComment( new XSSFClientAnchor( 0 , 0 , 0 , 0 , cell.getColumnIndex(), cell.getRowIndex(), cell.getColumnIndex() + 5 , cell.getRowIndex() + 6 )); comment.setString( new XSSFRichTextString( "必填项" )); cell.setCellComment(comment); } else if (str.contains( "证件类型" )) { Comment comment = drawing.createCellComment( new XSSFClientAnchor( 0 , 0 , 0 , 0 , cell.getColumnIndex(), cell.getRowIndex(), cell.getColumnIndex() + 5 , cell.getRowIndex() + 6 )); comment.setString( new XSSFRichTextString( "必填项,证件类型只支持 身份证" )); cell.setCellComment(comment); } else if (str.contains( "账单年月" )) { Comment comment = drawing.createCellComment( new XSSFClientAnchor( 0 , 0 , 0 , 0 , cell.getColumnIndex(), cell.getRowIndex(), cell.getColumnIndex() + 5 , cell.getRowIndex() + 6 )); comment.setString( new XSSFRichTextString( "必填项,日期格式:\n" + "202109\n" )); cell.setCellComment(comment); } } // 遍历集合数据,产生数据行 Iterator<List<String>> it = dataset.iterator(); int index = 0 ; while (it.hasNext()) { index++; row = sheet.createRow(index); row.setHeightInPoints( 20 ); //一般数据的行高为20 List<String> dataSources = it.next(); for ( int i = 0 ; i < dataSources.size(); i++) { SXSSFCell cell = row.createCell(i); cell.setCellStyle(commonDataStyle); cell.setCellValue(dataSources.get(i)); } } } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)