|
|
|
@ -16,6 +16,7 @@ import com.alibaba.excel.enums.CellExtraTypeEnum;
|
|
|
|
|
import com.alibaba.excel.read.listener.PageReadListener; |
|
|
|
|
import com.alibaba.excel.read.listener.ReadListener; |
|
|
|
|
import com.alibaba.excel.read.metadata.ReadSheet; |
|
|
|
|
import com.alibaba.excel.read.metadata.holder.csv.CsvReadWorkbookHolder; |
|
|
|
|
import com.alibaba.excel.util.ListUtils; |
|
|
|
|
import com.alibaba.fastjson2.JSON; |
|
|
|
|
|
|
|
|
@ -309,4 +310,28 @@ public class ReadTest {
|
|
|
|
|
// 这里 只要,然后读取第一个sheet 同步读取会自动finish
|
|
|
|
|
EasyExcel.read(fileName, new NoModelDataListener()).sheet().doRead(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 自定义修改csv配置 |
|
|
|
|
*/ |
|
|
|
|
@Test |
|
|
|
|
public void csvFormat() { |
|
|
|
|
String fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.csv"; |
|
|
|
|
try (ExcelReader excelReader = EasyExcel.read(fileName, DemoData.class, new DemoDataListener()).build()) { |
|
|
|
|
// 判断是 csv 文件
|
|
|
|
|
if (excelReader.analysisContext().readWorkbookHolder() instanceof CsvReadWorkbookHolder) { |
|
|
|
|
CsvReadWorkbookHolder csvReadWorkbookHolder = (CsvReadWorkbookHolder)excelReader.analysisContext() |
|
|
|
|
.readWorkbookHolder(); |
|
|
|
|
// 设置成逗号分隔 当然默认也是逗号分隔
|
|
|
|
|
// 这里要注意 withDelimiter 会重新生成一个 所以要放回去
|
|
|
|
|
csvReadWorkbookHolder.setCsvFormat(csvReadWorkbookHolder.getCsvFormat().withDelimiter(',')); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 拿到所有 sheet
|
|
|
|
|
List<ReadSheet> readSheetList = excelReader.excelExecutor().sheetList(); |
|
|
|
|
// 如果只想读取第一个 咋样传入参数即可
|
|
|
|
|
//ReadSheet readSheet = EasyExcel.readSheet(0).build();
|
|
|
|
|
excelReader.read(readSheetList); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|