mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix poi
This commit is contained in:
@@ -511,12 +511,12 @@ public class ExcelReader extends ExcelBase<ExcelReader> {
|
||||
* @return 转换别名列表
|
||||
*/
|
||||
private List<String> aliasHeader(List<Object> headerList) {
|
||||
final int size = headerList.size();
|
||||
final ArrayList<String> result = new ArrayList<>(size);
|
||||
if (CollUtil.isEmpty(headerList)) {
|
||||
return result;
|
||||
if(CollUtil.isEmpty(headerList)){
|
||||
return new ArrayList<>(0);
|
||||
}
|
||||
|
||||
final int size = headerList.size();
|
||||
final ArrayList<String> result = new ArrayList<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
result.add(aliasHeader(headerList.get(i), i));
|
||||
}
|
||||
|
@@ -1,27 +1,27 @@
|
||||
package cn.hutool.poi.excel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.poi.excel.cell.CellEditor;
|
||||
import cn.hutool.poi.excel.cell.CellUtil;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.poi.excel.cell.CellEditor;
|
||||
import cn.hutool.poi.excel.cell.CellUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Excel中的行{@link Row}封装工具类
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
* @since 4.0.7
|
||||
*/
|
||||
public class RowUtil {
|
||||
/**
|
||||
* 获取已有行或创建新行
|
||||
*
|
||||
* @param sheet Excel表
|
||||
*
|
||||
* @param sheet Excel表
|
||||
* @param rowIndex 行号
|
||||
* @return {@link Row}
|
||||
* @since 4.0.2
|
||||
@@ -36,23 +36,38 @@ public class RowUtil {
|
||||
|
||||
/**
|
||||
* 读取一行
|
||||
*
|
||||
* @param row 行
|
||||
*
|
||||
* @param row 行
|
||||
* @param cellEditor 单元格编辑器
|
||||
* @return 单元格值列表
|
||||
*/
|
||||
public static List<Object> readRow(Row row, CellEditor cellEditor) {
|
||||
return readRow(row, 0, Short.MAX_VALUE, cellEditor);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取一行
|
||||
*
|
||||
* @param row 行
|
||||
* @param startCellNumInclude 起始单元格号,0开始(包含)
|
||||
* @param endCellNumInclude 结束单元格号,0开始(包含)
|
||||
* @param cellEditor 单元格编辑器
|
||||
* @return 单元格值列表
|
||||
*/
|
||||
public static List<Object> readRow(Row row, int startCellNumInclude, int endCellNumInclude, CellEditor cellEditor) {
|
||||
if (null == row) {
|
||||
return new ArrayList<>(0);
|
||||
}
|
||||
final short length = row.getLastCellNum();
|
||||
if (length < 0) {
|
||||
return new ArrayList<>(0);
|
||||
final short rowLength = row.getLastCellNum();
|
||||
if (rowLength < 0) {
|
||||
return ListUtil.empty();
|
||||
}
|
||||
final List<Object> cellValues = new ArrayList<>(length);
|
||||
|
||||
final int size = Math.min(endCellNumInclude + 1, rowLength);
|
||||
final List<Object> cellValues = new ArrayList<>(size);
|
||||
Object cellValue;
|
||||
boolean isAllNull = true;
|
||||
for (short i = 0; i < length; i++) {
|
||||
for (int i = startCellNumInclude; i < size; i++) {
|
||||
cellValue = CellUtil.getCellValue(row.getCell(i), cellEditor);
|
||||
isAllNull &= StrUtil.isEmptyIfStr(cellValue);
|
||||
cellValues.add(cellValue);
|
||||
@@ -60,16 +75,16 @@ public class RowUtil {
|
||||
|
||||
if (isAllNull) {
|
||||
// 如果每个元素都为空,则定义为空行
|
||||
return new ArrayList<>(0);
|
||||
return ListUtil.empty();
|
||||
}
|
||||
return cellValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* 写一行数据
|
||||
*
|
||||
* @param row 行
|
||||
* @param rowData 一行的数据
|
||||
*
|
||||
* @param row 行
|
||||
* @param rowData 一行的数据
|
||||
* @param styleSet 单元格样式集,包括日期等样式
|
||||
* @param isHeader 是否为标题行
|
||||
*/
|
||||
|
Reference in New Issue
Block a user