com.github.kunalk16.excel.model.factory.ExcelWorkBook Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lightExcelReader Show documentation
Show all versions of lightExcelReader Show documentation
A lightweight Java framework to read .xlsx excel files.
The newest version!
package com.github.kunalk16.excel.model.factory;
import com.github.kunalk16.excel.model.user.Cell;
import com.github.kunalk16.excel.model.user.Sheet;
import com.github.kunalk16.excel.model.user.WorkBook;
import java.util.*;
public class ExcelWorkBook implements WorkBook {
private final Map sheetByName;
private final List sheetList;
private final Map cellLocationByName;
public ExcelWorkBook(Map sheetByName, Map cellLocationByName) {
this.sheetByName = sheetByName;
this.sheetList = Collections.unmodifiableList(new ArrayList<>(this.sheetByName.values()));
this.cellLocationByName = cellLocationByName;
}
@Override
public Sheet getSheet(int index) {
return this.sheetList.get(index);
}
@Override
public Sheet getSheet(String sheetName) {
return this.sheetByName.get(sheetName);
}
@Override
public Collection getSheets() {
return this.sheetByName.values();
}
@Override
public Cell getCellByDefinedName(String definedName) {
if (!this.cellLocationByName.containsKey(definedName)) {
return null;
}
return Optional.of(this.cellLocationByName.get(definedName))
.filter(cellLocation -> Objects.nonNull(this.getSheet(cellLocation.getSheetName())))
.map(cellLocation -> this.getSheet(cellLocation.getSheetName())
.getCell(cellLocation.getRow(), cellLocation.getColumn()))
.orElse(null);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy