Search in sources :

Example 1 with ExcelReader

use of com.alibaba.excel.ExcelReader in project easyexcel by alibaba.

the class RepeatTest method hh.

@Test
public void hh() throws IOException {
    ExcelReader reader = EasyExcel.read(new FileInputStream("D:\\test\\hg2.xls"), LockData.class, new RepeatListener()).headRowNumber(0).build();
    ReadSheet r1 = EasyExcel.readSheet(0).build();
    ReadSheet r2 = EasyExcel.readSheet(2).build();
    reader.read(r1);
    reader.read(r2);
    reader.finish();
}
Also used : ExcelReader(com.alibaba.excel.ExcelReader) ReadSheet(com.alibaba.excel.read.metadata.ReadSheet) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 2 with ExcelReader

use of com.alibaba.excel.ExcelReader in project easyexcel by alibaba.

the class MultipleSheetsDataTest method read.

private void read(File file) {
    MultipleSheetsListener multipleSheetsListener = new MultipleSheetsListener();
    try (ExcelReader excelReader = EasyExcel.read(file, MultipleSheetsData.class, multipleSheetsListener).build()) {
        List<ReadSheet> sheets = excelReader.excelExecutor().sheetList();
        int count = 1;
        for (ReadSheet readSheet : sheets) {
            excelReader.read(readSheet);
            Assert.assertEquals(multipleSheetsListener.getList().size(), count);
            count++;
        }
    }
}
Also used : ExcelReader(com.alibaba.excel.ExcelReader) ReadSheet(com.alibaba.excel.read.metadata.ReadSheet)

Example 3 with ExcelReader

use of com.alibaba.excel.ExcelReader in project easyexcel by alibaba.

the class RepetitionDataTest method readAndWrite.

private void readAndWrite(File file) {
    try (ExcelWriter excelWriter = EasyExcel.write(file, RepetitionData.class).build()) {
        WriteSheet writeSheet = EasyExcel.writerSheet(0).build();
        excelWriter.write(data(), writeSheet).write(data(), writeSheet);
    }
    try (ExcelReader excelReader = EasyExcel.read(file, RepetitionData.class, new RepetitionDataListener()).build()) {
        ReadSheet readSheet = EasyExcel.readSheet(0).build();
        excelReader.read(readSheet);
    }
}
Also used : ExcelReader(com.alibaba.excel.ExcelReader) ExcelWriter(com.alibaba.excel.ExcelWriter) WriteSheet(com.alibaba.excel.write.metadata.WriteSheet) ReadSheet(com.alibaba.excel.read.metadata.ReadSheet)

Example 4 with ExcelReader

use of com.alibaba.excel.ExcelReader in project easyexcel by alibaba.

the class RepetitionDataTest method readAndWriteTable.

private void readAndWriteTable(File file) {
    try (ExcelWriter excelWriter = EasyExcel.write(file, RepetitionData.class).build()) {
        WriteSheet writeSheet = EasyExcel.writerSheet(0).build();
        WriteTable writeTable = EasyExcel.writerTable(0).relativeHeadRowIndex(0).build();
        excelWriter.write(data(), writeSheet, writeTable).write(data(), writeSheet, writeTable);
    }
    try (ExcelReader excelReader = EasyExcel.read(file, RepetitionData.class, new RepetitionDataListener()).build()) {
        ReadSheet readSheet = EasyExcel.readSheet(0).headRowNumber(2).build();
        excelReader.read(readSheet);
    }
}
Also used : ExcelReader(com.alibaba.excel.ExcelReader) ExcelWriter(com.alibaba.excel.ExcelWriter) WriteSheet(com.alibaba.excel.write.metadata.WriteSheet) WriteTable(com.alibaba.excel.write.metadata.WriteTable) ReadSheet(com.alibaba.excel.read.metadata.ReadSheet)

Example 5 with ExcelReader

use of com.alibaba.excel.ExcelReader in project eden-architect by shiyindaxiaojie.

the class EasyExcelReader method read.

public <T> void read(@NonNull InputStream inputStream, @NonNull AnalysisEventListener<T> listener, int... sheetIndexs) {
    ExcelReader excelReader = excelReader(inputStream, listener);
    try {
        if (sheetIndexs == null) {
            excelReader.readAll();
        } else {
            List<ReadSheet> readSheets = new ArrayList<>();
            for (int sheetIndex : sheetIndexs) {
                readSheets.add(EasyExcel.readSheet(sheetIndex).build());
            }
            excelReader.read(readSheets);
        }
    } finally {
        excelReader.finish();
    }
}
Also used : ExcelReader(com.alibaba.excel.ExcelReader) ArrayList(java.util.ArrayList) ReadSheet(com.alibaba.excel.read.metadata.ReadSheet)

Aggregations

ExcelReader (com.alibaba.excel.ExcelReader)24 ReadSheet (com.alibaba.excel.read.metadata.ReadSheet)15 Test (org.junit.Test)6 ExcelWriter (com.alibaba.excel.ExcelWriter)5 Sheet (com.alibaba.excel.metadata.Sheet)5 WriteSheet (com.alibaba.excel.write.metadata.WriteSheet)5 FileInputStream (java.io.FileInputStream)4 WriteTable (com.alibaba.excel.write.metadata.WriteTable)3 ArrayList (java.util.ArrayList)3 MapCache (com.alibaba.excel.cache.MapCache)2 AnalysisContext (com.alibaba.excel.context.AnalysisContext)2 SyncReadListener (com.alibaba.excel.event.SyncReadListener)2 ExcelReaderBuilder (com.alibaba.excel.read.builder.ExcelReaderBuilder)2 FileOutputStream (java.io.FileOutputStream)2 List (java.util.List)2 ModelExcelListener (cn.ruiyeclub.listener.ModelExcelListener)1 StringExcelListener (cn.ruiyeclub.listener.StringExcelListener)1 SimpleData (com.alibaba.easyexcel.test.core.simple.SimpleData)1 TestFileUtil (com.alibaba.easyexcel.test.util.TestFileUtil)1 EasyExcel (com.alibaba.excel.EasyExcel)1