473,698 Members | 2,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

making leading zero's visible

LRW
This may be a question more directed to Excel, but I'm using PHP to
generate a CSV to be imported into Excel, so maybe the solution is
there. So, sorry for crossposting.

Anyway, I'm generating a text file, a CSV, that contains addresses
from a database. Zip codes that have a leading zero (eg: 01234) has
that 0 in the database, and it appears to have it when it's being
inserted and written to the text file, but when you view it in Excel
it goes away.

When I'm creating the string that becomes the CSV file, I surround the
zipcode with doublequotes so it's supposed to go into the file exactly
as written.
Is it an issue with Excel disregarding the quotes and still seeing the
number as purely a number and not a text string?

Is there a way I can alter that at the file generation end, because I
won't have control of the Excel program used when it's outputted.

Thanks for any assistance!
Liam
Jul 17 '05 #1
6 6727
Anyway, I'm generating a text file, a CSV, that contains addresses
from a database. Zip codes that have a leading zero (eg: 01234) has
that 0 in the database, and it appears to have it when it's being
inserted and written to the text file, but when you view it in Excel
it goes away.


To force Excel to treat entries as text, not numeric prefix the string
with a single quote
Jul 17 '05 #2
Carved in mystic runes upon the very living rock, the last words of LRW of
comp.lang.php make plain:
Anyway, I'm generating a text file, a CSV, that contains addresses
from a database. Zip codes that have a leading zero (eg: 01234) has
that 0 in the database, and it appears to have it when it's being
inserted and written to the text file, but when you view it in Excel
it goes away.


When importing, after you specify the delimiter, on the next screen select
all the fields and change the type to Text rather than General. You can
select all the fields at once.

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
Jul 17 '05 #3
"LRW" <de**@celticbea r.com> wrote in message
news:3a******** *************** ***@posting.goo gle.com...
This may be a question more directed to Excel, but I'm using PHP to
generate a CSV to be imported into Excel, so maybe the solution is
there. So, sorry for crossposting.

Anyway, I'm generating a text file, a CSV, that contains addresses
from a database. Zip codes that have a leading zero (eg: 01234) has
that 0 in the database, and it appears to have it when it's being
inserted and written to the text file, but when you view it in Excel
it goes away.

When I'm creating the string that becomes the CSV file, I surround the
zipcode with doublequotes so it's supposed to go into the file exactly
as written.
Is it an issue with Excel disregarding the quotes and still seeing the
number as purely a number and not a text string?

Is there a way I can alter that at the file generation end, because I
won't have control of the Excel program used when it's outputted.

Thanks for any assistance!
Liam


If Kevin's idea works, you should be able to built the single quote into
your text file generator's output. If it doesn't work, come back here and
tell me. I have another solution that's more involved to implement, but
automated once it's been set up and tested.
Jul 17 '05 #4
"Doug Kanter" <an***********@ hotmail.com> wrote in message
news:Cd******** ********@news02 .roc.ny...

If Kevin's idea works, you should be able to built the single quote into
your text file generator's output. If it doesn't work, come back here and
tell me. I have another solution that's more involved to implement, but
automated once it's been set up and tested.


Thanks; the single quote does work.
However, the single quote actually appears in the spreadsheet as well.
I decided on a different workaround: strlen(). If the zipcode is 5 digits
long (because the leading zero is in the data in the database) then
add -0000 to the end.
That makes it a string as well as makes it the same number of digits as the
zipcodes where people included their +4 Zip.

Unless someone has a better method. =)

Thanks all!
Liam
Jul 17 '05 #5
"Mechphisto " <li**@REEMOVEme chphisto.net> wrote in message
news:u3ioc.7544 1$Ik.5440329@at tbi_s53...
"Doug Kanter" <an***********@ hotmail.com> wrote in message
news:Cd******** ********@news02 .roc.ny...

If Kevin's idea works, you should be able to built the single quote into
your text file generator's output. If it doesn't work, come back here and tell me. I have another solution that's more involved to implement, but
automated once it's been set up and tested.

