string becomes numeric?

Ask a Question related to Macromedia ColdFusion, Design and Development.

  1. #1

    Default string becomes numeric?

    Hi,

    I am trying to dump a query out into an excel. I found that a varchar
    datatype column will be converted to numeric in the Excel. For example, if the
    data in that column is "0001", it becomes "1" in the Excel. Since this is an
    ID type column, we do not want to lose the "0". Is there a way to prevent
    this? Thanks for any advice.

    I used the the tag such as
    <CFHEADER NAME="Content-Disposition" VALUE="inline; filename=Test..xls">
    <CFCONTENT TYPE="application/msexcel"><cfoutput>TestColumn</cfoutput>
    <cfoutput query="GetTest">#TestColumnData#
    </cfoutput>

    Helena

    hupeng Guest

  2. Similar Questions and Discussions

    1. CS3 Numeric Extensions
      I need an extension to format php MySQL numeric data to display in currency. I downloaded one that does not work.
    2. #40274 [NEW]: Sessions fail with numeric string root keys
      From: ben at vanilla dot net Operating system: FreeBSD 6.2 PHP version: 5.2.0 PHP Bug Type: *Web Server problem Bug...
    3. numeric part of a string
      Can anyone tell me how can I get the numeric part of a string . for example I'm using this..Select substring('walnut 2224...
    4. How to sort a String column as Numeric?
      I have a datagrid (dgResults) that I am populating from a SQL stored procedure. After I fill my dataset (ds), I cache the dataset this way:...
    5. Problem converting array string back to numeric
      I'm afraid I don't know enough about your situation to help. How are you sending your values to ASP? It sounds to me like this is more like an ASP...
  3. #2

    Default Re: string becomes numeric?

    I haven't tested this in all cases but you can usually force text formatting by
    apostrophe-escaping the number.

    Change this:
    <cfoutput query="GetTest">#TestColumnData#
    To this:
    <cfoutput query="GetTest">'#TestColumnData#

    Cheers,
    -- MikeR

    MikerRoo Guest

  4. #3

    Default Re: string becomes numeric?

    Hi,

    Thanks. Adding apostrophe will force that data to be exported as string, but the data will have an apostrophe before it. Is there a trick to remove it in our exporting process.

    Helena
    hupeng Guest

  5. #4

    Default Re: string becomes numeric?

    You do not need to remove the apostrophe. In fact, as soon as you do, you
    will lose the leading zeros.

    In Excel, having the apostrophe isn't really part of the data. It just forces
    text formatting.
    For example, paste the following into two excel cells:
    '003
    '004

    Now select one of the cells, press Control-C and paste the result into a text
    file. You will see that the apostrophe is not included.

    Most math formulas still work too. For example setting a cell to =A1+A2 will
    still yield the correct value of 7.

    Bottom line is: you need that apostrophe to force text formatting. You see it
    in the formula bar but it has no other effect. (Text formatting, however,
    will break some formulas -- compared to number formatted cells).

    -- MikeR


    MikerRoo Guest

  6. #5

    Default Re: string becomes numeric?

    Thanks for the note. I just tried some experiments.

    If I entered '003 into a cell, the apostrophe will not show up as the data but
    the cell will have a little green triangle at the upper left corner of the
    cell.
    However, if I used the codes to export the query output into the excel
    spreadsheet, that apostrophe will appear as part of the data. If I copied that
    cell into a text file, that apostrophe will be part of the data copied. But if
    I highlighted this cell, clicked the data from the top text box (part of the
    top menu) (not from the cell), then that apostrophe "got recognized" as a
    "string formatting" mechanism, disappeared and the green corner appears.

    It seems that the export will not make that apostrophe automatically
    recognized as a string formatting mechanism. I could have thousands of lines
    of records in the Excel. Is there a batch tool to make it recognize this
    apostrophe?
    Thanks.

    hupeng Guest

  7. #6

    Default Re: string becomes numeric?

    OK, if you save a well-formed table, you can USUALLY use Miscrosoft's hidden
    styles. HOWEVER, this behavior changes from one Excel version to the next and
    you may have to use the whole Excel XML schema to get it to work reliably.

    Saving your table cells like this:
    <td style='mso-number-format:"\@"'>00004</td>
    will usually set text formatting -- without the apostrophe.

    Good luck,
    -- MikeR


    MikerRoo Guest

  8. #7

    Default Re: string becomes numeric?

    I used the following codes to export the query ouput directly into Excel from
    webpage, where should I insert the lines of codes <td
    style='mso-number-format:"\@"'> you suggest?

    <CFHEADER NAME="Content-Disposition" VALUE="inline; filename=Test..xls">
    <CFCONTENT TYPE="application/msexcel"><cfoutput>TestColumn</cfoutput>
    <cfoutput query="GetTest">#TestColumnData#
    </cfoutput>

    Thanks a lot for your help.

    hupeng Guest

  9. #8

    Default Re: string becomes numeric?

    Write your output in a table.
    Use the attached code as a start.

    -- MikeR



    <CFHEADER name="Content-Disposition" value="inline; filename=Test..xls">
    <CFCONTENT type="application/msexcel">

    <CFOUTPUT>
    <html>
    <head>
    </head>
    <body>
    <table>
    <tr>
    <th>TestColumn</th>
    </tr>

    <CFLOOP query="GetTest">
    <tr>
    <td style='mso-number-format:"\@"'>#TestColumnData#</td>
    </tr>
    </CFLOOP>

    </table>
    </body>
    </html>
    </CFOUTPUT>

    MikerRoo Guest

  10. #9

    Default Re: string becomes numeric?

    MikeR.
    Thanks a lot for the help. It is working great!! This format helps me solve quite a few other problems too. Cheers :)
    Helena
    hupeng 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