alibaba / easyexcel

快速、简洁、解决大文件内存溢出的java处理Excel工具
https://easyexcel.opensource.alibaba.com
Apache License 2.0
32.09k stars 7.5k forks source link

是否支持设置单元格公式 #3903

Open sduqlsc opened 2 months ago

sduqlsc commented 2 months ago

建议先去看文档

快速开始常见问题

异常代码

       public static class NumericValidationWriteHandler implements SheetWriteHandler {
        private final int firstCol, lastCol;

        public NumericValidationWriteHandler(int firstCol, int lastCol) {
            this.firstCol = firstCol;
            this.lastCol = lastCol;
        }

        @Override
        public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {
            Sheet sheet = writeSheetHolder.getSheet();
            DataValidationHelper helper = sheet.getDataValidationHelper();
            CellRangeAddressList addressList = new CellRangeAddressList(1, 65535, firstCol, lastCol);
            DataValidationConstraint constraint = helper.createCustomConstraint("ISNUMBER(A1)");
            DataValidation dataValidation = helper.createValidation(constraint, addressList);
            dataValidation.setErrorStyle(DataValidation.ErrorStyle.STOP);
            dataValidation.setShowErrorBox(true);
            dataValidation.createErrorBox("错误:", "赋值属性只能为数字");
            sheet.addValidationData(dataValidation);
        }
    }

sheet.setCustomWriteHandlerList(Lists.newArrayList(
  new EasyExcelExportExample.NumericValidationWriteHandler(1, 1),
   new EasyExcelExportExample.NumericValidationWriteHandler(3, 3)
 ));

异常提示

大家尽量把问题一次性描述清楚,然后贴上全部异常,这样方便把问题一次性解决掉。 至少大家要符合一个原则就是,能让其他人复现出这个问题,如果无法复现,肯定无法解决。

问题描述

设置所有行的单元格公式为数字,但是只有前两行可以,但是即使输入数字也报错。所以想问一下是否支持,还是只能用poi本身的功能?