News for hackers. Stuff that matters.
Re:A straightforward way to extend CSV with metadata by 41209 on Thursday August 19, 2021 @12:14PM (#28235691)
Am I insane here, or does Excel generally do a very good job of handling almost all CSV files.

I don't really see a need for a metadata file, nor would I ever see Excel or other tools accepting it. The main problem is adoption, CSV isn't perfect but it's what we have. Now if you wrote this as a member of the Excel team at Microsoft, and then Excel had the option of exporting CSV files with a metadata file, then I'd be a bit more excited.

Re:A straightforward way to extend CSV with metadata by VenTatsu on Thursday August 19, 2021 @01:06PM (#28236386)
Excel does a fairly bad job when moving data between two computers that aren't configured the same way, which kind of defeats the purpose of using a data interchange format.

Where I work we have offices in the US, and in Europe where installing a localized version of windows will swap ',' and '.' when used as the group and decimal separator. Excel when loading a value 100,002 in the US will see one hundred thousand and two, in some parts of Europe it will see one hundred and 2 thousandths.

Character set handing can be just as bad, there is no good way to get Excel to auto open a CSV file as UTF-8 that won't break every other CSV parser in existence. The only cross platform option is ASCII. Excel will happily load your local OS encoding, likely some variant of ISO-8859, but any other encoding requires jumping through hoops.

Re:A straightforward way to extend CSV with metadata by Tagbert on Thursday August 19, 2021 @12:27PM (#28235859)
Excel has some major problems with CSV ingestion though I don’t think that this proposal will address those problems.

Here are a couple of cases that I run into frequently:

* Excel is very aggressive about forcing type conversion based on its own assumptions. It will convert strings to dates or numbers, even if data is lost in the process. It will ignore quotes to convert long numeric IDs into scientific notation which truncates the ID unrecoverable.

* Excel cannot deal with quoted strings containing line breaks. It treats them as separate records and you get truncated records and partial records on separate rows.

Re:A straightforward way to extend CSV with metadata by mark-r on Thursday August 19, 2021 @11:05PM (#28242042)
My two favorite problems with Excel automatic type conversions:

Zip codes that lose leading zeros.

Gene names that get converted to dates. The names of some genes were recently changed because too many databases were being corrupted by researchers using Excel to read CSV files: https://www.theverge.com/2020/8/6/21355674/human-genes-renam...

Re:A straightforward way to extend CSV with metadata by IanCal on Thursday August 19, 2021 @12:29PM (#28235877)
Excel does an atrocious job of handling CSV files. It regularly alters data, messes up encodings and either can't or couldn't (I haven't checked in a few years) open CSV files that start with a capital letter I.

Source: dealing with CSV files people exported from Excel and the horrors that flowed from there.

Re:A straightforward way to extend CSV with metadata by bitwize on Thursday August 19, 2021 @01:09PM (#28236442)
> either can't or couldn't (I haven't checked in a few years) open CSV files that start with a capital letter I.

It can't do this because it confuses such files with files in SYLK format, which was YET ANOTHER attempt to standardize spreadsheet data interchange, dating from the 80s.

Re:A straightforward way to extend CSV with metadata by IanCal on Thursday August 19, 2021 @03:14PM (#28238050)
What I find incredible about this is that it decides that the file ending ".CSV" must not be a CSV file but SYLK. Then loading it as SYLK fails, and it doesn't then try and load it as a CSV file instead.
Re:A straightforward way to extend CSV with metadata by swader999 on Thursday August 19, 2021 @12:45PM (#28236109)
I've donated hours of my life to resolving excel corrupted csv files. They haven't been satisfying hours.
Re:A straightforward way to extend CSV with metadata by IanCal on Thursday August 19, 2021 @03:22PM (#28238153)
Same. If it helps, the python package ftfy can fix a lot of encoding issues.
Re:A straightforward way to extend CSV with metadata by swader999 on Thursday August 19, 2021 @05:16PM (#28239475)
It's tempting to consider different languages...
Re:A straightforward way to extend CSV with metadata by 41209 on Thursday August 19, 2021 @01:52PM (#28237020)
Does any widely used application do it better.

I always view CSV as a lowest common denominator, of course more precise formats exist, but not everyone can use those. Csvs normally get the job done, but like anything else you need to know it's limitations. Something like a basic phone book should work, your scientific data, with dozens upon dozens of floating point numbers may not work.

Re:A straightforward way to extend CSV with metadata by IanCal on Thursday August 19, 2021 @03:21PM (#28238132)
These are not limitations of CSV files, that's excel. Not being able to open a csv file starting with the letter I has nothing to do with CSV as a format.

There just aren't that many widely used applications that deal with things like this, but Google sheets seems to be the obvious one.

Re:A straightforward way to extend CSV with metadata by capeterson on Thursday August 19, 2021 @02:57PM (#28237818)
LibreOffice is generally a little less aggressive about formatting, but still has issues similar to Excel.

For me personally, I usually view things in Excel/LO but don't save, and if I need to modify anything I'll use a text editor for one-off changes, or I'll use something like Python with the pandas library for more programmatic changes. Pandas does have issues forcing timestamps to convert sometimes, but that can be easily configured. Otherwise, no problems with this method.

There's definitely a lot of friction if you want to edit .CSV's without your formatting/encoding being altered, unfortunately.

Re:A straightforward way to extend CSV with metadata by munk-a on Thursday August 19, 2021 @06:24PM (#28240120)
I much prefer ingesting CSVs into LibreOffice since it's a lot more upfront about what encoding it's going to try and use and the delimiter it has chosen - and those choices are extremely easy to modify and flexible. Excel also has a habit of utterly clobbering character encoding on export - once you start seeing umlauts and cedillas in your text you'll notice that Excel has a really bad habit of chosen latin-1.
Re:A straightforward way to extend CSV with metadata by capeterson on Thursday August 19, 2021 @08:23PM (#28240978)
Yeah I suppose that's the crux of it. I really like that first popup that LibreOffice has when you open it up where you can specify encoding, delimiters, etc.

LibreOffice does a similar amount of clobbering, but in general it notifies you of any would-be clobbering and allows you to abort beforehand, which is really nice. I still avoid exporting via LibreOffice though for very sensitive situations, but it is noticeably better still.

Re:A straightforward way to extend CSV with metadata by pbreit on Thursday August 19, 2021 @04:48PM (#28239192)
Google Sheets handles CSVs MUCH better.
Re:A straightforward way to extend CSV with metadata by jpeloquin on Thursday August 19, 2021 @05:03PM (#28239333)
> Am I insane here, or does Excel generally do a very good job of handling almost all CSV files.

If the user does Data > From Text/CSV > Transform > use PowerQuery to set the first row as the header, I think it's true that Excel does a good job. It provides the basics at least: configurable charset and column type detection. When the user re-saves to CSV, I'm not aware of any way to configure the output (e.g., force quotation of text content), but that's sort of ok.

The easy path—double clicking on a CSV file or using File > Open—is where all the weird auto-conversion of values happens. But other posts have covered that part.

Re:A straightforward way to extend CSV with metadata by awild on Thursday August 19, 2021 @01:23PM (#28236664)
Excel will strip leading zeros of your data, even when you're escaping it, it will also assume that that single cell of a Column of dot-separated floats is in fact a date. Excel is in fact so good at detecting formats that even if you construct an xls fill it with ids which partially start with zeros, properly mark them as strings, it will still nag you at every single cell of your file that there is something fishy about the file.
Re:A straightforward way to extend CSV with metadata by pbreit on Thursday August 19, 2021 @04:50PM (#28239209)
The stripping of leading zeroes is dreadful when working with zip codes and SSNs.
Re:A straightforward way to extend CSV with metadata by isoprophlex on Thursday August 19, 2021 @12:39PM (#28236015)
No, excel does about the worst possible job of handling CSVs.

You can't even hope to keep a file intact upon opening...

Re:A straightforward way to extend CSV with metadata by pbreit on Thursday August 19, 2021 @04:46PM (#28239176)
You are insane :-).

Excel has the most inexplicably horrific handling of long number strings that it is borderline unusable.

https://excel.uservoice.com/forums/304921-excel-for-windows-...