-1

If you have a single block of data, creating a table with fputcsv works great; it assumes the first row is a header and the following rows are of the same format.

But what do you do if you have multiple, differently formatted blocks of data you want to write out to a CSV:

Business Name: name-of-business.   Date: current date

Notes: single line of notes


Model | Product 
model1 | Product 1
model2 | Product 2
model3 | Product 3

The first line is basically a single line table with 4 columns and no headers The second line is a single line table with 2 columns and no headers Then the data - typical two column table with headers

Scott C Wilson
  • 19,102
  • 10
  • 61
  • 83
  • 2
    Then your code that reads and processes that info needs to be a lot more carefully written. Simple, there is no Magic bullet – RiggsFolly May 10 '22 at 11:57
  • _"The first line is basically a single line table with 4 columns and no headers"_ - so pass an array containing four values to write into four different cells to `fputcsv` then. _"The second line is a single line table with 2 columns and no headers"_ - so pass an array containing two values to write into two different cells to `fputcsv` then. – CBroe May 10 '22 at 11:57
  • 1
    You'd then have your own propitary definition of a CSV... it's not what I would expect from a CSV though, so don't blame on others if they can't understand your CSV :) – Honk der Hase May 10 '22 at 12:04
  • Agreed, this is a very unconventional CSV layout – ADyson May 10 '22 at 12:21
  • I was hoping there was a string that would be interpreted as "stop table" or "start table" but I guess not. – Scott C Wilson May 10 '22 at 12:30
  • CSV has a RFC, there's nothing more to expect from CSV than what's commented there I guess. – Honk der Hase May 10 '22 at 12:39
  • 1
    @HonkderHase please make an answer out of your comment, which seems to be the bottom line. I was hoping there was a way to indicate to Excel that multiple separate tables were included in the CSV but this doesn't seem possible. – Scott C Wilson May 11 '22 at 16:09

1 Answers1

0

As requested:

But what do you do if you have multiple, differently formatted blocks of data you want to write out to a CSV:

You'd then have your own propitary definition of a CSV... it's not what I would expect from a CSV though, so don't blame on others if they can't understand your CSV :)

CSV has a RFC, there's nothing more to expect from CSV than what's commented there I guess.

Honk der Hase
  • 2,459
  • 1
  • 14
  • 26