cfsimplicity / spreadsheet-cfml

Standalone library for working with spreadsheets and CSV in CFML
MIT License
126 stars 35 forks source link

ReadCsv with no headers = empty columns array #362

Open Daemach opened 7 months ago

Daemach commented 7 months ago

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.

cfsimplicity commented 6 months ago

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.