Search in sources :

Example 11 with ReadSheet

use of com.alibaba.excel.read.metadata.ReadSheet in project easyexcel by alibaba.

the class CsvExcelReadExecutor method execute.

@Override
public void execute() {
    CSVParser csvParser;
    try {
        csvParser = csvParser();
        csvReadContext.csvReadWorkbookHolder().setCsvParser(csvParser);
    } catch (IOException e) {
        throw new ExcelAnalysisException(e);
    }
    for (ReadSheet readSheet : sheetList) {
        readSheet = SheetUtils.match(readSheet, csvReadContext);
        if (readSheet == null) {
            continue;
        }
        csvReadContext.currentSheet(readSheet);
        int rowIndex = 0;
        for (CSVRecord record : csvParser) {
            dealRecord(record, rowIndex++);
        }
        // The last sheet is read
        csvReadContext.analysisEventProcessor().endSheet(csvReadContext);
    }
}
Also used : CSVParser(org.apache.commons.csv.CSVParser) CSVRecord(org.apache.commons.csv.CSVRecord) IOException(java.io.IOException) ReadSheet(com.alibaba.excel.read.metadata.ReadSheet) ExcelAnalysisException(com.alibaba.excel.exception.ExcelAnalysisException)

Example 12 with ReadSheet

use of com.alibaba.excel.read.metadata.ReadSheet in project easyexcel by alibaba.

the class BofRecordHandler method initReadSheetDataList.

private void initReadSheetDataList(XlsReadWorkbookHolder xlsReadWorkbookHolder) {
    if (xlsReadWorkbookHolder.getActualSheetDataList() != null) {
        return;
    }
    BoundSheetRecord[] boundSheetRecords = BoundSheetRecord.orderByBofPosition(xlsReadWorkbookHolder.getBoundSheetRecordList());
    List<ReadSheet> readSheetDataList = new ArrayList<ReadSheet>();
    for (int i = 0; i < boundSheetRecords.length; i++) {
        BoundSheetRecord boundSheetRecord = boundSheetRecords[i];
        ReadSheet readSheet = new ReadSheet(i, boundSheetRecord.getSheetname());
        readSheetDataList.add(readSheet);
    }
    xlsReadWorkbookHolder.setActualSheetDataList(readSheetDataList);
    // Just need to get the list of sheets
    if (!xlsReadWorkbookHolder.getNeedReadSheet()) {
        throw new ExcelAnalysisStopException("Just need to get the list of sheets.");
    }
}
Also used : ArrayList(java.util.ArrayList) ExcelAnalysisStopException(com.alibaba.excel.exception.ExcelAnalysisStopException) ReadSheet(com.alibaba.excel.read.metadata.ReadSheet) BoundSheetRecord(org.apache.poi.hssf.record.BoundSheetRecord)

Example 13 with ReadSheet

use of com.alibaba.excel.read.metadata.ReadSheet in project easyexcel by alibaba.

the class RepeatTest method hh2.

@Test
public void hh2() throws IOException {
    ExcelReader reader = EasyExcel.read(new FileInputStream("D:\\test\\sheet.xls"), LockData.class, new RepeatListener()).headRowNumber(0).build();
    ReadSheet r2 = EasyExcel.readSheet(1).build();
    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 14 with ReadSheet

use of com.alibaba.excel.read.metadata.ReadSheet in project easyexcel by alibaba.

the class RepeatTest method hh1.

@Test
public void hh1() throws IOException {
    ExcelReader reader = EasyExcel.read(new FileInputStream("D:\\test\\hg2.xls"), LockData.class, new RepeatListener()).headRowNumber(0).build();
    ReadSheet r2 = EasyExcel.readSheet(0).build();
    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 15 with ReadSheet

use of com.alibaba.excel.read.metadata.ReadSheet in project easyexcel by alibaba.

the class XlsxSaxAnalyser method execute.

@Override
public void execute() {
    for (ReadSheet readSheet : sheetList) {
        readSheet = SheetUtils.match(readSheet, xlsxReadContext);
        if (readSheet != null) {
            xlsxReadContext.currentSheet(readSheet);
            parseXmlSource(sheetMap.get(readSheet.getSheetNo()), new XlsxRowHandler(xlsxReadContext));
            // Read comments
            readComments(readSheet);
            // The last sheet is read
            xlsxReadContext.analysisEventProcessor().endSheet(xlsxReadContext);
        }
    }
}
Also used : ReadSheet(com.alibaba.excel.read.metadata.ReadSheet) XlsxRowHandler(com.alibaba.excel.analysis.v07.handlers.sax.XlsxRowHandler)

Aggregations

ReadSheet (com.alibaba.excel.read.metadata.ReadSheet)20 ExcelReader (com.alibaba.excel.ExcelReader)15 Test (org.junit.Test)6 ExcelWriter (com.alibaba.excel.ExcelWriter)5 WriteSheet (com.alibaba.excel.write.metadata.WriteSheet)5 WriteTable (com.alibaba.excel.write.metadata.WriteTable)3 FileInputStream (java.io.FileInputStream)3 ArrayList (java.util.ArrayList)3 MapCache (com.alibaba.excel.cache.MapCache)2 AnalysisContext (com.alibaba.excel.context.AnalysisContext)2 FileOutputStream (java.io.FileOutputStream)2 SimpleData (com.alibaba.easyexcel.test.core.simple.SimpleData)1 TestFileUtil (com.alibaba.easyexcel.test.util.TestFileUtil)1 EasyExcel (com.alibaba.excel.EasyExcel)1 XlsxRowHandler (com.alibaba.excel.analysis.v07.handlers.sax.XlsxRowHandler)1 ExcelProperty (com.alibaba.excel.annotation.ExcelProperty)1 DateTimeFormat (com.alibaba.excel.annotation.format.DateTimeFormat)1 NumberFormat (com.alibaba.excel.annotation.format.NumberFormat)1 DefaultConverterLoader (com.alibaba.excel.converters.DefaultConverterLoader)1 StringStringConverter (com.alibaba.excel.converters.string.StringStringConverter)1