use of com.alibaba.excel.read.metadata.ReadSheet 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();
}
use of com.alibaba.excel.read.metadata.ReadSheet in project easyexcel by alibaba.
the class BofRecordHandler method processRecord.
@Override
public void processRecord(XlsReadContext xlsReadContext, Record record) {
BOFRecord br = (BOFRecord) record;
XlsReadWorkbookHolder xlsReadWorkbookHolder = xlsReadContext.xlsReadWorkbookHolder();
if (br.getType() == BOFRecord.TYPE_WORKBOOK) {
xlsReadWorkbookHolder.setReadSheetIndex(null);
xlsReadWorkbookHolder.setIgnoreRecord(Boolean.FALSE);
return;
}
if (br.getType() != BOFRecord.TYPE_WORKSHEET) {
return;
}
// Init read sheet Data
initReadSheetDataList(xlsReadWorkbookHolder);
Integer readSheetIndex = xlsReadWorkbookHolder.getReadSheetIndex();
if (readSheetIndex == null) {
readSheetIndex = 0;
xlsReadWorkbookHolder.setReadSheetIndex(readSheetIndex);
}
ReadSheet actualReadSheet = xlsReadWorkbookHolder.getActualSheetDataList().get(readSheetIndex);
assert actualReadSheet != null : "Can't find the sheet.";
// Copy the parameter to the current sheet
ReadSheet readSheet = SheetUtils.match(actualReadSheet, xlsReadContext);
if (readSheet != null) {
xlsReadContext.currentSheet(readSheet);
xlsReadContext.xlsReadWorkbookHolder().setIgnoreRecord(Boolean.FALSE);
} else {
xlsReadContext.xlsReadWorkbookHolder().setIgnoreRecord(Boolean.TRUE);
}
// Go read the next one
xlsReadWorkbookHolder.setReadSheetIndex(xlsReadWorkbookHolder.getReadSheetIndex() + 1);
}
use of com.alibaba.excel.read.metadata.ReadSheet 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++;
}
}
}
use of com.alibaba.excel.read.metadata.ReadSheet 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);
}
}
use of com.alibaba.excel.read.metadata.ReadSheet 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);
}
}
Aggregations