I am downloading .csv files in remote server. It is taking the thousand separator as . instead of ,. How I can rectify this?
First, I would suggest looking at these two questions that have already been answered:
How to read data when some numbers contain commas as thousand separator?
Dealing with commas in a CSV file
I am not sure what you are doing with the exported file, but another option would be to remove the "thousand separator" on the file before exporting it as csv, then reformatting it after you have performed your action.
Related
How to change delimiter semicolon to comma of a file in google sheets or other way? I have already tried text to column feature but my file is too large around 10 MB so it doesn't work.
I have been through that path quite a few times, since business logic likes to use Excel, and software likes CSV.
Excel, and probably Google Sheets etc, are a pain to use for CSV. Especially Excel because it tries to be "friendly" for you, so it typically exports with separators determined by the Windows Locale (ex: ";" or "," ) - and excel usually shifts between quotes and no quotes.
If you HAVE the text file, and wish to IMPORT into excel, find the combination of separators that suits your language variant, using a test file. To convert the big text file, a tool like AWK is simple and awesome.
To EXPORT from Excel, I would again just go with whatever Excel wants to do, then adapt the file after using AWK or similar. Easier for me than trying to find settings for separator and quoting.
There is an article here that I find helpful.
PS: I should mention that in most of European region, CSV IS semicolon by default.
So I have a script in PHP that creates tab separated CSV output.
I have a button in my HTML that works like so:
Export Data
Ideally I want the user to open this CSV file in Excel.
The issue I have here is with tab separated CSVs, the file extension, and how Excel handles all of this. For example:
download="export.csv"
Results in the Browser asking me to open this in Excel (wanted behaviour), but then once in Excel none of the columns are respected as they are tab separated (not comma separated, which Excel is obviously expecting).
download="export.xls"
Results in the Browser asking me to open this in Excel (again, wanted behaviour), but then Excel complains that the file extension and the contents do not match and gives the user a warning. If the user goes past this warning the data displays as expected, but I could do without the warning.
download="export.txt"
Results in the Browser downloading the file as a text file. Once imported into Excel, the columns are respected, but I could do with this being thought of as an Excel file like CSV files are.
download="export.tsv"
Results in the Browser downloading the file, but as this extension isnt recognized, it will need to be imported into Excel manually, which isn't what I am after. Infact, even though TSV is the most correct file extension for tab separated verse, the TXT extension seems to work more smoothly.
I am unable to set file associations on the end users machine, and I would like to avoid going down the "export your data as an actual XLXS file" route if at all possible. I would prefer to use tab separated CSVs over comma separated CSVs because the exported data contains lots of commas naturally.
EDIT:
So as per Ron Rosenfeld suggested I tried outputting a comma separated CSV file with quotes around the data - and the file loads into Excel, with columns preserved - however the quotes appear on every piece of data in every column that uses quotes.
Is it possible to not have the quotes appear?
Ideally I would prefer to have the content tab separated, but at this stage anything that allows me to open a CSV file from a browser into Excel would be great.
I want a way to download a tab separated CSV file from a browser to Excel with as little fuss as possible. How can this be achieved?
The difference between the CSV and TSV files are - as long as the creator followed some rules, that: CSV file will have comma separated values and a TSV file will have tab separated values.
For TXT files, there is no formatting specified.
CSV files are comma-delimited, so you have to use this:
sep=,
And TSV files are tab-delimited, so you have to use this:
sep=\t
If you have MS Excel installed on your computer, CSV files are closely associated with Excel.
Please, look at this post to find out what the use of sep=; for UTF-8 and UTF-16LE leads to.
It's very important to properly output UTF-8 and UTF-16LE CSV files in PHP.
So THIS POST will be informative and useful for you.
CSV means "comma separated values", so the default separator is a ,.
To change that separator to a tab, put
sep=\t
as the first line in your .csv-file (yes, you can still name it .csv). That tells excel what the delimiter character should be.
Note, that if you open the .csv with an actual text editor, it should read like
sep= (an actual tabulator character here, it's just not visible...)
This feature is not officially defined in the .csv RFC 4180, so if it works with any software other than Excel depends on that software's implementation.
I have done this before. A painful experience, which I rather not relive. but since you asked (and bountied).
Make sure your http-headers read: Content-Type: application/x-www-form-urlencoded
Make ; your separator
Don't enclose by " (This is a magic I have yet to understand).
Fingers crossed
I have a medium-sized tab-delimited .txt file - about 40k lines. When I import to Openrefine, line 406 puts all the rest of the content - the whole 40,000 lines, into a single cell in column 13 of that line.
I've tried grep-serching the invisibles in two different text editors (Sublime Text 2 & TextWrangler), and everything looks like it should.
I've also tried using Excel to convert to csv, and that actually works, but:
it's an inelegant workaround,
it has trouble with diacriticals, and
I don't want to spend ay more time resolving it in Excel anyway
I tried excepting the offending line with 10 lines on either side, and that throws the same problem.
Here are those 21 lines, copied directly from TextWrangler. (I can copy from Terminal output if that makes any difference.)
Any help, as always, is very much appreciated!!
Solved It! Well, sort of. It turns out that Column 13 had text that included double-quotes within the text itself (In other words, not having to do with delimiters at all).
For now, I'm just going to remove those quotes in the entire file, which does work - I tested it. **I'd rather figure out how to keep the quotes as part of the text. Tried escaping them with /, but that didn't work.
Thanks SO Community. Especially #Ettore.
I see. The problem is related to the quotations marks. Try importing your file by unchecking "Quotation marks are used to enclose cells containing column separators".
The empty columns in my screenshot are due to the fact that your file sometimes has two or three tabs as a separator. You can delete them easily after import using "reorder / remove columns"
In many EU countries a comma ',' is used as the decimal separator, whereas in the US a dot '.' is used.
CSV (Comma Separated Values) files are supposed to use the comma to separate cell values. However, often a tab '\t' or other characters are used instead.
What's interesting, Excel if you save a .csv file using Microsoft Excel in a EU country using the comma as a decimal separator, the value it uses to separate cell values is not an escaped comma, but a semicolon ';'. Looking on the net it seems that, if you are in the US, Excel will save .csv files using a proper comma (I can't verify this).
I'm trying to find a way to create a csv file that can be recognized by Excel without any user action, both in the EU and the US.
Here's an example using Excel with an Italian locale
The above, saved as .csv (MS-DOS), translates to
foo;foo bar;
foo'bar;"foo""bar";
foo,bar;foo.bar;
foo:bar;"foo;bar";
foo/bar;foo\bar;
"foo
bar";foo|bar;
foo;bar;foobar
this is to make the empty line appear
It may be possible that, depending on the local "list separator", this may not be recognized correctly.
I've read that the new Excel 2013 needs sep=; to be set as the first line in order to work correctly. This is an ugly hack, but it seems to also be working for Excel 2010 (except it gets overwritten on save)...
Does the above text work for you, if you save it as a csv?
Is there a less hacky way to tell Excel which character is the cell separator, without having the user to set things up?
Thanks.
Time to head back to a time before visual anything, and grab a command from the past. It will involve you manually writing the file out with VBA, but it has the criteria you expect: Write
Open "c:\tmp\myfile.csv" for output as #1
for i=1 to 100
write #1,range("A"&i),range("B"&i),range("C"&i)
next i
close #1
You will have to do a little manual work - it doesn't translate a single quote into a double quote, but the rest is as desired:
the Write # statement inserts commas between items and quotation marks around strings as they are written to the file
Numeric data is always written using the period as the decimal separator.
Dates are written as #yyyy-mm-dd hh:mm:ss#
For example, I have the following:
fname;lname;email
...and it's all in one box.
I would like it to be separated in different boxes, like:
fname lname email
How can I do this?
Got it silly me,
use go to data, form data, delimited with semicolons
:)
figured it a 30 sec after post
How is this related to programming?
Anyway you can just open CSV files in Excel. It supports the CSV format as well. You might only need to specify the separator character. Sometimes it's the semicolon ;, sometimes it's the comma ,.
They need to be separated by commas (comma delimited) not semi-colons.
e.g. fname, lname, email
Quotes around text fields wouldn't hurt either.