You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
val columnIndexes:Iterable<Int> =if (columns !=null) {
253
-
getColumnIndices(columns)
254
-
} else {
255
-
val headerRow = checkNotNull(sheet.getRow(skipRows)) {
256
-
"Row number ${skipRows +1} (1-based index) is not defined on the sheet ${sheet.sheetName}"
282
+
val columnIndexes:Iterable<Int> =when{
283
+
withDefaultHeader -> {
284
+
val notEmptyRow = sheet.rowIterator().asSequence().find { it !=null }
285
+
checkNotNull(notEmptyRow){
286
+
"There are no defined cells"
287
+
}
288
+
notEmptyRow.firstCellNum until notEmptyRow.lastCellNum
257
289
}
258
-
val firstCellNum = headerRow.firstCellNum
259
-
check(firstCellNum != (-1).toShort()) {
260
-
"There are no defined cells on header row number ${skipRows +1} (1-based index). Pass `columns` argument to specify what columns to read or make sure the index is correct"
290
+
columns !=null-> getColumnIndices(columns)
291
+
else-> {
292
+
val headerRow = checkNotNull(sheet.getRow(skipRows)) {
293
+
"Row number ${skipRows +1} (1-based index) is not defined on the sheet ${sheet.sheetName}"
294
+
}
295
+
val firstCellNum = headerRow.firstCellNum
296
+
check(firstCellNum != (-1).toShort()) {
297
+
"There are no defined cells on header row number ${skipRows +1} (1-based index). Pass `columns` argument to specify what columns to read or make sure the index is correct"
298
+
}
299
+
headerRow.firstCellNum until headerRow.lastCellNum
261
300
}
262
-
headerRow.firstCellNum until headerRow.lastCellNum
263
301
}
264
302
265
-
val headerRow:Row?= sheet.getRow(skipRows)
303
+
val headerRow:Row?=if(withDefaultHeader){
304
+
sheet.shiftRows(0, sheet.lastRowNum, 1)
305
+
sheet.createRow(0)
306
+
}else{
307
+
sheet.getRow(skipRows)
308
+
}
309
+
266
310
val first = skipRows +1
267
311
val last = rowsCount?.let { first + it -1 } ?: sheet.lastRowNum
268
312
val valueRowsRange = (first..last)
@@ -277,7 +321,11 @@ public fun DataFrame.Companion.readExcel(
277
321
?:CellReference.convertNumToColString(index) // Use Excel column names if no data
278
322
}
279
323
280
-
val name = repairNameIfRequired(nameFromCell, columnNameCounters, nameRepairStrategy)
324
+
val name = repairNameIfRequired(
325
+
nameFromCell,
326
+
columnNameCounters,
327
+
if (withDefaultHeader) NameRepairStrategy.MAKE_UNIQUEelse nameRepairStrategy
328
+
)
281
329
columnNameCounters[nameFromCell] =
282
330
columnNameCounters.getOrDefault(nameFromCell, 0) +1// increase the counter for specific column name
0 commit comments