Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadCsv with no headers = empty columns array #362

Open
Daemach opened this issue Feb 16, 2024 · 1 comment
Open

ReadCsv with no headers = empty columns array #362

Daemach opened this issue Feb 16, 2024 · 1 comment

Comments

@Daemach
Copy link

Daemach commented Feb 16, 2024

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
Copy link
Owner

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 cfsimplicity changed the title ReadLargeFile with no headers = empty columns array ReadCsv with no headers = empty columns array Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants