use of com.alibaba.excel.ExcelReader in project easyexcel by alibaba.
the class ParameterDataTest method readAndWrite5.
private void readAndWrite5(File file, ExcelTypeEnum type) throws Exception {
ExcelWriter excelWriter = EasyExcel.write(new FileOutputStream(file)).excelType(type).head(ParameterData.class).relativeHeadRowIndex(0).build();
WriteSheet writeSheet = EasyExcel.writerSheet(0).relativeHeadRowIndex(0).needHead(Boolean.FALSE).build();
WriteTable writeTable = EasyExcel.writerTable(0).relativeHeadRowIndex(0).needHead(Boolean.TRUE).build();
excelWriter.write(data(), writeSheet, writeTable);
excelWriter.finish();
ExcelReader excelReader = EasyExcel.read(file.getPath(), new ParameterDataListener()).head(ParameterData.class).mandatoryUseInputStream(Boolean.FALSE).autoCloseStream(Boolean.TRUE).readCache(new MapCache()).build();
ReadSheet readSheet = EasyExcel.readSheet().head(ParameterData.class).use1904windowing(Boolean.FALSE).headRowNumber(1).sheetNo(0).sheetName("0").build();
excelReader.read(readSheet);
excelReader.finish();
excelReader = EasyExcel.read(file.getPath(), new ParameterDataListener()).head(ParameterData.class).mandatoryUseInputStream(Boolean.FALSE).autoCloseStream(Boolean.TRUE).readCache(new MapCache()).build();
excelReader.read();
excelReader.finish();
}
use of com.alibaba.excel.ExcelReader in project easyexcel by alibaba.
the class ParameterDataTest method readAndWrite6.
private void readAndWrite6(File file, ExcelTypeEnum type) throws Exception {
ExcelWriter excelWriter = EasyExcel.write(new FileOutputStream(file)).excelType(type).head(ParameterData.class).relativeHeadRowIndex(0).build();
WriteSheet writeSheet = EasyExcel.writerSheet(0).relativeHeadRowIndex(0).needHead(Boolean.FALSE).build();
WriteTable writeTable = EasyExcel.writerTable(0).registerConverter(new StringStringConverter()).relativeHeadRowIndex(0).needHead(Boolean.TRUE).build();
excelWriter.write(data(), writeSheet, writeTable);
excelWriter.finish();
ExcelReader excelReader = EasyExcel.read(file.getPath(), new ParameterDataListener()).head(ParameterData.class).mandatoryUseInputStream(Boolean.FALSE).autoCloseStream(Boolean.TRUE).readCache(new MapCache()).build();
ReadSheet readSheet = EasyExcel.readSheet("0").head(ParameterData.class).use1904windowing(Boolean.FALSE).headRowNumber(1).sheetNo(0).build();
excelReader.read(readSheet);
excelReader.finish();
excelReader = EasyExcel.read(file.getPath(), new ParameterDataListener()).head(ParameterData.class).mandatoryUseInputStream(Boolean.FALSE).autoCloseStream(Boolean.TRUE).readCache(new MapCache()).build();
excelReader.read();
excelReader.finish();
}
use of com.alibaba.excel.ExcelReader in project easyexcel by alibaba.
the class SkipDataTest method readAndWrite.
private void readAndWrite(File file) {
try (ExcelWriter excelWriter = EasyExcel.write(file, SimpleData.class).build()) {
WriteSheet writeSheet0 = EasyExcel.writerSheet(0, "第一个").build();
WriteSheet writeSheet1 = EasyExcel.writerSheet(1, "第二个").build();
WriteSheet writeSheet2 = EasyExcel.writerSheet(2, "第三个").build();
WriteSheet writeSheet3 = EasyExcel.writerSheet(3, "第四个").build();
excelWriter.write(data("name1"), writeSheet0);
excelWriter.write(data("name2"), writeSheet1);
excelWriter.write(data("name3"), writeSheet2);
excelWriter.write(data("name4"), writeSheet3);
}
List<SkipData> list = EasyExcel.read(file, SkipData.class, null).sheet("第二个").doReadSync();
Assert.assertEquals(1, list.size());
Assert.assertEquals("name2", list.get(0).getName());
SyncReadListener syncReadListener = new SyncReadListener();
try (ExcelReader excelReader = EasyExcel.read(file, SkipData.class, null).registerReadListener(syncReadListener).build()) {
ReadSheet readSheet1 = EasyExcel.readSheet("第二个").build();
ReadSheet readSheet3 = EasyExcel.readSheet("第四个").build();
excelReader.read(readSheet1, readSheet3);
List<Object> syncList = syncReadListener.getList();
Assert.assertEquals(2, syncList.size());
Assert.assertEquals("name2", ((SkipData) syncList.get(0)).getName());
Assert.assertEquals("name4", ((SkipData) syncList.get(1)).getName());
}
}
use of com.alibaba.excel.ExcelReader in project chunjun by DTStack.
the class ExcelFileReadClient method open.
@Override
public void open(InputStream inputStream, FtpConfig ftpConfig) throws IOException {
cellCount = ftpConfig.getColumn().size();
ExcelReadListener listener = new ExcelReadListener();
queue = listener.getQueue();
ExcelReaderBuilder builder = EasyExcel.read(inputStream, listener);
if (!ftpConfig.getIsFirstLineHeader()) {
builder.headRowNumber(0);
}
builder.ignoreEmptyRow(true);
ExcelReader reader = builder.build();
sheetNum = reader.excelExecutor().sheetList().size();
executorService = new ThreadPoolExecutor(1, 1, 0, NANOSECONDS, new LinkedBlockingDeque<>(2), new BasicThreadFactory.Builder().namingPattern("excel-schedule-pool-%d").uncaughtExceptionHandler(new ExcelReaderExceptionHandler()).daemon(false).build());
ExcelReaderExecutor executor = new ExcelReaderExecutor(reader);
executorService.execute(executor);
}
Aggregations