spreadsheet-cfml icon indicating copy to clipboard operation
spreadsheet-cfml copied to clipboard

ReadCsv with no headers = empty columns array

Open Daemach opened this issue 1 year ago • 1 comments
trafficstars

When using the read() method, and I don't provide headers and don't specify that the first row is headers, the library returns a query with columns named column1, etc That is convenient syntax to work with and makes the code more readable. When using readLargeFile and returning a struct, it would be great if you could do the same thing with the columns array.

Daemach avatar Feb 16 '24 16:02 Daemach

I think you're talking about readCsv() rather than readLargeFile().

The read() method does that because a query must have column names. readCsv() returns an array of arrays which doesn't require them. If you don't specify them then I think it's right that columns should be empty. If you want to add them you can using the withHeader() method:

spreadsheet.readCsv( path )
  .intoAnArray()
  .withHeader( [ "column1", "column2", "column3" ] )
  .execute();

The header values don't have to appear in the CSV, they will still be used if not present.

cfsimplicity avatar Feb 19 '24 15:02 cfsimplicity