mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
增加ExcelWriter.addIgnoredErrors,支持忽略警告小标
This commit is contained in:
parent
f8dbf66bc9
commit
bee80f3d14
@ -2,7 +2,7 @@
|
|||||||
# 🚀Changelog
|
# 🚀Changelog
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.28(2024-05-06)
|
# 5.8.28(2024-05-08)
|
||||||
|
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
* 【core 】 修正XmlUtil的omitXmlDeclaration描述注释(issue#I9CPC7@Gitee)
|
* 【core 】 修正XmlUtil的omitXmlDeclaration描述注释(issue#I9CPC7@Gitee)
|
||||||
@ -15,6 +15,7 @@
|
|||||||
* 【captcha】 Captcha.setBackground为null时背景透明(issue#3558@Github)
|
* 【captcha】 Captcha.setBackground为null时背景透明(issue#3558@Github)
|
||||||
* 【captcha】 HttpDownloader.downloadBytes增加超时参数重载(issue#3556@Github)
|
* 【captcha】 HttpDownloader.downloadBytes增加超时参数重载(issue#3556@Github)
|
||||||
* 【http 】 增加ExceptionFilter和DefaultExceptionFilter支持异常处理(issue#3568@Github)
|
* 【http 】 增加ExceptionFilter和DefaultExceptionFilter支持异常处理(issue#3568@Github)
|
||||||
|
* 【poi 】 增加ExcelWriter.addIgnoredErrors,支持忽略警告小标
|
||||||
|
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【http 】 修复HttpUtil.urlWithFormUrlEncoded方法重复编码问题(issue#3536@Github)
|
* 【http 】 修复HttpUtil.urlWithFormUrlEncoded方法重复编码问题(issue#3536@Github)
|
||||||
|
@ -20,20 +20,11 @@ import cn.hutool.poi.excel.cell.CellLocation;
|
|||||||
import cn.hutool.poi.excel.cell.CellUtil;
|
import cn.hutool.poi.excel.cell.CellUtil;
|
||||||
import cn.hutool.poi.excel.style.Align;
|
import cn.hutool.poi.excel.style.Align;
|
||||||
import org.apache.poi.common.usermodel.Hyperlink;
|
import org.apache.poi.common.usermodel.Hyperlink;
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
import org.apache.poi.ss.usermodel.*;
|
||||||
import org.apache.poi.ss.usermodel.CellStyle;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
import org.apache.poi.ss.usermodel.ClientAnchor;
|
|
||||||
import org.apache.poi.ss.usermodel.DataValidation;
|
|
||||||
import org.apache.poi.ss.usermodel.DataValidationConstraint;
|
|
||||||
import org.apache.poi.ss.usermodel.DataValidationHelper;
|
|
||||||
import org.apache.poi.ss.usermodel.Drawing;
|
|
||||||
import org.apache.poi.ss.usermodel.Font;
|
|
||||||
import org.apache.poi.ss.usermodel.HeaderFooter;
|
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
|
||||||
import org.apache.poi.ss.usermodel.Sheet;
|
|
||||||
import org.apache.poi.ss.usermodel.Workbook;
|
|
||||||
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 java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -591,6 +582,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");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 增加下拉列表
|
* 增加下拉列表
|
||||||
*
|
*
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
package cn.hutool.poi.excel;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.ListUtil;
|
||||||
|
import org.apache.poi.ss.usermodel.BuiltinFormats;
|
||||||
|
import org.apache.poi.ss.usermodel.CellStyle;
|
||||||
|
import org.apache.poi.ss.usermodel.IgnoredErrorType;
|
||||||
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||||
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class WriteNumberToStringTest {
|
||||||
|
@Test
|
||||||
|
@Ignore
|
||||||
|
public void writeNumberTest() {
|
||||||
|
final ExcelWriter writer = ExcelUtil.getWriter("d:/test/dataWithNumber.xlsx");
|
||||||
|
final XSSFSheet sheet = (XSSFSheet) writer.getSheet();
|
||||||
|
sheet.addIgnoredErrors(new CellRangeAddress(0, 100, 0, 100), IgnoredErrorType.NUMBER_STORED_AS_TEXT);
|
||||||
|
final CellStyle cellStyle = writer.getStyleSet().getCellStyle();
|
||||||
|
cellStyle.setDataFormat((short) BuiltinFormats.getBuiltinFormat("TEXT"));
|
||||||
|
|
||||||
|
writer.writeRow(ListUtil.of("姓名", "编号"));
|
||||||
|
writer.writeRow(ListUtil.of("张三", "010001"));
|
||||||
|
writer.writeRow(ListUtil.of("李四", "120001"));
|
||||||
|
writer.writeRow(ListUtil.of("王五", 123456));
|
||||||
|
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user