增加ExcelWriter.addIgnoredErrors,支持忽略警告小标

This commit is contained in:
Looly 2024-05-08 16:56:52 +08:00
parent 0b7133a185
commit 3ca8babb84

View File

@ -14,8 +14,10 @@ package org.dromara.hutool.poi.excel;
import org.apache.poi.common.usermodel.Hyperlink; import org.apache.poi.common.usermodel.Hyperlink;
import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList; import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.xssf.usermodel.XSSFDataValidation; 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.bean.BeanUtil;
import org.dromara.hutool.core.collection.ListUtil; import org.dromara.hutool.core.collection.ListUtil;
import org.dromara.hutool.core.comparator.IndexedComparator; import org.dromara.hutool.core.comparator.IndexedComparator;
@ -561,6 +563,26 @@ public class ExcelWriter extends ExcelBase<ExcelWriter> {
return this; return this;
} }
/**
* 设置忽略错误即Excel中的绿色警告小标只支持XSSFSheet<br>
* 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");
}
/** /**
* 增加下拉列表 * 增加下拉列表
* *