@@ -112,7 +112,16 @@ public fun DataFrame.Companion.readExcel(
112
112
setWorkbookTempDirectory()
113
113
val wb = WorkbookFactory .create(url.openStream())
114
114
return wb.use {
115
- readExcel(wb, sheetName, skipRows, columns, stringColumns?.toFormattingOptions(), rowsCount, nameRepairStrategy, withDefaultHeader)
115
+ readExcel(
116
+ wb,
117
+ sheetName,
118
+ skipRows,
119
+ columns,
120
+ stringColumns?.toFormattingOptions(),
121
+ rowsCount,
122
+ nameRepairStrategy,
123
+ withDefaultHeader,
124
+ )
116
125
}
117
126
}
118
127
@@ -143,7 +152,16 @@ public fun DataFrame.Companion.readExcel(
143
152
setWorkbookTempDirectory()
144
153
val wb = WorkbookFactory .create(file)
145
154
return wb.use {
146
- readExcel(it, sheetName, skipRows, columns, stringColumns?.toFormattingOptions(), rowsCount, nameRepairStrategy, withDefaultHeader)
155
+ readExcel(
156
+ it,
157
+ sheetName,
158
+ skipRows,
159
+ columns,
160
+ stringColumns?.toFormattingOptions(),
161
+ rowsCount,
162
+ nameRepairStrategy,
163
+ withDefaultHeader,
164
+ )
147
165
}
148
166
}
149
167
@@ -172,7 +190,17 @@ public fun DataFrame.Companion.readExcel(
172
190
rowsCount : Int? = null,
173
191
nameRepairStrategy : NameRepairStrategy = NameRepairStrategy .CHECK_UNIQUE ,
174
192
withDefaultHeader : Boolean = false,
175
- ): AnyFrame = readExcel(asURL(fileOrUrl), sheetName, skipRows, columns, stringColumns, rowsCount, nameRepairStrategy, withDefaultHeader)
193
+ ): AnyFrame =
194
+ readExcel(
195
+ asURL(fileOrUrl),
196
+ sheetName,
197
+ skipRows,
198
+ columns,
199
+ stringColumns,
200
+ rowsCount,
201
+ nameRepairStrategy,
202
+ withDefaultHeader,
203
+ )
176
204
177
205
/* *
178
206
* @param sheetName sheet to read. By default, the first sheet in the document
@@ -201,7 +229,16 @@ public fun DataFrame.Companion.readExcel(
201
229
setWorkbookTempDirectory()
202
230
val wb = WorkbookFactory .create(inputStream)
203
231
return wb.use {
204
- readExcel(it, sheetName, skipRows, columns, stringColumns?.toFormattingOptions(), rowsCount, nameRepairStrategy, withDefaultHeader)
232
+ readExcel(
233
+ it,
234
+ sheetName,
235
+ skipRows,
236
+ columns,
237
+ stringColumns?.toFormattingOptions(),
238
+ rowsCount,
239
+ nameRepairStrategy,
240
+ withDefaultHeader,
241
+ )
205
242
}
206
243
}
207
244
@@ -279,15 +316,17 @@ public fun DataFrame.Companion.readExcel(
279
316
nameRepairStrategy : NameRepairStrategy = NameRepairStrategy .CHECK_UNIQUE ,
280
317
withDefaultHeader : Boolean = false,
281
318
): AnyFrame {
282
- val columnIndexes: Iterable <Int > = when {
319
+ val columnIndexes: Iterable <Int > = when {
283
320
withDefaultHeader -> {
284
321
val notEmptyRow = sheet.rowIterator().asSequence().find { it != null }
285
- checkNotNull(notEmptyRow){
322
+ checkNotNull(notEmptyRow) {
286
323
" There are no defined cells"
287
324
}
288
325
notEmptyRow.firstCellNum until notEmptyRow.lastCellNum
289
326
}
327
+
290
328
columns != null -> getColumnIndices(columns)
329
+
291
330
else -> {
292
331
val headerRow = checkNotNull(sheet.getRow(skipRows)) {
293
332
" Row number ${skipRows + 1 } (1-based index) is not defined on the sheet ${sheet.sheetName} "
@@ -300,10 +339,10 @@ public fun DataFrame.Companion.readExcel(
300
339
}
301
340
}
302
341
303
- val headerRow: Row ? = if (withDefaultHeader){
342
+ val headerRow: Row ? = if (withDefaultHeader) {
304
343
sheet.shiftRows(0 , sheet.lastRowNum, 1 )
305
344
sheet.createRow(0 )
306
- }else {
345
+ } else {
307
346
sheet.getRow(skipRows)
308
347
}
309
348
@@ -324,7 +363,7 @@ public fun DataFrame.Companion.readExcel(
324
363
val name = repairNameIfRequired(
325
364
nameFromCell,
326
365
columnNameCounters,
327
- if (withDefaultHeader) NameRepairStrategy .MAKE_UNIQUE else nameRepairStrategy
366
+ if (withDefaultHeader) NameRepairStrategy .MAKE_UNIQUE else nameRepairStrategy,
328
367
)
329
368
columnNameCounters[nameFromCell] =
330
369
columnNameCounters.getOrDefault(nameFromCell, 0 ) + 1 // increase the counter for specific column name
0 commit comments