Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Query2Excel

    I am trying to utilize this UDF found on CFLIB.ORG. Have emailed the author,
    but havn't heard yet and I am on a tight deadline (as usual. ; )) I hope it is
    OK to post this here.

    When I specify the query, like so #Query2Excel(getreport)#, "getreport" being
    the name of my query. It works fine.

    BUUUUT when I try to add the columns & headers so I can control the order,
    like so #Query2Excel(getreport,colorder,colorder)#, I get an error saying IE
    can't open the page. "Colorder" is the variable that contains a comma-delimited
    list of column names in the "getreport" query.

    What am I doing wrong?

    Thank you!
    Hope:confused;

    hope.martin Guest

  2. #2

    Default Re: Query2Excel

    Whoops! I see I forgot a bit of code in my first post. To save confusion,
    here's the whole thing:

    <cfinclude template="../Assets/query2excel.cfm">
    <cfscript>
    cols = "<cfoutput>#colorder#</cfoutput>";
    heads = "<cfoutput>#colorder#</cfoutput>";
    data = getreport;
    </cfscript>
    <CFHEADER NAME="Content-Disposition" VALUE="inline; filename=tracker.xls">

    <cfcontent
    type="application/msexcel"><cfoutput>#Query2Excel(data,heads,cols)#</cfoutput>


    hope.martin Guest

  3. #3

    Default Re: Query2Excel

    Woohoo! I almost have this solved. Thanks to much help from the UDF author!


    The first part of the problem was that I was aliasing a column in my getreport
    query. Removed the alias and it hung on a column that doesn't exist
    (FISCAL_YEAR). But the getreport query contained an added query column called
    "FY". That is the same name as a column in another table that is used to build
    this report. When I changed the added QUERY column to "FISCAL_YEAR"... IT
    WORKED!!! Not sure why but at this point as long as it works I don't care.

    Now the only problem remaining is this: on one of the columns (WON), once it
    gets to excel, an apostrophe appears before the value. That is to say if in the
    database I have "200500050009" then once it gets to excel it becomes
    "'200500050009". That's not good!

    Help!

    hope.martin Guest

  4. #4

    Default Re: Query2Excel

    Yay! I finally have this working as I need it.

    To Review:
    1. aliased columns caused problems. when I removed the aliases, the UDF worked
    fine
    2. In MSExcel, numerical values greater than 10 digits will show as scientific
    notation. To get around this the UDF added an apostrophe infront of the numbers
    like so:

    if (isNumeric(colValue) and Len(colValue) gt 10) {
    colValue="'#colValue#";

    I didn't want the apostrophe, so I added and equal sign and surrounded the
    number with quotes like so:

    if (isNumeric(colValue) and Len(colValue) gt 10) {
    colValue="=""#colValue#""";

    And excel treats it as a formula displaying it correctly without the added
    apostrophe

    I hope someone will find this helpful!

    :D

    hope.martin 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