gpt4 book ai didi

java - 使用 Apache poi 和电子邮件验证生成 excel 工作表

转载 作者:行者123 更新时间:2023-12-02 04:34:56 24 4
gpt4 key购买 nike

我正在使用 apache poi 生成电子邮件的 Excel 工作表——这意味着生成 Excel 后,如果用户在单元格中输入电子邮件,我需要验证该电子邮件

下面是我的代码

DVConstraint EmailConstraint=null;
DataValidation EmaildataValidation =null;

EmailConstraint=DVConstraint.createCustomFormulaConstraint("AND(FIND("+'@'+",$A$2),FIND(.,$A$2),ISERROR(FIND( ,$A$2)))");---->getting error here only

EmaildataValidation =dataValidationHelper.createValidation(EmailConstraint, addressList1);
EmaildataValidation.setSuppressDropDownArrow(false);
sheet.addValidationData(EmaildataValidation);

当我执行此方法时,我收到以下错误

Stacktrace:] with root cause
org.apache.poi.ss.formula.FormulaParseException: Parse error near char 9 '@' in specified formula 'AND(FIND(@,$A$2),FIND(.,$A$2),ISERROR(FIND( ,$A$2)))'. Expected cell ref or constant literal
at org.apache.poi.ss.formula.FormulaParser.expected(FormulaParser.java:188)
at org.apache.poi.ss.formula.FormulaParser.parseSimpleFactor(FormulaParser.java:1128)
at org.apache.poi.ss.formula.FormulaParser.percentFactor(FormulaParser.java:1083)
at org.apache.poi.ss.formula.FormulaParser.powerFactor(FormulaParser.java:1070)
at org.apache.poi.ss.formula.FormulaParser.Term(FormulaParser.java:1430)
at org.apache.poi.ss.formula.FormulaParser.additiveExpression(FormulaParser.java:1530)
at org.apache.poi.ss.formula.FormulaParser.concatExpression(FormulaParser.java:1514)
at org.apache.poi.ss.formula.FormulaParser.comparisonExpression(FormulaParser.java:1471)
at org.apache.poi.ss.formula.FormulaParser.Arguments(FormulaParser.java:1056)
at org.apache.poi.ss.formula.FormulaParser.function(FormulaParser.java:943)
at org.apache.poi.ss.formula.FormulaParser.parseNonRange(FormulaParser.java:536)
at org.apache.poi.ss.formula.FormulaParser.parseRangeable(FormulaParser.java:416)
at org.apache.poi.ss.formula.FormulaParser.parseRangeExpression(FormulaParser.java:237)
at org.apache.poi.ss.formula.FormulaParser.parseSimpleFactor(FormulaParser.java:1123)
at org.apache.poi.ss.formula.FormulaParser.percentFactor(FormulaParser.java:1083)
at org.apache.poi.ss.formula.FormulaParser.powerFactor(FormulaParser.java:1070)
at org.apache.poi.ss.formula.FormulaParser.Term(FormulaParser.java:1430)
at org.apache.poi.ss.formula.FormulaParser.additiveExpression(FormulaParser.java:1530)
at org.apache.poi.ss.formula.FormulaParser.concatExpression(FormulaParser.java:1514)
at org.apache.poi.ss.formula.FormulaParser.comparisonExpression(FormulaParser.java:1471)
at org.apache.poi.ss.formula.FormulaParser.Arguments(FormulaParser.java:1056)
at org.apache.poi.ss.formula.FormulaParser.function(FormulaParser.java:943)
at org.apache.poi.ss.formula.FormulaParser.parseNonRange(FormulaParser.java:536)
at org.apache.poi.ss.formula.FormulaParser.parseRangeable(FormulaParser.java:416)
at org.apache.poi.ss.formula.FormulaParser.parseRangeExpression(FormulaParser.java:237)
at org.apache.poi.ss.formula.FormulaParser.parseSimpleFactor(FormulaParser.java:1123)
at org.apache.poi.ss.formula.FormulaParser.percentFactor(FormulaParser.java:1083)
at org.apache.poi.ss.formula.FormulaParser.powerFactor(FormulaParser.java:1070)

我尝试了很多,但没能做到。

最佳答案

查找函数的第一个参数是字符串,因此必须用引号引起来。寻找(”@”,..在java中,您可以在公式之间使用转义字符串字符。

关于java - 使用 Apache poi 和电子邮件验证生成 excel 工作表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30950543/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com