缺少 Apache POI Java 的单元格策略 [英] Missing cell policy of Apache POI Java

查看:32
本文介绍了缺少 Apache POI Java 的单元格策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释一下 Apache POIMissing cell policy 吗?究竟什么是缺失的细胞?我没有找到 Apache POI 文档 link 是不言自明的到底缺少什么单元格.

Can somebody please explain about the Missing cell policy of Apache POI ? What are exactly missing cells ? I didn't find the Apache POI docs link to be self-explanatory on what exactly are missing cells.

推荐答案

您是否阅读了 Apache POI Excel 繁忙开发者指南?

在某些情况下,在迭代时,您需要完全控制缺失或空白行和单元格的处理方式,并且您需要确保访问每个单元格,而不仅仅是文件中定义的单元格.(CellIterator 将只返回文件中定义的单元格,这些单元格主要是具有值或样式的单元格,但它取决于 Excel).

In some cases, when iterating, you need full control over how missing or blank rows and cells are treated, and you need to ensure you visit every cell and not just those defined in the file. (The CellIterator will only return the cells defined in the file, which is largely those with values or stylings, but it depends on Excel).

在这种情况下,您应该获取一行的第一列和最后一列信息,然后调用 getCell(int, MissingCellPolicy) 来获取单元格.使用 MissingCellPolicy 控制空白或空单元格的处理方式.

In cases such as these, you should fetch the first and last column information for a row, then call getCell(int, MissingCellPolicy) to fetch the cell. Use a MissingCellPolicy to control how blank or null cells are handled.

如果您在一行中迭代列,一些空白的单元格甚至可能不存在,这可能导致毫无戒心的代码抛出 NullPointerException.MissingCellPolicy,当传递给 getCell 时,会引导和简化告诉 Apache POI 如何处理这些类型单元格的代码.

If you're iterating over columns in a row, some cells that are blank may not even exist, which may causing unsuspecting code to throw a NullPointerException. A MissingCellPolicy, when passed to getCell, guides and simplifies code that tells Apache POI how to handle these kinds of cells.

  • CREATE_NULL_AS_BLANK - 如果返回的Cell 不存在,而不是返回null,创建一个新的Cell,单元格类型为blank".这可以帮助方便地避免 NullPointerException.
  • RETURN_BLANK_AS_NULL - 即使如果单元格存在但单元格类型为空白",则返回 null.这可以让您忽略容易存在的空白单元格.
  • RETURN_NULL_AND_BLANK - 不要t 修改现有结构;对于不存在的单元格返回 null 并返回空白 Cell 如果它存在但其单元格类型为空白.这是 getCell 重载,不需要 MissingCellPolicy.
  • CREATE_NULL_AS_BLANK - If the Cell returned doesn't exist, instead of returning null, create a new Cell with a cell type of "blank". This can help avoid NullPointerExceptions conveniently.
  • RETURN_BLANK_AS_NULL - Even if the cell exists but has a cell type of "blank", return null. This can allow you ignore blank cells that do exist easily.
  • RETURN_NULL_AND_BLANK - Don't modify the existing structure; return null for cells that don't really exist and return the blank Cell if it exists but its cell type is blank. This is the behavior of the getCell overload that doesn't take a MissingCellPolicy.

这篇关于缺少 Apache POI Java 的单元格策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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