mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -4,6 +4,7 @@ import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.lang.func.SerConsumer;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
|
||||
@@ -125,7 +126,7 @@ public class CsvBaseReader implements Serializable {
|
||||
* @param csvStr CSV字符串
|
||||
* @param rowHandler 行处理器,用于一行一行的处理数据
|
||||
*/
|
||||
public void readFromStr(final String csvStr, final CsvRowHandler rowHandler) {
|
||||
public void readFromStr(final String csvStr, final SerConsumer<CsvRow> rowHandler) {
|
||||
read(parse(new StringReader(csvStr)), rowHandler);
|
||||
}
|
||||
|
||||
@@ -242,7 +243,7 @@ public class CsvBaseReader implements Serializable {
|
||||
* @param rowHandler 行处理器,用于一行一行的处理数据
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
public void read(final Reader reader, final CsvRowHandler rowHandler) throws IORuntimeException {
|
||||
public void read(final Reader reader, final SerConsumer<CsvRow> rowHandler) throws IORuntimeException {
|
||||
read(parse(reader), rowHandler);
|
||||
}
|
||||
|
||||
@@ -256,10 +257,10 @@ public class CsvBaseReader implements Serializable {
|
||||
* @throws IORuntimeException IO异常
|
||||
* @since 5.0.4
|
||||
*/
|
||||
private void read(final CsvParser csvParser, final CsvRowHandler rowHandler) throws IORuntimeException {
|
||||
private void read(final CsvParser csvParser, final SerConsumer<CsvRow> rowHandler) throws IORuntimeException {
|
||||
try {
|
||||
while (csvParser.hasNext()){
|
||||
rowHandler.handle(csvParser.next());
|
||||
rowHandler.accept(csvParser.next());
|
||||
}
|
||||
} finally {
|
||||
IoUtil.close(csvParser);
|
||||
|
@@ -3,6 +3,7 @@ package cn.hutool.poi.csv;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.lang.func.SerConsumer;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
@@ -120,7 +121,7 @@ public class CsvReader extends CsvBaseReader implements Iterable<CsvRow>, Closea
|
||||
* @throws IORuntimeException IO异常
|
||||
* @since 5.0.4
|
||||
*/
|
||||
public void read(final CsvRowHandler rowHandler) throws IORuntimeException {
|
||||
public void read(final SerConsumer<CsvRow> rowHandler) throws IORuntimeException {
|
||||
read(this.reader, rowHandler);
|
||||
}
|
||||
|
||||
|
@@ -1,18 +0,0 @@
|
||||
package cn.hutool.poi.csv;
|
||||
|
||||
/**
|
||||
* CSV的行处理器,实现此接口用于按照行处理数据
|
||||
*
|
||||
* @author Looly
|
||||
* @since 5.0.4
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface CsvRowHandler {
|
||||
|
||||
/**
|
||||
* 处理行数据
|
||||
*
|
||||
* @param row 行数据
|
||||
*/
|
||||
void handle(CsvRow row);
|
||||
}
|
@@ -2,8 +2,8 @@ package cn.hutool.poi.excel;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.lang.func.SerBiConsumer;
|
||||
import cn.hutool.poi.excel.cell.CellEditor;
|
||||
import cn.hutool.poi.excel.cell.CellHandler;
|
||||
import cn.hutool.poi.excel.cell.CellUtil;
|
||||
import cn.hutool.poi.excel.reader.BeanSheetReader;
|
||||
import cn.hutool.poi.excel.reader.ColumnSheetReader;
|
||||
@@ -252,7 +252,7 @@ public class ExcelReader extends ExcelBase<ExcelReader> {
|
||||
* @param cellHandler 单元格处理器,用于处理读到的单元格及其数据
|
||||
* @since 5.3.8
|
||||
*/
|
||||
public void read(final CellHandler cellHandler) {
|
||||
public void read(final SerBiConsumer<Cell, Object> cellHandler) {
|
||||
read(0, Integer.MAX_VALUE, cellHandler);
|
||||
}
|
||||
|
||||
@@ -265,7 +265,7 @@ public class ExcelReader extends ExcelBase<ExcelReader> {
|
||||
* @param cellHandler 单元格处理器,用于处理读到的单元格及其数据
|
||||
* @since 5.3.8
|
||||
*/
|
||||
public void read(int startRowIndex, int endRowIndex, final CellHandler cellHandler) {
|
||||
public void read(int startRowIndex, int endRowIndex, final SerBiConsumer<Cell, Object> cellHandler) {
|
||||
checkNotClosed();
|
||||
|
||||
startRowIndex = Math.max(startRowIndex, this.sheet.getFirstRowNum());// 读取起始行(包含)
|
||||
@@ -280,7 +280,7 @@ public class ExcelReader extends ExcelBase<ExcelReader> {
|
||||
Cell cell;
|
||||
for (short x = 0; x < columnSize; x++) {
|
||||
cell = row.getCell(x);
|
||||
cellHandler.handle(cell, CellUtil.getCellValue(cell));
|
||||
cellHandler.accept(cell, CellUtil.getCellValue(cell));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,21 +0,0 @@
|
||||
package cn.hutool.poi.excel.cell;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
|
||||
/**
|
||||
* 单元格处理器接口<br>
|
||||
* 用于在读取Excel单元格值时自定义结果值的获取,如在获取值的同时,获取单元格样式、坐标等信息,或根据单元格信息,装饰转换结果值
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface CellHandler {
|
||||
|
||||
/**
|
||||
* 处理
|
||||
*
|
||||
* @param cell 单元格对象,可以获取单元格行、列样式等信息
|
||||
* @param value 单元格值
|
||||
*/
|
||||
void handle(Cell cell, Object value);
|
||||
}
|
@@ -15,9 +15,13 @@ import java.io.InputStream;
|
||||
*/
|
||||
public interface ExcelSaxReader<T> {
|
||||
|
||||
// sheet r:Id前缀
|
||||
/**
|
||||
* sheet r:Id前缀
|
||||
*/
|
||||
String RID_PREFIX = "rId";
|
||||
// sheet name前缀
|
||||
/**
|
||||
* sheet name前缀
|
||||
*/
|
||||
String SHEET_NAME_PREFIX = "sheetName:";
|
||||
|
||||
/**
|
||||
|
@@ -20,6 +20,7 @@ import java.util.List;
|
||||
* <pre>
|
||||
* <sheetData></sheetData>
|
||||
* </pre>
|
||||
*
|
||||
* @since 5.5.3
|
||||
*/
|
||||
public class SheetDataSaxHandler extends DefaultHandler {
|
||||
@@ -61,7 +62,12 @@ public class SheetDataSaxHandler extends DefaultHandler {
|
||||
// 存储每行的列元素
|
||||
private List<Object> rowCellList = new ArrayList<>();
|
||||
|
||||
public SheetDataSaxHandler(final RowHandler rowHandler){
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param rowHandler 行处理器
|
||||
*/
|
||||
public SheetDataSaxHandler(final RowHandler rowHandler) {
|
||||
this.rowHandler = rowHandler;
|
||||
}
|
||||
|
||||
@@ -155,7 +161,7 @@ public class SheetDataSaxHandler extends DefaultHandler {
|
||||
lastFormula.append(ch, start, length);
|
||||
break;
|
||||
}
|
||||
} else{
|
||||
} else {
|
||||
// 按理说内容应该为"<v>内容</v>",但是某些特别的XML内容不在v或f标签中,此处做一些兼容
|
||||
// issue#1303@Github
|
||||
lastContent.append(ch, start, length);
|
||||
|
@@ -2,10 +2,11 @@ package cn.hutool.poi.excel;
|
||||
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.lang.func.SerBiConsumer;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.poi.excel.cell.CellHandler;
|
||||
import lombok.Data;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
@@ -231,7 +232,7 @@ public class ExcelReadTest {
|
||||
@Ignore
|
||||
public void readNullRowTest(){
|
||||
final ExcelReader reader = ExcelUtil.getReader("d:/test/1.-.xls");
|
||||
reader.read((CellHandler) Console::log);
|
||||
reader.read((SerBiConsumer<Cell, Object>) Console::log);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user