CSV file - Leading Zeros

Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default CSV file - Leading Zeros

    Is there a way to write a CSV file so that excel wont drop the leading
    zero's from fields? I could use spreadsheet::writeexcel or OLE but
    that's like using a sledgehammer for something that needs to be hand
    tightened.

    Thanks.
    Paul

    Paul Kraus Guest

  2. Similar Questions and Discussions

    1. preserve leading zeros in alphanumeric values from doc.info
      I store an alphanumeric data item in a doc.info object, and retrieve it to populate form fields in the doc and in a dynamic stamp. This works fine...
    2. Leading Zeros not being read from Excel Query
      We are having an odd problem when trying to read in a query from Excel. What we are trying to do: We have a page where users will upload an Excel...
    3. Disappering leading zeros
      Have a problem that has me swinging. I have a MS Access d/b that contains a zip code directory. Updates are done via a web-based ColdFusion form....
    4. Insert leading zeros
      I have a string of digits that looks like something like these: 0025, 1234, 0001, 1003, and so on. They are all 4 digits in length. Then when I...
    5. CSV for Excel - Problem with Leading Zeros
      Can we consider change the string to: ' 0000563' ? Luke (This posting is provided "AS IS", with no warranties, and confers no rights.)
  3. #2

    Default Re: CSV file - Leading Zeros

    Paul Kraus wrote:
    > Is there a way to write a CSV file so that excel wont drop the leading
    > zero's from fields? I could use spreadsheet::writeexcel or OLE but
    > that's like using a sledgehammer for something that needs to be hand
    > tightened.
    Put your numerics in quotes:

    "0099"

    But, depending on your copy of Excel, you may well not be able to do
    arithmetic on those fields. A CSV file simply doesn't hold any
    formatting information!

    Rob




    Rob Dixon Guest

  4. #3

    Default RE: CSV file - Leading Zeros


    I think this is more an Excel question than a Perl question. Excel will
    detect that it is a number and show you the equivalent formatted as a
    number. I think you can highlight the row and do a Format->Cells and
    pick Text as the type. Otherwise if the first character is a single
    quote then excel will treat the cell as text.

    -----Original Message-----
    From: Paul Kraus [mailto:pkraus@pelsupply.com]
    Sent: Friday, December 12, 2003 12:49 PM
    To: [email]beginners@perl.org[/email]
    Subject: CSV file - Leading Zeros

    Is there a way to write a CSV file so that excel wont drop the leading
    zero's from fields? I could use spreadsheet::writeexcel or OLE but
    that's like using a sledgehammer for something that needs to be hand
    tightened.

    Thanks.
    Paul


    --
    To unsubscribe, e-mail: [email]beginners-unsubscribe@perl.org[/email] For additional
    commands, e-mail: [email]beginners-help@perl.org[/email] <http://learn.perl.org/>
    <http://learn.perl.org/first-response>


    Tim Johnson Guest

  5. #4

    Default Re: CSV file - Leading Zeros

    Paul Kraus wrote:
    > Is there a way to write a CSV file so that excel wont drop the leading
    > zero's from fields? I could use spreadsheet::writeexcel or OLE but
    > that's like using a sledgehammer for something that needs to be hand
    > tightened.
    >
    > Thanks.
    > Paul
    Leading zeroes are meaningful only in strings. If you want leading zeroes
    in your data, signify that the value is a string by quoting it. It will
    totally make a hash of any numerical functions on the field, but if
    leading zeroes are that important...

    You could also think about the proper place to concern yourself with data,
    and where to concern yourself with it's representation. A database table,
    such as a CSV file, has one set of needs. A report has a comletely
    different set. Don't wate energy trying to line things up verticall in
    stored data. Just translate to your desired presentation format on
    extraction.

    So why do you need leading zeroes?

    Joseph

    R. Joseph Newton Guest

  6. #5

    Default RE: CSV file - Leading Zeros

    At 02:03 PM 12/12/2003, Tim Johnson wrote:
    >I think this is more an Excel question than a Perl question. Excel will
    >detect that it is a number and show you the equivalent formatted as a
    >number. I think you can highlight the row and do a Format->Cells and
    >pick Text as the type. Otherwise if the first character is a single
    >quote then excel will treat the cell as text.

    This doesn't work for me, the single quote is picked up in the conversion process. I don't think it is possible.

    -Mark
    >-----Original Message-----
    >From: Paul Kraus [mailto:pkraus@pelsupply.com]
    >Sent: Friday, December 12, 2003 12:49 PM
    >To: [email]beginners@perl.org[/email]
    >Subject: CSV file - Leading Zeros
    >
    >Is there a way to write a CSV file so that excel wont drop the leading
    >zero's from fields? I could use spreadsheet::writeexcel or OLE but
    >that's like using a sledgehammer for something that needs to be hand
    >tightened.
    >
    >Thanks.
    >Paul

    Mark Lobue Guest

  7. #6

    Default Re: CSV file - Leading Zeros

    At 09:45 PM 12/12/2003, R. Joseph Newton wrote:
    >Paul Kraus wrote:
    >
    >> Is there a way to write a CSV file so that excel wont drop the leading
    >> zero's from fields? I could use spreadsheet::writeexcel or OLE but
    >> that's like using a sledgehammer for something that needs to be hand
    >> tightened.
    >>
    >> Thanks.
    >> Paul
    >
    >Leading zeroes are meaningful only in strings. If you want leading zeroes
    >in your data, signify that the value is a string by quoting it. It will
    >totally make a hash of any numerical functions on the field, but if
    >leading zeroes are that important...
    This doesn't work, Excel still strips the delimiters and displays the number as numeric
    >You could also think about the proper place to concern yourself with data,
    >and where to concern yourself with it's representation. A database table,
    >such as a CSV file, has one set of needs. A report has a comletely
    >different set. Don't wate energy trying to line things up verticall in
    >stored data. Just translate to your desired presentation format on
    >extraction.
    >
    >So why do you need leading zeroes?
    My case is patient medical record numbers, which are always 9 digits and may have a leading zero. I have had this problem a long time, I just format the cells after the conversion process.

    -Mark

    Mark Lobue Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139