Add a zero to a zip code in a csv file? - excel

Is there a quick way to append a zero to some highlighted cells in my csv file so I don't have to go one by one?
Should be 01234
Instead it is showing 1234
Since all the zip codes are different I cant just do a simple find and replace. TY

You can do that using cell formatting option Zip Code.
Select the column/cells containing zip codes.
Right click -> Format Cells
Number tab -> Special category
And select Zip Code type.

You can:
Open the csv in excel
Insert a mask at ZipCode column using =TEXT(A1, "00000")
Save as csv, ignoring the fact that you'll loose the formulas (this will preserve the results in the csv file)

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.

Excel - exporting as TXT with text position

I have several text files (about 6). All have the following format.
Column (Text position in txt file)
1-4 -> Code
6-72 -> Name
74-78 -> another code
80-81 -> another code
These text files I want to import into excel, so I can sort them after A-Z and inspect the duplicates. After doing so, I must delete a few duplicates and export this to ONE single txt file. This file must be saved in the exact same format as before. Unfortunately I cannot find anything in the Internet regarding this.
Could somebody help me?
Thanks and best regards
Dennis
I found a solution!
First I combine the data in the excel file and manipulate it. After
that I adjust the width of the columns, so no values overlap.
Then I save this as an .prn file.
This .prn file I open in notepad++ and manipulate the column
position with help of SHIFT + ALT + Down to set multiple Cursors.
Now I got my file :-)
Thanks anyway!
Ressources:
Export an Excel Spreadsheet as fixed width text file
Notepad Multiple Cursors

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"

pentaho report excel output - leading '0' gets truncated

I have a format issue with my pentaho report excel/csv output.
My report output contains zip code column, which has leading zeroes if the zip code length is less than 5. the leading zeroes get truncated when i open the report output in excel file. I used 'textfield' for the zipcode column, i even tried concatenating zeroes in my xaction sql. everything works fine if i open the output in a text editor, but when we open it in excel file the zero got trimmed.
can we prevent this trimming issue or can we use other data fields in design instead of text field.
Change the extension of your csv to .txt so you get Excel's dialogue boxes for importing text files; there you can select the comma as your column delimiter. On the third screen (after you hit "next" twice), there is an option to choose the formatting of each column. Select you zip code column, change it from "General" to "Text" format, and your leading zeroes will be retained.
use text formatting in the Home-->Number-->Special
Cannt paste imapge--> i guess not enough points
Hope it helps
I don't know whether it is proper or not but enclose field in Double quotes or single which ever you prefer..
quotes will not display in excel file format but it will display in textpad or notepad..
So it you don't have any problem in adding this extra thing then it will solve your problem.
What is the original data format in your DB? Is it an INT?
In your sql statement, try something like this (adjust for the relevant sql dialect, if necessary):
lpad(cast(zip as CHAR(5)),5,'0') zip
where zip is your field name.
Then use text-field as you are already doing.

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