From ae3e39d522e708d6317f372ff4c8fc1f5c215fb4 Mon Sep 17 00:00:00 2001 From: Ramesh Babu Date: Sat, 18 Feb 2023 13:22:49 +0530 Subject: [PATCH] #165 Removed ExcelReader.java --- .../io/github/selcukes/excel/ExcelReader.java | 80 ------------------- 1 file changed, 80 deletions(-) delete mode 100644 selcukes-excel-runner/src/main/java/io/github/selcukes/excel/ExcelReader.java diff --git a/selcukes-excel-runner/src/main/java/io/github/selcukes/excel/ExcelReader.java b/selcukes-excel-runner/src/main/java/io/github/selcukes/excel/ExcelReader.java deleted file mode 100644 index e8e851a68..000000000 --- a/selcukes-excel-runner/src/main/java/io/github/selcukes/excel/ExcelReader.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) Ramesh Babu Prudhvi. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.github.selcukes.excel; - -import io.github.selcukes.commons.config.ConfigFactory; -import io.github.selcukes.commons.exception.ExcelConfigException; -import io.github.selcukes.databind.utils.Streams; -import org.apache.poi.ss.usermodel.CellType; -import org.apache.poi.ss.usermodel.DataFormatter; -import org.apache.poi.ss.usermodel.FormulaEvaluator; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.ss.usermodel.Workbook; -import org.apache.poi.ss.usermodel.WorkbookFactory; - -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -public class ExcelReader { - private final Workbook workbook; - - public ExcelReader(String fileName) { - this.workbook = getWorkBook(fileName); - } - - private Workbook getWorkBook(String fileName) { - try (Workbook wb = WorkbookFactory.create(Objects.requireNonNull(ConfigFactory.getStream(fileName)))) { - return wb; - } catch (Exception e) { - throw new ExcelConfigException("Failed reading excel file : " + fileName); - } - } - - public Stream getAllSheets() { - return Streams.of(workbook.iterator()); - } - - public Map>> getAllSheetsDataMap() { - return getAllSheets().collect(Collectors.toMap(Sheet::getSheetName, this::getSheetData)); - } - - public List> getSheetData(Sheet sheet) { - return Streams.of(sheet.iterator()) - .map(this::getRowData) - .collect(Collectors.toList()); - } - - private List getRowData(Row row) { - DataFormatter df = new DataFormatter(); - FormulaEvaluator formulaEvaluator = workbook.getCreationHelper().createFormulaEvaluator(); - return Streams.of(row.iterator()) - .map(cell -> { - if (cell == null) { - return ""; - } else if (cell.getCellType().equals(CellType.FORMULA)) { - return df.formatCellValue(cell, formulaEvaluator); - } else { - return df.formatCellValue(cell); - } - }).collect(Collectors.toList()); - } - -}