From 3ca8babb8481fa9a330ce1a585f87f200dae1b5e Mon Sep 17 00:00:00 2001 From: Looly Date: Wed, 8 May 2024 16:56:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0ExcelWriter.addIgnoredErrors?= =?UTF-8?q?=EF=BC=8C=E6=94=AF=E6=8C=81=E5=BF=BD=E7=95=A5=E8=AD=A6=E5=91=8A?= =?UTF-8?q?=E5=B0=8F=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dromara/hutool/poi/excel/ExcelWriter.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) 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"); + } + /** * 增加下拉列表 *