@@ -277,7 +277,7 @@ object ExcelMacros:
277277 end if
278278 case CellType .NUMERIC =>
279279 if DateUtil .isCellDateFormatted(cell) then
280- // Dates are represented as strings for consistency with CSV behavior
280+ // TODO: Dates are represented as strings for consistency with CSV behavior
281281 info.copy(
282282 couldBeInt = false ,
283283 couldBeLong = false ,
@@ -353,68 +353,4 @@ object ExcelMacros:
353353 end if
354354 end inferColumnTypeFromCells
355355
356- /** Helper function to perform type inference on Excel data and return the inferred TypeRepr (legacy CSV-based approach)
357- */
358- private def inferTypesFromExcelData (using
359- Quotes
360- )(
361- filePath : String ,
362- sheetName : String ,
363- colRange : Option [String ],
364- headers : List [String ],
365- numRows : Int ,
366- preferIntToBoolean : Boolean
367- ): quotes.reflect.TypeRepr =
368-
369- // Extract sample rows for type inference
370- val sampleRows = extractSampleRows(filePath, sheetName, colRange, numRows, headers.length)
371-
372- // Convert rows to properly escaped CSV format for the InferrerOps
373- def escapeCsvField (field : String ): String =
374- if field.contains(" ," ) || field.contains(" \" " ) || field.contains(" \n " ) then " \" " + field.replace(" \" " , " \"\" " ) + " \" "
375- else field
376-
377- val csvRows = sampleRows.map(_.map(escapeCsvField).mkString(" ," ))
378- val rowsIterator = csvRows.iterator
379-
380- // Use InferrerOps to infer types
381- InferrerOps .inferrer(rowsIterator, preferIntToBoolean, numRows)
382- end inferTypesFromExcelData
383-
384- /** Extracts sample data rows from an Excel sheet for type inference
385- */
386- private def extractSampleRows (filePath : String , sheetName : String , colRange : Option [String ], numRows : Int , numColumns : Int ): List [List [String ]] =
387- val workbook = WorkbookFactory .create(new File (filePath))
388- try
389- val sheet = workbook.getSheet(sheetName)
390- val sheetIterator = sheet.iterator().asScala
391-
392- // Skip header row
393- if sheetIterator.hasNext then sheetIterator.next()
394- end if
395-
396- val sampleRows = sheetIterator.take(numRows).toList
397-
398- colRange match
399- case Some (range) if range.nonEmpty =>
400- val cellRange = CellRangeAddress .valueOf(range)
401- val firstCol = cellRange.getFirstColumn
402- val lastCol = cellRange.getLastColumn
403- sampleRows.map { row =>
404- (firstCol to lastCol).map { i =>
405- row.getCell(i, Row .MissingCellPolicy .CREATE_NULL_AS_BLANK ).toString
406- }.toList
407- }
408- case _ =>
409- sampleRows.map { row =>
410- // Ensure we extract exactly numColumns to match headers
411- (0 until numColumns).map { i =>
412- row.getCell(i, Row .MissingCellPolicy .CREATE_NULL_AS_BLANK ).toString
413- }.toList
414- }
415- end match
416- finally workbook.close()
417- end try
418- end extractSampleRows
419-
420356end ExcelMacros
0 commit comments