public class Row extends Object
Cell,无论是获取单元格的数据还是样式都是通过本类实现,
Cell对象并不提供任何获取信息的方法,Row除了提供最原始的getInt(int),getString(int)
等方法外还能调用to(java.lang.Class<T>)和too(java.lang.Class<T>)方法将行转为指定对象,to方法和too的区别在于前者每一行都会
创建一个独立的对象而后者是内存共享的,如果需要使用数组或集合类收集对象则需要使用to方法,流式one-by-one的场景建议
使用too方法。
使用to和too方法转对象都有一个前提,那就是所转对象的属性或set方法必须使用ExcelColumn注解,
通过表头行上的文本与@ExcelColumn注解的value值进行匹配,如果使用Sheet.forceImport()强制匹配时
无@ExcelColumn注解的字段将会按照字段名进行匹配,除了按照表头文本匹配外还支持列索引匹配
少量数据也可以使用toMap()方法将行数据转为字典类型,为了保证列顺序返回的Map方法为LinkedHashMap,
字典的Key为表头文本,Value为单元格的值,多行表头按照行1:行2进行拼接,参考Sheet.getHeader()文档。
Row还提供了isEmpty()和isBlank()两个空判断以及getFirstColumnIndex()和getLastColumnIndex()
两个列索引方法。isEmpty仅判断单元格起始下标是否小于结束下标,至于单元格里是否有值或样式则不在判断之内,isBlank则会
判断每个单元格的值是否为blank,blank的标准为字符串null或“”其余类型null
| 限定符和类型 | 字段和说明 |
|---|---|
protected Cell[] |
cells |
protected int |
fc |
protected HeaderRow |
hr |
protected int |
index |
protected int |
lc |
protected org.slf4j.Logger |
LOGGER |
protected SharedStrings |
sst
The Shared String Table
|
protected Styles |
styles
The global styles
|
protected boolean |
unknownLength |
| 构造器和说明 |
|---|
Row() |
| 限定符和类型 | 方法和说明 |
|---|---|
HeaderRow |
asHeader()
将当前行转为表头行
|
Cell[] |
copyCells()
Returns deep clone cells
|
Cell[] |
copyCells(int newLength)
Returns deep clone cells
|
<T> T |
geet()
使用
Sheet.bind(java.lang.Class<?>)方法绑定类型后,使用此方法将整行数据转为指定类型<T>,与get()的区别在于
本方法返回的对象是内存共享的(只有一个对象副本) |
<T> T |
get()
使用
Sheet.bind(java.lang.Class<?>)方法绑定类型后,使用此方法将整行数据转为指定类型<T> |
Boolean |
getBoolean(Cell c)
获取单元格的值并转为
Boolean类型,对于非布尔类型则兼容C语言的bool判断 |
Boolean |
getBoolean(int columnIndex)
获取单元格的值并转为
Boolean类型,对于非布尔类型则兼容C语言的bool判断 |
Boolean |
getBoolean(String columnName)
获取单元格的值并转为
Boolean类型,对于非布尔类型则兼容C语言的bool判断 |
Byte |
getByte(Cell c)
获取单元格的值并转为
Byte类型 |
Byte |
getByte(int columnIndex)
获取单元格的值并转为
Byte类型 |
Byte |
getByte(String columnName)
获取单元格的值并转为
Byte类型 |
Cell |
getCell(int i)
获取单元格
Cell,获取到单元格后可用于后续取值或样式 |
Cell |
getCell(String name)
获取单元格
Cell,获取到单元格后可用于后续取值或样式,如果查找不到时则返回一个空的单元格 |
int |
getCellStyle(Cell c)
获取单元格样式值,可以拿此返回值调用
Styles.getBorder(int)等方法获取具体的样式 |
int |
getCellStyle(int columnIndex)
获取单元格样式值,可以拿此返回值调用
Styles.getBorder(int)等方法获取具体的样式 |
int |
getCellStyle(String columnName)
获取单元格样式值,可以拿此返回值调用
Styles.getBorder(int)等方法获取具体的样式 |
CellType |
getCellType(Cell c)
获取单元格的数据类型
注意:这里仅是一个近似的类型,因为从原始文件中只能获取到
numeric,string,
boolean三种类型。 |
CellType |
getCellType(int columnIndex)
获取单元格的数据类型
注意:这里仅是一个近似的类型,因为从原始文件中只能获取到
numeric,string,
boolean三种类型。 |
CellType |
getCellType(String columnName)
获取单元格的数据类型
注意:这里仅是一个近似的类型,因为从原始文件中只能获取到
numeric,string,
boolean三种类型。 |
Character |
getChar(Cell c)
获取单元格的值并转为
Character类型 |
Character |
getChar(int columnIndex)
获取单元格的值并转为
Character类型 |
Character |
getChar(String columnName)
获取单元格的值并转为
Character类型 |
Date |
getDate(Cell c)
获取单元格的值并转为
java.util.Date类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理 |
Date |
getDate(int columnIndex)
获取单元格的值并转为
java.util.Date类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理 |
Date |
getDate(String columnName)
获取单元格的值并转为
java.util.Date类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理 |
BigDecimal |
getDecimal(Cell c)
获取单元格的值并转为
java.math.BigDecimal类型 |
BigDecimal |
getDecimal(int columnIndex)
获取单元格的值并转为
java.math.BigDecimal类型 |
BigDecimal |
getDecimal(String columnName)
获取单元格的值并转为
java.math.BigDecimal类型 |
Double |
getDouble(Cell c)
获取单元格的值并转为
Double类型 |
Double |
getDouble(int columnIndex)
获取单元格的值并转为
Double类型 |
Double |
getDouble(String columnName)
获取单元格的值并转为
Double类型 |
int |
getFirstColumnIndex()
获取首列下标 (zero base)
|
Float |
getFloat(Cell c)
获取单元格的值并转为
Float类型 |
Float |
getFloat(int columnIndex)
获取单元格的值并转为
Float类型 |
Float |
getFloat(String columnName)
获取单元格的值并转为
Float类型 |
String |
getFormula(Cell cell)
获取单元格的公式
|
String |
getFormula(int columnIndex)
获取单元格的公式
|
String |
getFormula(String columnName)
获取单元格的公式
|
Double |
getHeight()
获取行高,仅
XMLFullRow支持 |
Integer |
getInt(Cell c)
获取单元格的值并转为
Integer类型 |
Integer |
getInt(int columnIndex)
获取单元格的值并转为
Integer类型 |
Integer |
getInt(String columnName)
获取单元格的值并转为
Integer类型 |
int |
getLastColumnIndex()
获取尾列下标 (zero base)
|
LocalDate |
getLocalDate(Cell c)
获取单元格的值并转为
LocalDate类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理 |
LocalDate |
getLocalDate(int columnIndex)
获取单元格的值并转为
LocalDate类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理 |
LocalDate |
getLocalDate(String columnName)
获取单元格的值并转为
LocalDate类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理 |
LocalDateTime |
getLocalDateTime(Cell c)
获取单元格的值并转为
LocalDateTime类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理 |
LocalDateTime |
getLocalDateTime(int columnIndex)
获取单元格的值并转为
LocalDateTime类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理 |
LocalDateTime |
getLocalDateTime(String columnName)
获取单元格的值并转为
LocalDateTime类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理 |
LocalTime |
getLocalTime(Cell c)
获取单元格的值并转为
LocalTime类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理 |
LocalTime |
getLocalTime(int columnIndex)
获取单元格的值并转为
LocalTime类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理 |
LocalTime |
getLocalTime(String columnName)
获取单元格的值并转为
LocalTime类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理 |
Long |
getLong(Cell c)
获取单元格的值并转为
Long类型 |
Long |
getLong(int columnIndex)
获取单元格的值并转为
Long类型 |
Long |
getLong(String columnName)
获取单元格的值并转为
Long类型 |
int |
getRowNum()
获取行号,与你打开Excel文件看到的一样从1开始
|
Short |
getShort(Cell c)
获取单元格的值并转为
Short类型 |
Short |
getShort(int columnIndex)
获取单元格的值并转为
Short类型 |
Short |
getShort(String columnName)
获取单元格的值并转为
Short类型 |
String |
getString(Cell c)
获取单元格的值并转为
String类型 |
String |
getString(int columnIndex)
获取单元格的值并转为
String类型 |
String |
getString(String columnName)
获取单元格的值并转为
String类型 |
Styles |
getStyles()
Returns a global
Styles |
Time |
getTime(Cell c)
获取单元格的值并转为
java.sql.Time类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理 |
Time |
getTime(int columnIndex)
获取单元格的值并转为
java.sql.Time类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理 |
Time |
getTime(String columnName)
获取单元格的值并转为
java.sql.Time类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理 |
Timestamp |
getTimestamp(Cell c)
获取单元格的值并转为
java.sql.Timestamp类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理 |
Timestamp |
getTimestamp(int columnIndex)
获取单元格的值并转为
java.sql.Timestamp类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理 |
Timestamp |
getTimestamp(String columnName)
获取单元格的值并转为
java.sql.Timestamp类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理 |
boolean |
hasFormula(Cell cell)
检查单元格是否包含公式
|
boolean |
hasFormula(int columnIndex)
检查单元格是否包含公式
|
boolean |
hasFormula(String columnName)
检查单元格是否包含公式
|
boolean |
isBlank()
判断单行的所有单元格是否为空,所有单元格无值或空字符串时返回
true |
boolean |
isBlank(Cell c)
判断单元格是否为空值
|
boolean |
isBlank(int columnIndex)
判断单元格是否为空值
|
boolean |
isBlank(String columnName)
判断单元格是否为空值
|
boolean |
isEmpty()
判断单行无有效单元格,仅空Tag<row />时返回
true |
boolean |
isHidden()
获取当前行是否隐藏,仅
XMLFullRow支持 |
boolean |
nonBlank()
判断单行是否包含值,任意单元格有值且不为空字符串时返回
true |
boolean |
nonEmpty()
判断单行是否包含有效单元格,包含任意实例化单元格时返回
true |
protected void |
rangeCheck(int index)
Check the cell ranges,
|
Row |
setCells(Cell[] cells)
Setting custom
Cell |
Row |
setCells(Cell[] cells,
int fromIndex,
int toIndex)
Setting custom
Cell |
Row |
setHr(HeaderRow hr)
设置表头
|
static int |
testNumberType(char[] cb,
int a,
int b) |
<T> T |
to(Class<T> clazz)
将行数据转为指定对象<T>,待转换的对象必须包含无参的构建函数且待接收的字段使用
ExcelColumn注解,
如果未指定表头时则以当前行为表头此时to方法会返回一个null对象,外部需要过滤非null对象否则会抛NPE异常。 |
static int |
toCellIndex(char[] cb,
int a,
int b)
Convert to column index
|
Map<String,Object> |
toMap()
将行数据转为字典类型,为保证列顺序实际类型为
LinkedHashMap,如果使用Sheet.dataRows()和Sheet.header(int)
指定表头则字典的Key为表头文本,Value为表头对应的列值,如果未指定表头那将以列索引做为Key,与导出指定的colIndex一样索引从0开始。 |
<T> T |
too(Class<T> clazz)
与
to(java.lang.Class<T>)方法功能相同,唯一区别是#too方法返回的对象是内存共享的,所以不能将返回值收集到集合类或者数组 |
String |
toString() |
protected final org.slf4j.Logger LOGGER
protected int index
protected int fc
protected int lc
protected Cell[] cells
protected SharedStrings sst
protected HeaderRow hr
protected boolean unknownLength
protected Styles styles
public int getRowNum()
public int getFirstColumnIndex()
public int getLastColumnIndex()
public boolean isEmpty()
truetruepublic boolean nonEmpty()
truepublic boolean isBlank()
truetruepublic boolean nonBlank()
truepublic Double getHeight()
XMLFullRow支持customHeight=1时返回自定义行高否则返回nullpublic boolean isHidden()
XMLFullRow支持true行隐藏protected void rangeCheck(int index)
index - the indexIndexOutOfBoundsException - If the specified index
argument is negativepublic Cell getCell(int i)
Cell,获取到单元格后可用于后续取值或样式i - 单元格列索引CellIndexOutOfBoundsException - 单元络索引为负数时抛此异常public Cell getCell(String name)
Cell,获取到单元格后可用于后续取值或样式,如果查找不到时则返回一个空的单元格name - 表头Cellpublic HeaderRow asHeader()
public Boolean getBoolean(int columnIndex)
Boolean类型,对于非布尔类型则兼容C语言的bool判断columnIndex - 单元格索引numeric类型非0为true其余为false,
string类型文本值为"true"则为true,单元格为空或未实例化时返回nullpublic Boolean getBoolean(String columnName)
Boolean类型,对于非布尔类型则兼容C语言的bool判断columnName - 列名numeric类型非0为true其余为false,
string类型文本值为"true"则为true,单元格为空或未实例化时返回nullpublic Boolean getBoolean(Cell c)
Boolean类型,对于非布尔类型则兼容C语言的bool判断c - 单元格Cellnumeric类型非0为true其余为false,
string类型文本值为"true"则为true,单元格为空或未实例化时返回nullpublic Byte getByte(int columnIndex)
Byte类型columnIndex - 列索引numeric类型强制转为byte,其余类型返回nullpublic Byte getByte(String columnName)
Byte类型columnName - 列名numeric类型强制转为byte,其余类型返回nullpublic Byte getByte(Cell c)
Byte类型c - 单元格Cellnumeric类型强制转为byte,其余类型返回nullpublic Character getChar(int columnIndex)
Character类型columnIndex - 列索引numeric类型强制转为char,string类型取第一个字符,其余类型返回nullpublic Character getChar(String columnName)
Character类型columnName - 列名numeric类型强制转为char,string类型取第一个字符,其余类型返回nullpublic Character getChar(Cell c)
Character类型c - 单元格Cellnumeric类型强制转为char,string类型取第一个字符,其余类型返回nullpublic Short getShort(int columnIndex)
Short类型columnIndex - 列索引numeric和string类型能强转为short,其余类型返回nullpublic Short getShort(String columnName)
Short类型columnName - 列名numeric和string类型能强转为short,其余类型返回nullpublic Short getShort(Cell c)
Short类型c - 单元格Cellnumeric和string类型能强转为short,其余类型返回nullpublic Integer getInt(int columnIndex)
Integer类型columnIndex - 单元格索引numeric和string类型能强转为Integer,其余类型返回nullpublic Integer getInt(String columnName)
Integer类型columnName - 列索引numeric和string类型能强转为Integer,其余类型返回nullpublic Integer getInt(Cell c)
Integer类型c - 单元格Cellnumeric和string类型能强转为Integer,其余类型返回nullpublic Long getLong(int columnIndex)
Long类型columnIndex - 单元格索引numeric和string类型能强转为Long,其余类型返回nullpublic Long getLong(String columnName)
Long类型columnName - 列名numeric和string类型能强转为Long,其余类型返回nullpublic Long getLong(Cell c)
Long类型c - 单元格Cellnumeric和string类型能强转为Long,其余类型返回nullpublic String getString(int columnIndex)
String类型columnIndex - 单元格索引nullpublic String getString(String columnName)
String类型columnName - 列名nullpublic String getString(Cell c)
String类型c - 单元格Cellnullpublic Float getFloat(int columnIndex)
Float类型columnIndex - 单元格索引Float否则返回null,此接口可能抛NumberFormatException异常public Float getFloat(String columnName)
Float类型columnName - 列名Float否则返回null,此接口可能抛NumberFormatException异常public Float getFloat(Cell c)
Float类型c - 单元格CellFloat否则返回null,此接口可能抛NumberFormatException异常public Double getDouble(int columnIndex)
Double类型columnIndex - 单元格索引Double否则返回null,此接口可能抛NumberFormatException异常public Double getDouble(String columnName)
Double类型columnName - 列名Double否则返回null,此接口可能抛NumberFormatException异常public Double getDouble(Cell c)
Double类型c - 单元格CellDouble否则返回null,此接口可能抛NumberFormatException异常public BigDecimal getDecimal(int columnIndex)
java.math.BigDecimal类型columnIndex - 单元格索引java.math.BigDecimal否则返回null,此接口可能抛NumberFormatException异常public BigDecimal getDecimal(String columnName)
java.math.BigDecimal类型columnName - 列名java.math.BigDecimal否则返回null,此接口可能抛NumberFormatException异常public BigDecimal getDecimal(Cell c)
java.math.BigDecimal类型c - 单元格Celljava.math.BigDecimal否则返回null,此接口可能抛NumberFormatException异常public Date getDate(int columnIndex)
java.util.Date类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理columnIndex - 单元格索引java.util.Date否则返回null,此接口可能抛NumberFormatException异常public Date getDate(String columnName)
java.util.Date类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理columnName - 列名java.util.Date否则返回null,此接口可能抛NumberFormatException异常public Date getDate(Cell c)
java.util.Date类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理c - 单元格Celljava.util.Date否则返回null,此接口可能抛NumberFormatException异常public Timestamp getTimestamp(int columnIndex)
java.sql.Timestamp类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理columnIndex - 单元格索引java.sql.Timestamp否则返回null,此接口可能抛NumberFormatException异常public Timestamp getTimestamp(String columnName)
java.sql.Timestamp类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理columnName - 列名java.sql.Timestamp否则返回null,此接口可能抛NumberFormatException异常public Timestamp getTimestamp(Cell c)
java.sql.Timestamp类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理c - 单元格Celljava.sql.Timestamp否则返回null,此接口可能抛NumberFormatException异常public Time getTime(int columnIndex)
java.sql.Time类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理columnIndex - 单元格索引java.sql.Time否则返回null,此接口可能抛NumberFormatException异常public Time getTime(String columnName)
java.sql.Time类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理columnName - 列名java.sql.Time否则返回null,此接口可能抛NumberFormatException异常public Time getTime(Cell c)
java.sql.Time类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理c - 单元格Celljava.sql.Time否则返回null,此接口可能抛NumberFormatException异常public LocalDateTime getLocalDateTime(int columnIndex)
LocalDateTime类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理columnIndex - 单元格索引LocalDateTime否则返回null,此接口可能抛NumberFormatException异常public LocalDateTime getLocalDateTime(String columnName)
LocalDateTime类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理columnName - 列名LocalDateTime否则返回null,此接口可能抛NumberFormatException异常public LocalDateTime getLocalDateTime(Cell c)
LocalDateTime类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理c - 单元格CellLocalDateTime否则返回null,此接口可能抛NumberFormatException异常public LocalDate getLocalDate(int columnIndex)
LocalDate类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理columnIndex - 单元格索引LocalDate否则返回null,此接口可能抛NumberFormatException异常public LocalDate getLocalDate(String columnName)
LocalDate类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理columnName - 列名LocalDate否则返回null,此接口可能抛NumberFormatException异常public LocalDate getLocalDate(Cell c)
LocalDate类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理c - 单元格CellLocalDate否则返回null,此接口可能抛NumberFormatException异常public LocalTime getLocalTime(int columnIndex)
LocalTime类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理columnIndex - 单元格索引LocalTime否则返回null,此接口可能抛NumberFormatException异常public LocalTime getLocalTime(String columnName)
LocalTime类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理columnName - 列名LocalTime否则返回null,此接口可能抛NumberFormatException异常public LocalTime getLocalTime(Cell c)
LocalTime类型,整数和小数类型将以1900-1-1为基础进行计算,字符串将进行格式化处理c - 单元格CellLocalTime否则返回null,此接口可能抛NumberFormatException异常public String getFormula(int columnIndex)
columnIndex - 列索引nullpublic String getFormula(String columnName)
columnName - 列名nullpublic boolean hasFormula(int columnIndex)
columnIndex - 单元格索引true否则返回falsepublic boolean hasFormula(String columnName)
columnName - 列名true否则返回falsepublic boolean hasFormula(Cell cell)
cell - 单元格true否则返回falsepublic CellType getCellType(int columnIndex)
注意:这里仅是一个近似的类型,因为从原始文件中只能获取到numeric,string,
boolean三种类型。在解析到原始类型之后对于numeric类型会根据数字大小和格式重新设置类型,
比如小于0x7fffffff的值为int,超过这个范围时为long,如果带日期格式化则为date类型,
小数也是同样处理,有日期格式化为data类型否则为decimal类型
columnIndex - 列索引CellTypepublic CellType getCellType(String columnName)
注意:这里仅是一个近似的类型,因为从原始文件中只能获取到numeric,string,
boolean三种类型。在解析到原始类型之后对于numeric类型会根据数字大小和格式重新设置类型,
比如小于0x7fffffff的值为int,超过这个范围时为long,如果带日期格式化则为date类型,
小数也是同样处理,有日期格式化为data类型否则为decimal类型
columnName - 列名CellTypepublic CellType getCellType(Cell c)
注意:这里仅是一个近似的类型,因为从原始文件中只能获取到numeric,string,
boolean三种类型。在解析到原始类型之后对于numeric类型会根据数字大小和格式重新设置类型,
比如小于0x7fffffff的值为int,超过这个范围时为long,如果带日期格式化则为date类型,
小数也是同样处理,有日期格式化为data类型否则为decimal类型
public int getCellStyle(int columnIndex)
Styles.getBorder(int)等方法获取具体的样式columnIndex - 列索引public int getCellStyle(String columnName)
Styles.getBorder(int)等方法获取具体的样式columnName - 列名public int getCellStyle(Cell c)
Styles.getBorder(int)等方法获取具体的样式c - 单元格Cellpublic boolean isBlank(int columnIndex)
columnIndex - 列索引truepublic boolean isBlank(String columnName)
columnName - 列名truepublic <T> T get()
Sheet.bind(java.lang.Class<?>)方法绑定类型后,使用此方法将整行数据转为指定类型<T>T - 绑定的对象类型public <T> T geet()
Sheet.bind(java.lang.Class<?>)方法绑定类型后,使用此方法将整行数据转为指定类型<T>,与get()的区别在于
本方法返回的对象是内存共享的(只有一个对象副本)T - 绑定的对象类型public <T> T to(Class<T> clazz)
ExcelColumn注解,
如果未指定表头时则以当前行为表头此时to方法会返回一个null对象,外部需要过滤非null对象否则会抛NPE异常。
指定对象<T>解析的结果会缓存到HeaderRow对象中,除非指定不同类型否则后续都将从HeaderRow中获取
必要信息,这样可以提高转换性能
T - 强转返回对象类型clazz - 指定转换类型public <T> T too(Class<T> clazz)
to(java.lang.Class<T>)方法功能相同,唯一区别是#too方法返回的对象是内存共享的,所以不能将返回值收集到集合类或者数组T - 强转返回对象类型clazz - 指定转换类型public Map<String,Object> toMap()
LinkedHashMap,如果使用Sheet.dataRows()和Sheet.header(int)
指定表头则字典的Key为表头文本,Value为表头对应的列值,如果未指定表头那将以列索引做为Key,与导出指定的colIndex一样索引从0开始。
对于多行表头字典Key将以行1:行2:行n的格式进行拼接,横向合并的单元格将自动将值复制到每一列,而纵向合并的单元格则不会复制,
可以参考Sheet.getHeader()方法。
关于单元格类型的特殊说明:行数据转对象时会根据对象定义进行一次类型转换,将单元格的值转为对象定义中的类型,但是转为字典时却不会有这一步
逻辑,类型是根据excel中的值进行粗粒度转换,例如数字类型如果带有日期格式化则会返回一个Timestamp类型,
所以最终的数据类型可能与预期有所不同
public Cell[] copyCells()
public Cell[] copyCells(int newLength)
newLength - the length of the copy to be returnedpublic Row setCells(Cell[] cells)
Cellcells - row cellspublic Row setCells(Cell[] cells, int fromIndex, int toIndex)
Cellcells - row cellsfromIndex - specify the first cells index(one base)toIndex - specify the last cells index(one base)public static int toCellIndex(char[] cb,
int a,
int b)
cb - character buffera - the start indexb - the end indexpublic static int testNumberType(char[] cb,
int a,
int b)
Copyright © 2024. All rights reserved.