How to import CSV-file with Microsoft Excel 2016? - excel

I try to import a CSV-file in Excel. The program has funny default properties. It puts the content of the rows all in one column including the commas. Lets say the file content is (test.csv):
1, 2, 3
4, 5, 6
What I expect Excel to do is to put each number into a separate field using the comma as separators. However, the excel table has only two fields each containing 3 numbers including the commas, something like this (not what I want):
"1, 2, 3"
"4, 5, 6"
What do I have to change in Excel settings so that it does this standard task correctly?

You are probably not importing the CSV but instead opening it either double clicking or using the open dialog.
One of the correct ways of importing a CSV into Excel is using Data | From Text/CSV menu. This way you will be able to select the delimiters, change data types if you need etc.

Importing CSV via Data | From Text is -- altough working -- rather cumbersome: You need to select the file, the wizard asks about "Delimited" or "Fixed width", then you need to select "Comma" as seperator and finally how to import the data. And when you want to reimport later on the whole procedure starts again and again and again ..
Instead use Data | New Query | From File | From CSV and select the file to import from. I still had to adjust the encoding to UTF-8 while other settings are correctly detected (delimited by comma).
The really great advantage is that you have to do this only once as the above procedure creates a so called "workbook query". To update or reimport just click "Refresh" in the workbook query's context menu.

Depending of the configuration of Excel, the CSV files can be separated with "," or ";". To open a CSV file it's better to go to file-->open file-->text. There Excel asks you for the way you want to separate your fields in CSV.
Regards

Related

Is there a way to retain the phone numbers with + sign format when exporting to Excel/CSV

