如何在 JAVA 中使用 apache poi 在 Excel 中删除警告? [英] How to remove warning in Excel using apache poi in JAVA?

查看:50
本文介绍了如何在 JAVA 中使用 apache poi 在 Excel 中删除警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 apache poi api 在我的 Java 应用程序中生成 Excel 工作表.excel 中设置的数据以字符串类型动态传入.对于 column1,值为字母数字.当我生成 Excel 时,它会给我绿色指示,并在单元格上显示警告数字存储为文本"带有 2 位数年份的文本日期".

I am using apache poi api to generate Excel sheet in my application in java. Data that are set in excel are coming dynamically with type string. For column1, values are alphanumeric. When I generate Excel, it will give me green indication with warning "Number Stored as Text" or "Text date with 2-digit year" on cell.

我想删除那个警告.我发现从 excel 中我们可以将单元格标记为忽略错误",以忽略警告.

I want to remove that warning. I found that from excel we can flag a cell as 'ignore error', to ignore the warning.

如何以编程方式完成此任务或是否有其他替代方法来完成此任务?

How to do it programmatically or is there any other alternative to achieve this task ?

我还附上了用绿色标记显示警告的屏幕截图.

I also have attached screenshot that shows warning with green mark.

代码:

if (cellValue != null && (shouldBeRightAlign))
{
 cellType = Cell.CELL_TYPE_NUMERIC;
}
else if (cellValue != null)
{
 cellType = Cell.CELL_TYPE_STRING;
}
cell.setCellValue(cellValue);

推荐答案

API 现在提供了相应的方法

public void addIgnoredErrors(CellRangeAddress region,
                    IgnoredErrorType... ignoredErrorTypes)

这篇关于如何在 JAVA 中使用 apache poi 在 Excel 中删除警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