zoukankan      html  css  js  c++  java
  • POI 给单元格添加批注

     图中红框框是处理单元格内容和批注的地方。

    参考:https://blog.csdn.net/qq_38974638/article/details/114837631

    //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));
                }
            }
    
        }
    
  • 相关阅读:
    phpmyadmin和网页上面的乱码问题
    整理: Android HAL
    warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]-给char* 形参 传入 宏定义字符串
    ubuntu 输入法莫名其妙变繁体
    linux内核版本号添加字符/为何有时会自动添加“+”号以及怎么去掉
    Unable to handle kernel NULL pointer dereference at virtual address 00000000
    Ubuntu 18.04 安装 Samba 服务器及配置
    linux查看版本信息
    图解:电压掉电监测电路如何实现检测工作?
    精密全波整流+一阶RC滤波器检测市电电压
  • 原文地址:https://www.cnblogs.com/qq1445496485/p/15622664.html
Copyright © 2011-2022 走看看