diff --git a/src/main.tsx b/src/main.tsx index f5e6514..c87d616 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -437,9 +437,9 @@ const TYPE_PATTERNS: { type: ColumnType; pattern: RegExp }[] = [ { type: 'number', pattern: /^[+-]?[\d,]+\.?\d*$/ }, ]; -function detectColumnType(rows: string[][], colIndex: number): ColumnType { +function detectColumnTypeFrom(rows: string[][], colIndex: number, start: number): ColumnType { const samples: string[] = []; - for (let i = 0; i < rows.length && samples.length < TYPE_DETECTION_SAMPLE_SIZE; i++) { + for (let i = start; i < rows.length && samples.length < TYPE_DETECTION_SAMPLE_SIZE; i++) { const val = (rows[i][colIndex] || '').trim(); if (val !== '' && val !== '--' && val !== 'N/A' && val !== 'n/a') samples.push(val); } @@ -451,6 +451,13 @@ function detectColumnType(rows: string[][], colIndex: number): ColumnType { return 'string'; } +// With "1st Row = Header" off, row 0 is the header text and outvotes sparse columns +// (one value plus "--" everywhere else), so retry without it before giving up +function detectColumnType(rows: string[][], colIndex: number): ColumnType { + const type = detectColumnTypeFrom(rows, colIndex, 0); + return type === 'string' && rows.length > 1 ? detectColumnTypeFrom(rows, colIndex, 1) : type; +} + const SUFFIX_MULTIPLIERS: Record = { 'K': 1e3, 'M': 1e6, 'B': 1e9, 'T': 1e12 }; function extractSortValue(cellValue: string, colType: ColumnType): number | string | null { @@ -977,7 +984,7 @@ const ColumnHeader: React.FC<{ {header}