Thanks; the single quote does work.
However, the single quote actually appears in the spreadsheet as well.
I decided on a different workaround: strlen(). If the zipcode is 5 digits
long (because the leading zero is in the data in the database) then
add -0000 to the end.
That makes it a string as well as makes it the same number of digits as

the zipcodes where people included their +4 Zip.

Unless someone has a better method. =)

Thanks all!
Liam


That's a nice method. And, this is so much better than rec.boats, where
everyone's arguing about politics and anchor chains.
Jul 17 '05 #6
Hi Liam,
There is a zip code format, but I would avoid that because you will not
be able to sort properly on zip code if you do and it makes it good
only for the US. [ mixed US zip and zip+4]

Prior to opening your .csv file change the file extension to .txt so
that the text import wizard will come up and you can tell it which
columns are text -- you want your zip code column to be text.

If you already have your data in the columns you don't need to start
over, I have a macro to fix the US zip codes. The zip+4 are
fine because they are text already, and the macro will ignore them.
Even it they were numbers the macro would ignore numbers with
more than 5 digits. See FixUSzip5 macro in
Rearranging Data in Columns
http://www.mvps.org/dmcritchie/excel/join.htm#fixuszip5
Format the column as text before running the macro.
Changing the format either way between number and text, has
no effect until the data is reentered, which is what the macro will do.
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
13781
by: david | last post by:
Hi, I have an application as follows: MySQL database Back-Eend linked to MS Access Front-End and ASP Web Application. I require users to enter Serial Numbers such as: 0105123567 (10 digits), the first 4 being the month and year (mmyy)
2
1846
by: Jeff Lowry | last post by:
I'm pasing a zip code as a prameter to an Access stored procedure. In Access the parameter is a text data type. It works for non-leading zero zip codes but, apparently access (or ASP) is converting it to a value first (dropping the zero) then sending that to my SP. Even if I use cStr() to be sure the parameter is sent a string it still seems to drop the leading zero. Any thoughts? Note: It needs to be a string for canadian zip...
7
2894
by: david | last post by:
Hi, I have 2 text boxes on an ASP form. A user enters a Serial Number in TB1 such as 0105123456, presses tab to move to TB2, TB2 then displays the value of TB1 after a calculation has been done. (Based on a Serial Number range). i.e. a user enters 0105123456, TB2 then adds 'x' qty to this number depending on how many serial numbers are required.
1
12776
by: Joshua Ammann | last post by:
Hello, I'm trying to export a query containing contact information, including a field. Some zip codes have one or two leading zeros, for example, San Juan, PR (00927) and Springfield, MA (01104). When I export to a comma separated value (.csv) file, the zip code for San Juan becomes "927" and for Springfield becomes "1104". How can I prevent the leading zero(s) from being trimmed in the exported .csv file? Because the table contains...
1
1423
by: tfs | last post by:
I am reading into a datagrid and can't seem to get the "execution time" column (the 3rd column) to move to the right. My problem is that the last character in the 2nd column is right up against the end of the column and the 3rd column is too close and confusing. So I was trying to move the data in the 3rd column over a few spaces. So I did the following:
5
3474
by: GarryJones | last post by:
I have code numbers in 2 fields from a table which correspond to month and date. (Month, Code number) Field name = ml_mna 1 2 3 etc up to 12 (Data is entered without a leading zero)
8
4819
by: Andrew Poulos | last post by:
In my limited testing with FF 2, IE 6 and Opera 9 when I divided a positive integer, that is less than 100, by 100 I get a leading zero in front of the decimal point. For example 80/100 gives 0.8 This is what the server app is expecting a leading zero (it does indeed fail without it). Do I need to do anything to ensure the leading zero is there?
4
3214
by: bobm2005 | last post by:
Whatever format I try in Printf, an 'E' format number nearly always has a leading non-zero:- 1.2345E7 -9.3456E8 etc. Is it possible to force it (printf) always to have leading zero? Thus, the above becomes:-
6
7757
by: JimmyKoolPantz | last post by:
Task: Customer wants a script of the data that was processed in a "CSV" file. Problem: Zip-Code leading zeros are dropped Basically we have a client that has requested a custom script for each file that he has us process. He wants this in a Comma Delimited Format.
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8901
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7739
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.