Skip to content

Commit c7f159b

Browse files
committed
chore: Add recursive call instead of listing all cellTypes
1 parent 6c09571 commit c7f159b

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

dataframe-excel/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/xlsx.kt

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,9 @@ private fun repairNameIfRequired(
278278
}
279279
}
280280

281-
private fun Cell?.cellValue(sheetName: String): Any? =
282-
when (this?.cellType) {
281+
private fun Cell?.cellValue(sheetName: String): Any? {
282+
if (this == null) return null
283+
fun getValueFromType(type: CellType?): Any? = when (type) {
283284
CellType._NONE -> error("Cell $address of sheet $sheetName has a CellType that should only be used internally. This is a bug, please report https://github.com/Kotlin/dataframe/issues")
284285
CellType.NUMERIC -> {
285286
val number = numericCellValue
@@ -290,19 +291,14 @@ private fun Cell?.cellValue(sheetName: String): Any? =
290291
}
291292

292293
CellType.STRING -> stringCellValue
293-
CellType.FORMULA -> when (this.cachedFormulaResultType) {
294-
CellType.NUMERIC -> numericCellValue
295-
CellType.STRING -> stringCellValue
296-
CellType.BOOLEAN -> booleanCellValue
297-
CellType.ERROR -> errorCellValue
298-
else -> null
299-
}
300-
294+
CellType.FORMULA -> getValueFromType(cachedFormulaResultType)
301295
CellType.BLANK -> stringCellValue
302296
CellType.BOOLEAN -> booleanCellValue
303297
CellType.ERROR -> errorCellValue
304298
null -> null
305299
}
300+
return getValueFromType(cellType)
301+
}
306302

307303
public fun <T> DataFrame<T>.writeExcel(
308304
path: String,

dataframe-excel/src/test/kotlin/org/jetbrains/kotlinx/dataframe/io/XlsxTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,6 @@ class XlsxTest {
125125
@Test
126126
fun `read xlsx file that has cells with formulas that return numbers and strings`() {
127127
val df = DataFrame.readExcel(testResource("formula_cell.xlsx"))
128-
df.columnNames() shouldBe listOf("Number", "Greather than 5", "Multiplied by 10", "Divide by 5")
128+
df.columnNames() shouldBe listOf("Number", "Greater than 5", "Multiplied by 10", "Divided by 5")
129129
}
130130
}
2 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)