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

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:

Related

Csv writer escape semicolon python [duplicate]

I am using Excel for Mac 2016 on macOS Sierra software. Although I have been successfully copying and pasting CSV files into excel for some time now, recently, they have begun to behave in an odd way. When I paste the data, the content of each row seems to split over many columns. Where as before one cell would have been able to contain many words, it seems now as though each cell is only able to contain one word, so it splits the content of what would normally be in one cell, over many cells, making some rows of data spread out over up to 100 columns!
I have tried Data tab>> From text>> which takes me through a Text Wizard. There I choose Delimited>> Choose Delimiters: Untick the 'Space' box ('Tab' box is still ticked)>> Column data as 'General'>> Finish. Following this process appears to import the data into its correct columns. It works. BUT, a lot of work to get there!
Question: Is there any way to change the default settings of Delimiters, so that the 'Space' delimiter does not automatically divide the data?
I found an answer! It has to do with the "Text to Columns" function:
The way fix this behavior is:
Select a non-empty cell
Do Data -> Text to Columns
Make sure to choose Delimited
Click Next >
Enable the Tab delimiter, disable all the others
Clear Treat consecutive delimiters as one
Click Cancel
Now try pasting your data again
I did the opposite regarding "consecutive delimiters"!
I put a tick in the box next to "Treat consecutive delimiters as one", and THEN it worked.
Choose delimiter directly in CSV file to open in Excel
For Excel to be able to read a CSV file with a field separator used in a given CSV file, you can specify the separator directly in that file. For this, open your file in any text editor, say Notepad, and type the below string before any other data:
To separate values with comma: sep=,
To separate values with semicolon: sep=;
To separate values with a pipe: sep=|
In a similar fashion, you can use any other character for the delimiter - just type the character after the equality sign.
For example, to correctly open a semicolon delimited CSV in Excel, we explicitly indicate that the field separator is a semicolon:
reference

How to import CSV-file with Microsoft Excel 2016?

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

Excel 2010 - load a text file "as text"

Is there anyway I can get Excel 2010 to load a text file as pure text, i.e. apply no interpretation to any field? I need to modify a large CSV file with several hundred columns (basically remove some columns). It's health data, so some of the columns are:
NHS number "123456789012", which Excel displays as 1.23E09
Hospital ID: "0123456", which Excel displays as "123456". The leading zero is important here.
Various 2 char status codes where the leading zero is imports, i.e. "01" does not mean "1".
I don't want to have to go through all 297 columns reformatting them correctly. Please help!
From main menu Data select From Text (or similar. I don't know if it is the correct label in English Excel version. On my version it is the third button from left on the Data ribbon).
Then choose your csv file. You will get a wizard where you have to choose the column separator character and especially the import format of the columns. Here you should select all columns and then choose the radio button 'Text'. This should import all data as plain text.

Looking up multiple values in a list

I'm trying to select multiple values based on a search key. In it's most basic form there is no problem with this. I followed this example and everything went well:
http://office.microsoft.com/en-us/excel-help/how-to-look-up-a-value-in-a-list-and-return-multiple-corresponding-values-HA001226038.aspx
=IF(ISERROR(INDEX($A$1:$B$7,SMALL(IF($A$1:$A$7=$A$10,ROW($A$1:$A$7)),ROW(1:1)),2)),"",INDEX($A$1:$B$7,SMALL(IF($A$1:$A$7=$A$10,ROW($A$1:$A$7)),ROW(1:1)),2))
The problem with this however is that in my case I have multiple CSV files (external) where some values in my A$ column look like this:
=- sometext // results into #NAME? error
Excel interprets these as a formulas where it is actually only supposed to be a string. Sure I could change it to text and save it again but I would like to avoid any manipulation in these CSV files.
I tried to extend the second IF statement (if you read it from left to right) with:
IF(AND($A$1:$A$7 <> "#NAME?", $A$1:$A$7=$A$10,ROW($A$1:$A$7)))
and
IF(AND(NOT(ISERROR($A$1:$A$7)), $A$1:$A$7=$A$10,ROW($A$1:$A$7)))
Both didn't work. (Sorry if I messed up some syntax and formula names, I'm using a different language version)
Here a small image of what's happening right now and how it should look:
On the right site you can see a list of values right next to Test1 which are missing on the left site due to the #NAME? error.
I would suggest opening the csv's files as text files. Selecting Comma as your delimiter and then select Text as your Column data format. This way, Excel will treat all your data as text and will not try to read =- sometext as a formula.
To do so, you would need to change your .csv files extension to .txt or anything else (even no file format).
Instead of "Opening" the CSV file, you can "Import" it. This will open the Text Import Wizard which will allow you to specify particular columns as Text. This is located in different areas in different versions of Excel. In Excel 2007, it is on the Data Tab / Get External Data / From Text. The example below demonstrates bringing in long numbers, but it should work just as well with your formula "lookalikes"

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