Excel 2010 - load a text file "as text" - excel

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.

Related

KDB: Preserve Leading Zeros When Saving Data to CSV?

I'm trying to export data from KDB to a csv file. Unfortunately, when I do this, the leading zeros disappear. For example, 0355 becomes 355.
Is there a hack of sorts that I can use to get around this issue?
I think your issue may be in the process of opening the CSV with excel. The prevailing 0's are still present until viewed in excel.
If you are wanting to view the data in excel one option would be to first string the data and then add a prevailing ' in kdb. For example:
q)table: flip `a`b`c!(`001`002`003; 123; 10 12 12)
q)update a:("'",'string a) from table
a b c
-------------
"'001" 123 10
"'002" 123 12
"'003" 123 12
This effectively acts as a indicator stating "this is text", thus the 0 will be retained. The ' will not be visible in the cells unless you edit a specific cell, as a result it is useful for displaying these symbols. Other than this I think your best option would be to just change the column type settings in excel.
If your .csv file contains the leading 0's when opened in notepad, then the problem is likely that Excel is misinterpreting the value as a number since when kdb+ exports symbols to a csv file it does without wrapping the value in quotation marks.
To get around this open Excel and click on the 'Data' ribbon and then 'From Text' to import your csv using the Import Wizard. Once you have selected your csv, the wizard will open and you can set the delimeter as comma.
You will then be able to choose the data types for each column, and setting the column with the leading 0's as text format will make them appear correctly.

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:

Lost precision when saving csv to excel format

I have a CSV file, in which one column is storing some account number text, like 99010124450000237, however when i try to save it to excel, it always format the number to 99010124450000200, the last 2 digits are rounded. this is so annoying, because actually i just want the account number be text field, but Excel will always take it as a number, and even worse, it was rounded. anybody have the same pinpoint and maybe some suggestions?
I tried to format the column to a specific format, and tried to import data. neither method works.
You don't say what version you're using, but the following seems to work in Excel 2007:
Use Data ... Get External Data ... From Text Select your file and
click "Import"
In Text Import Wizard Step 1, set Original Data Type
to "Delimited" (the default on my installation)
In Text Import Wizard Step 2, select your delimiter (my test file uses Comma)
In Text Import Wizard Step 3, click on the column with the account
number (it should be highlighted) and change "Column Data Format" to
"Text"
Click "Finish"
I used a file with the following text, selecting the second column to be Text:
"99010124450000237",99010124450000237,"99010124450000237"
99010124450000237,"99010124450000237","99010124450000237"
and got this output:
A B C
1 9.90101E+16 99010124450000237 9.90101E+16
2 9.90101E+16 99010124450000237 9.90101E+16

Export and customize a crystal report in excel

I am having an issue is that while exporting a report to excel sheet, there are lots of spaces and empty cells between the data, as well as, the cells are merged.
Is there is a way to export the report and each field will be in a cell or to control that exportation, suppose my report looks like this:
No Trans_No
1 123
2 333
In my excel sheet, I would like
A B
No Trans_No
1 123
2 333
, But currently it is showing a merging of the cells and spaces , so instead of Trans_No will be in CELL B, it is in D.
So, is there is a way to control o export that?
mohs, welcome to StackOverflow.
Crystal Reports and Excel have very different methods and data structures. When exporting a .rpt into .xls format, Crystal has to make many compromises and judgement calls. Here are some suggestions:
Do you absolutely need to use Crystal in this process?
A. You can import data directly from your data source into Excel (without using Crystal) using Data->Import External Data.
B. You can export from Crystal into CSV format. If the Excel file is being made just for a machine to read it, CSV is a better option.
Keep your Crystal Report very simple.
A. After you drag & drop fields onto your design, do not resize or overlap them.
B. Make sure in your options, you have snap to grid checked.
C. Are your fields horizontally aligned? If not, they will probably be put on different rows.
D. If you are grouping data, you may want to suppress the group headers & footers.
If you are finding empty rows between your data, you can filter these out in Excel:
Select column
Data > Filter (Excel 2010)
Dropdown > uncheck 'Blanks'
I don't use Crystal Reports, but could you export to a CSV file, then import into Excel. The import will allow you to specify the delimiters and should format your data better.
From experience with exporting from older versions of Crystal to Excel, a couple of options:
(1) Export to CSV and open the CSV file in Excel.
This had the disadvantage that instead of appearing at the top of the report above the data values, the column headings would appear on every line of the output before the column values - like so:
No Trans_No 1 123
No Trans_No 2 333
This issue may have been resolved in CR XI - if not, the workround we used for this was to suppress column headings (so that only the values were included in the output), then copy and paste a standard spreadsheet heading for the report into the output in Excel.
(2) Consistently format all fields to the same, minimum size (typically, two grid widths), with columns aligned by snapping the left edge of fields to guidelines.
This produces output which is almost unreadable in the standard report viewer, but which should align correctly in Excel.

Excel changes date formats

I run a process to produce a rather large CSV file of data. Sometimes I find it helpful to open the CSV in excel, make changes manually, and then re-save. However, if there are dates in the CSV, excel automatically reformats them. Is there a way to prevent excel from doing this? It would be helpful if I could turn off all text formatting altogether.
If you prepend an apostrophe ' to the beginning of any date string during the export process, Excel will read the value literally (i.e. as plain text) rather than trying to convert it to a date.
This particular solution is handled during the export process. I'm not sure how you would change Excel to treat the file differently at runtime.
Excel does some nasty tricks when outputting XML. One of its tricks is to drop left most column delimiters if 16 or so consecutive rows have no values for these columns. This means that if you're splitting the lines up based on commmas then these rows will have a different number of columns to the rest.
It will also drop any initial 0's so things like numeric Ids can become messed up.
Another risk you run is chopping the file off short since Excel can only support a maximum number of rows. (Prior to Excel 2007 this was around 65536)
If you need to do anything to a CSV file other than read it use a text editor.
When you import the CSV file into Excel, be sure to pre-format the date column as text. There's a frequently overlooked option in the parsing that allows you to control the format column by column. This also works well for preventing the leading zeros in New England ZIP codes from getting dropped in your contact lists.
If you used the excel file version which is 2010 or later (not sure lower version), you can set up to use current operation-system date format or not in Excel/CSV file.
Right Click cell with date value (e.g. '9/12/2013') in CSV file and pop up the menu
Click 'Format Cells' and open a pop up screen
Go to 'Number' tab and you can see 'Date' was selected in 'Category' (left side) and 'Type' on the right side
Observed that there are two types of Date format (one is with () and another is not with ()). Read the comment there and you can find that you can use the date format which is not with date. It means that your changes to the CSV file will not be applied with your current operation-system date format. So, I think date format won't be changed in CSV file in this case.

Resources