I noticed that anytime I export from somewhere like Salesforce where the Phone = +123124141.
The data in Excel will just become =123124141 or #NAME? or some other Error spouted from Excel.
This makes data patch extremely painful and manual. Any ideas how to get around this?
When you create the file, use a different extension than .csv or .txt (these ones are interpreted by EXCEL as a green light to interpret columns as numeric/date, etc and format accordingly. Use .DAT, for example. When you open it from within EXCEL it will invoke the text import wizard, and there you should choose comma separated (or tab separated, etc, as the case maybe), and on the final screen of the wizard, choose the columns you don't want reformatted (you can choose all of them, if you like), and choose Text. Now the column values will be kept intact.
Alternatively you can first create a blank workbook/sheet, and use Data From Text to invoke the Wizard and bring the data in the same way.
If you don't want EXCEL to launch and open when you double-click on a .CSV file, without asking questions, you can remove the file-association (of CSV with EXCEL) using Windows explorer.
It is reasonably easy to develop a VBA macro to import such delimited files using 'TEXT' data types to automate what the Wizard would do.

Export Excel data with a custom deliminator in .csv

I want to export a huge excel file as a .csv, but the data contains commas within the cells.
How do I export the excel data to a .csv with the deliminator as this |
I've tried doing the usual "save as", but it is not working for my data.
Hi Check out this method in the below link, its what I have used in the past
https://www.howtogeek.com/howto/21456/export-or-save-excel-files-with-pipe-or-other-delimiters-instead-of-commas/
Summary:
Control Panel –> Region and Language, and then click the Additional settings
When in the additional settings find “List separator”
Change this to anything you want, in your case you would want the | pipe
By definition CSV stands for Comma Delimited.
Easy alternatives that were under your nose in the Save As window are:
"Formatted Text(Space Delimited)" though this won't be appropriate if you have spaces in your cells
"Text(Tab Delimited)" it is less likely you'll have tabs in your cells and people won't type those in to excel.
If you really want the 'pipe' | then I would suggest saving as tab delimited and running some kind of find & replace on the resulting text file. This is a bit of a workaround
A even bigger workaround is to concatenate the cells using a formula on the sheet with a | involved and the save as text only that column.

Importing CSV into Excel: import wizard fails to recognize text qualifier but opening directly in Excel converts to scientific notation

I receive a csv file periodically from a database download and I cannot change the way this csv file is produced. I need to convert it to an Excel file to pass it on to an external partner. There are two fields causing trouble in the csv file when I import into Excel: a permit number which is actually a character string, and a location description which can contain commas and other punctuation.
If I right click on the csv file and select Open With Excel, the location description is imported correctly but some permit numbers are converted to scientific notation.
Alternatively, if I use the text import wizard in Excel, I can import the permit numbers as text, but the location description ends up being split across multiple cells even when I set the text qualifier to ".
Here is a simplified example of the data as it appears in the csv file:
id, "Permit Number", Species, Longitude, "Location Details"
1, 2F66-16, DE, -120.0001, "near a road, in woods (FR16)"
2, 678E-15, DE, -120.0002, "near milepost 65, north side of road"
Is there a solution that will allow me to import both fields correctly? This question is very similar but has no answers:
excel text importing: wizard vs opening a file within Explorer
Thanks for any help.
Update: I think the Location Description is being split into multiple cells because of line breaks in the csv. I'm not sure how these are being generated or how to remove them or deal with them, but when I open the file in Excel, the line breaks are still there (although the entire location description is in one cell). Unfortunately I can't post the full example data because it is sensitive data not easily converted to dummy data. Any thoughts on how to remove line breaks from a csv file?
For whatever reason, Excel doesn't seem to like spaces between the comma and the quote. If you do a global find and replace on your input data (change comma-space-quote to comma-quote) -- and then parse your data, it will honor the text qualifiers as you need.
id, "Permit Number", Species, Longitude, "Location Details"
1, 2F66-16, DE, -120.0001, "near a road, in woods (FR16)"
2, 678E-15, DE, -120.0002, "near milepost 65, north side of road"
You are on the right track using the text import wizard within Excel, that at least gives you more control.
I don't know why the text qualifier isn't working, that's exactly what it is designed to do.
Are you specifying that final column as TEXT instead of leaving it as GENERAL?
Do the sample items in the wizard show correctly?
Are you positive they are " characters, and something similar (like smart quotes)?
It's a pain, but if nothing else works, you can always combine the columns back together at the end:
Insert a column before your broken up details
Add a formula like =E2 & "," & E3 (or longer if it splits into more than two)
Copy the combined column, then paste values (over the same cells)
Delete the now extraneous columns
Was able to do it with the text importer:

How to prevent excel from truncating numbers in a CSV file?

The first few lines of my CSV file look like this (when viewed from Notepad++):
Trace,Original Serial Number,New Serial number
0000073800000000097612345678901234567890,0054,0001
When I open this file in excel, I get this:
For some reason, excel is truncating the serial numbers and the trace number. I have tried changing the format to Text but that still doesn't work, as excel only sees the value up to the 6:
7.38000000000976E+34
If I change it to Number:
73800000000097600000000000000000000.00
What can I do? I only have 60 lines, so if I have to start over and some how recopy the text into excel I will, but I'm afraid saving it will change the format once again.
You shouldn't need to start over or alter the existing CSV. The fastest way might be to use Excel's text import wizard. In the data tab under Get External Data click From Text and select your CSV file.
The wizard that appears will let you tell Excel the data type of each "column" and you can tell it to use text for your barcode.
Excel is trying to "help" you by formatting the input values. To avoid this, do not double-click the file to open it. Instead, open the Data tab and in the Get External Data section, click on From Text
Then tell the Import Wizard that the fields are Text:
One solution that may work for you depending on the environment you consume the csv, you can add a nonnumeric character to the beginning and end (e.g. a "_") of the values. This will force Excel to recognize it as text. You can then remove the "_"s in your downstream environment (SQL, Databricks, etc.) or even keep them if they don't interfere with your reporting.

CSV file creation without exponential numbers

How do you get around the exponential conversion that takes place when inserting a value into a csv file. I have a process that creates a csv file and then starts entering rows into it. One of those fields inside a row inserts a value similar to this:
123,45,45,466,6656,23423,2455,234,2454
These are just a string of id's i need to preserve on the csv file in order to import them into another program that expects a comma separated number of values in this field.
Of course when i open excel and look at this csv it gives me something like this:
123,45,45,466,6656,000,000,000,000
so those last few values mean nothing to the import process and it fails.
My question is how do i write to a csv file and get around my values being converted to exponential numbers as well as preserving the comma separated number values like above?
Thanks in advance
Billy
Put quotes around them
"123","45","45","466","6656","23423","2455","234","2454"
In order to get around this issue i used the following steps in MS Excel 2007:
Open a Blank Workbook in Excel.
Choose Data, Get External Data, Import Data. (Excel 2007 is Data, Get External Data, Data from Text)
Browse to your .csv file and Select "Import".
Import Wizard should appear.
Page 1 Select "Delimited"
Select the row which you want to start the import.
click "Next"
In the Delimiters, select "comma" and/or other delimiters you are using.
Note: The bottom half of the window will preview the way the data is to be imported.
click "Next"
highlight each column of your data in the window below. For each column you can specify "General", "Text", "Data", or "do not import column" using the radio buttons in the top left of the Wizard box. I used the "Text" option. This is an optional step.
Click Finish.
place the value in single quotes while using data
Eg:
String[] abc = {"0123455677888", "154758768969", "abcsdhfsdj", ""abcsdhfsdj3725423", "62343664268abcsdhfsdj"};
CSVWriter csvWriter = new CSVWriter(String fileName);
//csvWriter.writeNext(String[] stringArray)
csvWriter.writeNext(" \' "+abc[0]+" \' ", " \' "+abc[1]+" \' ", abc[2], abc[3], abc[4]);
Try this
It will store the data perfectly

Resources