From 1f98caf69651b82fc3f710bc452a1324fd5c8082 Mon Sep 17 00:00:00 2001 From: Max Stephan Date: Tue, 5 Sep 2023 14:59:59 +0200 Subject: [PATCH] refactor(core): fix klint errors --- .../excel/result/ExcelCheckerResultData.kt | 2 +- .../v2/spreadsheet/SpreadsheetEvaluator.kt | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 modules/fbs-core/api/src/main/kotlin/de/thm/ii/fbs/utils/v2/spreadsheet/SpreadsheetEvaluator.kt diff --git a/modules/fbs-core/api/src/main/kotlin/de/thm/ii/fbs/model/v2/checker/excel/result/ExcelCheckerResultData.kt b/modules/fbs-core/api/src/main/kotlin/de/thm/ii/fbs/model/v2/checker/excel/result/ExcelCheckerResultData.kt index f68c606be..1a62f7d79 100644 --- a/modules/fbs-core/api/src/main/kotlin/de/thm/ii/fbs/model/v2/checker/excel/result/ExcelCheckerResultData.kt +++ b/modules/fbs-core/api/src/main/kotlin/de/thm/ii/fbs/model/v2/checker/excel/result/ExcelCheckerResultData.kt @@ -70,7 +70,7 @@ data class CellResultData( @get:JsonIgnore // Not return this information to the user val formula: String?, @get:JsonIgnore // Not return this information to the user - val solution: Cell?, + val solution: Cell? ) { constructor(cell: Cell, cellResult: CellResult?) : this( cell.cell, diff --git a/modules/fbs-core/api/src/main/kotlin/de/thm/ii/fbs/utils/v2/spreadsheet/SpreadsheetEvaluator.kt b/modules/fbs-core/api/src/main/kotlin/de/thm/ii/fbs/utils/v2/spreadsheet/SpreadsheetEvaluator.kt new file mode 100644 index 000000000..05f543e00 --- /dev/null +++ b/modules/fbs-core/api/src/main/kotlin/de/thm/ii/fbs/utils/v2/spreadsheet/SpreadsheetEvaluator.kt @@ -0,0 +1,28 @@ +package de.thm.ii.fbs.utils.v2.spreadsheet + +import org.apache.poi.ss.usermodel.CellType +import org.apache.poi.ss.usermodel.FormulaEvaluator +import org.apache.poi.ss.usermodel.Workbook +import org.slf4j.LoggerFactory + +class SpreadsheetEvaluator { + companion object { + private val logger = LoggerFactory.getLogger(SpreadsheetEvaluator::class.java) + + fun evaluateAll(workbook: Workbook, evaluator: FormulaEvaluator) { + for (sheet in workbook.sheetIterator()) { + for (row in sheet.rowIterator()) { + for (cell in row.cellIterator()) { + if (cell.cellType == CellType.FORMULA) { + try { + evaluator.evaluateFormulaCell(cell) + } catch (e: Exception) { + // Ignore Evaluation errors + } + } + } + } + } + } + } +} \ No newline at end of file