zoukankan      html  css  js  c++  java
  • 完美解决POI写批注报错comments in one cell are not allowed, cell....问题

    解决方案:

    示例代码如下:

      /**
         * 给某一格设置注释
         * @param sheet
         * @param rowIndex
         * @param colIndex
         * @param value
         */
        public static void setCellCommon(Sheet sheet, int rowIndex, int colIndex, String value) {
            Row row = sheet.getRow(rowIndex);
            if (row == null) {
    //            log.debug(ExcelConfig.ERROR + " setCellCommon," + sheet.getSheetName() + "第" + rowIndex + "为NULL");
                return;
            }
            Cell cell = row.getCell(colIndex);
            if (cell == null) {
                cell = row.createCell(colIndex);
            }
            if(value == null){
                cell.removeCellComment();
                return;
            }
            Drawing drawing = sheet.createDrawingPatriarch();
            CreationHelper factory = sheet.getWorkbook().getCreationHelper();
            ClientAnchor anchor = factory.createClientAnchor();
    
            //(int dx1, int dy1, int dx2, int dy2, short col1, int row1, short col2, int row2)
            //前四个参数是坐标点,后四个参数是编辑和显示批注时的大小.
            //以上参数不设置时会有默认值,当一个被重复设置批注时会报错Multiple cell comments in one cell are not allowed
            //故在设置批注前检查锚点位置有无批注,有的话移除
            Row row1 = sheet.getRow(anchor.getRow1());
            if(row1 != null){
                Cell cell1 = row1.getCell(anchor.getCol1());
                if(cell1 != null){
                    cell1.removeCellComment();
                }
            }
    
            Comment comment = drawing.createCellComment(anchor);
            RichTextString str = factory.createRichTextString(value);
            comment.setString(str);
            comment.setAuthor("Auto+");
            cell.setCellComment(comment);
        }

    优秀不够,你是否无可替代

    软件测试交流QQ群:721256703,期待你的加入!!

    欢迎关注我的微信公众号:软件测试君


  • 相关阅读:
    ubuntu下php-fpm多实例运行配置
    ubuntu下nginx+PHP-FPM安装配置
    php中include_path配置
    laravel中的队列
    laravel权限控制Gate
    Configuring an NVIDIA Jetson TX2
    NVIDIA Jetson TX2 の設定
    3-Jetson Nano Developer KitでAWS IoT GreengrassのML Inferenceを試す(GPU編)
    2-Jetson Nano Developer KitでAWS IoT GreengrassのML Inferenceを試す
    1-Jetson Nano Developer KitでAWS IoT Greengrassを動かしてみる
  • 原文地址:https://www.cnblogs.com/longronglang/p/13628293.html
Copyright © 2011-2022 走看看