diff --git a/hutool-poi/src/main/java/org/dromara/hutool/poi/excel/ExcelWriter.java b/hutool-poi/src/main/java/org/dromara/hutool/poi/excel/ExcelWriter.java index bf43073f9..e6bcc5723 100644 --- a/hutool-poi/src/main/java/org/dromara/hutool/poi/excel/ExcelWriter.java +++ b/hutool-poi/src/main/java/org/dromara/hutool/poi/excel/ExcelWriter.java @@ -14,8 +14,10 @@ package org.dromara.hutool.poi.excel; import org.apache.poi.common.usermodel.Hyperlink; import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddressList; import org.apache.poi.xssf.usermodel.XSSFDataValidation; +import org.apache.poi.xssf.usermodel.XSSFSheet; import org.dromara.hutool.core.bean.BeanUtil; import org.dromara.hutool.core.collection.ListUtil; import org.dromara.hutool.core.comparator.IndexedComparator; @@ -561,6 +563,26 @@ public class ExcelWriter extends ExcelBase { return this; } + /** + * 设置忽略错误,即Excel中的绿色警告小标,只支持XSSFSheet
+ * 见:https://stackoverflow.com/questions/23488221/how-to-remove-warning-in-excel-using-apache-poi-in-java + * + * @param cellRangeAddress 指定单元格范围 + * @param ignoredErrorTypes 忽略的错误类型列表 + * @return this + * @throws UnsupportedOperationException 如果sheet不是XSSFSheet + * @since 5.8.28 + */ + public ExcelWriter addIgnoredErrors(final CellRangeAddress cellRangeAddress, final IgnoredErrorType... ignoredErrorTypes) throws UnsupportedOperationException { + final Sheet sheet = this.sheet; + if (sheet instanceof XSSFSheet) { + ((XSSFSheet) sheet).addIgnoredErrors(cellRangeAddress, ignoredErrorTypes); + return this; + } + + throw new UnsupportedOperationException("Only XSSFSheet supports addIgnoredErrors"); + } + /** * 增加下拉列表 *