Slick way to generate a CSV for user download?

Discussion in 'ASP General' started by MyndPhlyp, May 20, 2005.

  1. MyndPhlyp

    MyndPhlyp Guest

    I've been trying to Google this but have been getting far too many hits to
    be of use. Is there a slick way to generate a CSV or other Excel-friendly
    format and push it to the client? I'm using VBScript (and HTML and other
    typical stuff of course) on the ASP pages (no .NET stuff). Just a shove in
    the right direction is all I really need here.
     
    MyndPhlyp, May 20, 2005
    #1
    1. Advertising

  2. What's your data source?

    Ray at work

    "MyndPhlyp" <> wrote in message
    news:%23$...
    > I've been trying to Google this but have been getting far too many hits to
    > be of use. Is there a slick way to generate a CSV or other Excel-friendly
    > format and push it to the client? I'm using VBScript (and HTML and other
    > typical stuff of course) on the ASP pages (no .NET stuff). Just a shove in
    > the right direction is all I really need here.
    >
    >
     
    Ray Costanzo [MVP], May 20, 2005
    #2
    1. Advertising

  3. MyndPhlyp

    Mark Schupp Guest

    Response.ContentType = "text/comma-separated-values"
    Response.AddHeader "Content-Disposition","attachment; filename=extract.csv"

    For i = 1 to 10

    Next
    Response.Write CSVString( "row" & CStr(i)) & "," & CSVString("column 2")
    & vbCrLf
    Response.end

    Function CSVString( ByVal strIn )
    If IsNull( strIn ) Then strIn = ""
    CSVString = """" & Replace(strIn, """", "'") & """"
    CSVString = Replace(CSVString, vbCrLf, "<cr>")
    End Function

    --
    --Mark Schupp


    "MyndPhlyp" <> wrote in message
    news:%23$...
    > I've been trying to Google this but have been getting far too many hits to
    > be of use. Is there a slick way to generate a CSV or other Excel-friendly
    > format and push it to the client? I'm using VBScript (and HTML and other
    > typical stuff of course) on the ASP pages (no .NET stuff). Just a shove in
    > the right direction is all I really need here.
    >
    >
     
    Mark Schupp, May 20, 2005
    #3
  4. just query the database... write the text file string line by line and
    create the file however you wan it with the filesystem object

    its pretty easy really


    "MyndPhlyp" <> wrote in message
    news:%23$...
    > I've been trying to Google this but have been getting far too many hits to
    > be of use. Is there a slick way to generate a CSV or other Excel-friendly
    > format and push it to the client? I'm using VBScript (and HTML and other
    > typical stuff of course) on the ASP pages (no .NET stuff). Just a shove in
    > the right direction is all I really need here.
    >
    >
     
    Kyle Peterson, May 20, 2005
    #4
  5. MyndPhlyp

    MyndPhlyp Guest

    SQL Server 2K via ADODB.Recordset


    "Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
    message news:...
    > What's your data source?
    >
    > Ray at work
    >
    > "MyndPhlyp" <> wrote in message
    > news:%23$...
    > > I've been trying to Google this but have been getting far too many hits

    to
    > > be of use. Is there a slick way to generate a CSV or other

    Excel-friendly
    > > format and push it to the client? I'm using VBScript (and HTML and other
    > > typical stuff of course) on the ASP pages (no .NET stuff). Just a shove

    in
    > > the right direction is all I really need here.
    > >
    > >

    >
    >
     
    MyndPhlyp, May 20, 2005
    #5
  6. MyndPhlyp

    MyndPhlyp Guest

    "Mark Schupp" <> wrote in message
    news:...
    > Response.ContentType = "text/comma-separated-values"
    > Response.AddHeader "Content-Disposition","attachment;

    filename=extract.csv"
    >
    > For i = 1 to 10
    >
    > Next
    > Response.Write CSVString( "row" & CStr(i)) & "," & CSVString("column

    2")
    > & vbCrLf
    > Response.end
    >
    > Function CSVString( ByVal strIn )
    > If IsNull( strIn ) Then strIn = ""
    > CSVString = """" & Replace(strIn, """", "'") & """"
    > CSVString = Replace(CSVString, vbCrLf, "<cr>")
    > End Function


    Yeah, that's kind of what I was looking for. Short, sweet and simple. Thanx
    for ruining my weekend with yet another thing to play around with. <G> (It's
    s'posed to rain anyway.)
     
    MyndPhlyp, May 20, 2005
    #6
  7. MyndPhlyp

    Hal Rosser Guest

    "MyndPhlyp" <> wrote in message
    news:%23$...
    > I've been trying to Google this but have been getting far too many hits to
    > be of use. Is there a slick way to generate a CSV or other Excel-friendly
    > format and push it to the client? I'm using VBScript (and HTML and other
    > typical stuff of course) on the ASP pages (no .NET stuff). Just a shove in
    > the right direction is all I really need here.
    >


    Create the csv file on the server
    provide a link to that file on the asp page
     
    Hal Rosser, May 22, 2005
    #7
  8. MyndPhlyp

    MyndPhlyp Guest

    "Hal Rosser" <> wrote in message
    news:diQje.5145$...
    >
    > "MyndPhlyp" <> wrote in message
    > news:%23$...
    > > I've been trying to Google this but have been getting far too many hits

    to
    > > be of use. Is there a slick way to generate a CSV or other

    Excel-friendly
    > > format and push it to the client? I'm using VBScript (and HTML and other
    > > typical stuff of course) on the ASP pages (no .NET stuff). Just a shove

    in
    > > the right direction is all I really need here.
    > >

    >
    > Create the csv file on the server
    > provide a link to that file on the asp page


    Thanks Hal, but the Response.Write et al solution earlier in this thread
    appears to be the better alternative to files. The CSV, although I didn't
    mention it, is the contents of a tabular report currently being viewed by
    the user so it has to be generated on demand. As you might guess, this is
    for an internal web. Doint it this way allows me to skip the creation to
    disk and instead just push the stuff to the user ... on demand, of course.
     
    MyndPhlyp, May 22, 2005
    #8
  9. MyndPhlyp

    Roland Hall Guest

    "Mark Schupp" wrote in message news:...
    : Response.ContentType = "text/comma-separated-values"
    : Response.AddHeader "Content-Disposition","attachment;
    filename=extract.csv"
    :
    : For i = 1 to 10
    :
    : Next
    : Response.Write CSVString( "row" & CStr(i)) & "," & CSVString("column
    2")
    : & vbCrLf
    : Response.end
    :
    : Function CSVString( ByVal strIn )
    : If IsNull( strIn ) Then strIn = ""
    : CSVString = """" & Replace(strIn, """", "'") & """"
    : CSVString = Replace(CSVString, vbCrLf, "<cr>")
    : End Function

    In this example, shouldn't the response.write goes inside the for...next
    loop?
    And, how do you keep from getting the Action cancelled page?

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
     
    Roland Hall, May 22, 2005
    #9
  10. MyndPhlyp

    MyndPhlyp Guest

    "Roland Hall" <nobody@nowhere> wrote in message
    news:%...
    > "Mark Schupp" wrote in message

    news:...
    > : Response.ContentType = "text/comma-separated-values"
    > : Response.AddHeader "Content-Disposition","attachment;
    > filename=extract.csv"
    > :
    > : For i = 1 to 10
    > :
    > : Next
    > : Response.Write CSVString( "row" & CStr(i)) & "," & CSVString("column
    > 2")
    > : & vbCrLf
    > : Response.end
    > :
    > : Function CSVString( ByVal strIn )
    > : If IsNull( strIn ) Then strIn = ""
    > : CSVString = """" & Replace(strIn, """", "'") & """"
    > : CSVString = Replace(CSVString, vbCrLf, "<cr>")
    > : End Function
    >
    > In this example, shouldn't the response.write goes inside the for...next
    > loop?
    > And, how do you keep from getting the Action cancelled page?


    It is an oversimplified example probably modified in haste. I think just
    about everybody has been guilty of that at least once in their life. Yes,
    the Response.Write should be between the For and Next. My query was
    interpreted correctly though - how to push a file to a browser. The key bits
    are the Response.ContentType and Response.AddHeader methods (to which I add
    Response.Clear at the beginning and Response.Flush just before the
    Response.End). What happens between the Response.AddHeader and the
    Response.Flush, Response.End is really of no consequence.
     
    MyndPhlyp, May 22, 2005
    #10
  11. MyndPhlyp

    Roland Hall Guest

    "MyndPhlyp" wrote in message news:...
    :
    : "Roland Hall" <nobody@nowhere> wrote in message
    : news:%...
    : > "Mark Schupp" wrote in message
    : news:...
    : > : Response.ContentType = "text/comma-separated-values"
    : > : Response.AddHeader "Content-Disposition","attachment;
    : > filename=extract.csv"
    : > :
    : > : For i = 1 to 10
    : > :
    : > : Next
    : > : Response.Write CSVString( "row" & CStr(i)) & "," &
    CSVString("column
    : > 2")
    : > : & vbCrLf
    : > : Response.end
    : > :
    : > : Function CSVString( ByVal strIn )
    : > : If IsNull( strIn ) Then strIn = ""
    : > : CSVString = """" & Replace(strIn, """", "'") & """"
    : > : CSVString = Replace(CSVString, vbCrLf, "<cr>")
    : > : End Function
    : >
    : > In this example, shouldn't the response.write goes inside the for...next
    : > loop?
    : > And, how do you keep from getting the Action cancelled page?
    :
    : It is an oversimplified example probably modified in haste. I think just
    : about everybody has been guilty of that at least once in their life. Yes,
    : the Response.Write should be between the For and Next. My query was
    : interpreted correctly though - how to push a file to a browser. The key
    bits
    : are the Response.ContentType and Response.AddHeader methods (to which I
    add
    : Response.Clear at the beginning and Response.Flush just before the
    : Response.End). What happens between the Response.AddHeader and the
    : Response.Flush, Response.End is really of no consequence.

    It is to me. I was asking for knowledge, not to challenge. I wasn't aware
    I could send content as a file without first having a file.

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
     
    Roland Hall, May 22, 2005
    #11
  12. MyndPhlyp

    MyndPhlyp Guest

    "Roland Hall" <nobody@nowhere> wrote in message
    news:...
    >
    > It is to me. I was asking for knowledge, not to challenge. I wasn't

    aware
    > I could send content as a file without first having a file.


    I too was unaware ... 'till now. It has since been permanently recorded in
    that feeble cabinet I call a brain (only to eventually get lost in the dust
    of time).
     
    MyndPhlyp, May 22, 2005
    #12
  13. MyndPhlyp

    MyndPhlyp Guest

    "Dave Anderson" <> wrote in message
    news:...
    >
    >

    http://msdn.microsoft.com/library/en-us/iissdk/html/06da9e8d-cf8c-4bb0-8c11-4bf79a0994da.asp
    >

    http://msdn.microsoft.com/library/en-us/iissdk/html/7dfd936a-b985-4e15-a774-269dfcfd053c.asp
    >

    http://msdn.microsoft.com/library/en-us/ado270/htm/mdmthgetstringmethod(recordset)ado.asp


    Cool. I wasn't aware of the Recordset.GetString method. Thanx.

    BTW - I used to know a Dave Anderson hundreds of years ago in New England.
    We called him "Uncle Dave" 'cus he was an only child (and therefore would
    never be an uncle). On a longshot, would that happen to be you?
     
    MyndPhlyp, May 22, 2005
    #13
  14. MyndPhlyp

    Mark Schupp Guest

    > : It is an oversimplified example probably modified in haste. I think just
    > : about everybody has been guilty of that at least once in their life.

    Yes,
    > : the Response.Write should be between the For and Next. My query was
    > : interpreted correctly though - how to push a file to a browser. The key


    It was between the for and next when I tested the code. It pasted into the
    message very strangely. I did notice and thought I fixed it (my whole life
    has been weird lately).

    IIRC the "action canceled" is a weird bug (or maybe a "feature") in IE.
    Having to do with whether the page is called using GET or POST. Try using
    GET.

    --
    Mark Schupp



    "Roland Hall" <nobody@nowhere> wrote in message
    news:...
    > "MyndPhlyp" wrote in message news:...
    > :
    > : "Roland Hall" <nobody@nowhere> wrote in message
    > : news:%...
    > : > "Mark Schupp" wrote in message
    > : news:...
    > : > : Response.ContentType = "text/comma-separated-values"
    > : > : Response.AddHeader "Content-Disposition","attachment;
    > : > filename=extract.csv"
    > : > :
    > : > : For i = 1 to 10
    > : > :
    > : > : Next
    > : > : Response.Write CSVString( "row" & CStr(i)) & "," &
    > CSVString("column
    > : > 2")
    > : > : & vbCrLf
    > : > : Response.end
    > : > :
    > : > : Function CSVString( ByVal strIn )
    > : > : If IsNull( strIn ) Then strIn = ""
    > : > : CSVString = """" & Replace(strIn, """", "'") & """"
    > : > : CSVString = Replace(CSVString, vbCrLf, "<cr>")
    > : > : End Function
    > : >
    > : > In this example, shouldn't the response.write goes inside the

    for...next
    > : > loop?
    > : > And, how do you keep from getting the Action cancelled page?
    > :
    > : It is an oversimplified example probably modified in haste. I think just
    > : about everybody has been guilty of that at least once in their life.

    Yes,
    > : the Response.Write should be between the For and Next. My query was
    > : interpreted correctly though - how to push a file to a browser. The key
    > bits
    > : are the Response.ContentType and Response.AddHeader methods (to which I
    > add
    > : Response.Clear at the beginning and Response.Flush just before the
    > : Response.End). What happens between the Response.AddHeader and the
    > : Response.Flush, Response.End is really of no consequence.
    >
    > It is to me. I was asking for knowledge, not to challenge. I wasn't

    aware
    > I could send content as a file without first having a file.
    >
    > --
    > Roland Hall
    > /* This information is distributed in the hope that it will be useful, but
    > without any warranty; without even the implied warranty of merchantability
    > or fitness for a particular purpose. */
    > Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    > WSH 5.6 Documentation -

    http://msdn.microsoft.com/downloads/list/webdev.asp
    > MSDN Library - http://msdn.microsoft.com/library/default.asp
    >
    >
     
    Mark Schupp, May 23, 2005
    #14
  15. MyndPhlyp

    Roland Hall Guest

    "MyndPhlyp" wrote in message news:...
    :
    : "Roland Hall" <nobody@nowhere> wrote in message
    : news:...
    : >
    : > It is to me. I was asking for knowledge, not to challenge. I wasn't
    : aware
    : > I could send content as a file without first having a file.
    :
    : I too was unaware ... 'till now. It has since been permanently recorded in
    : that feeble cabinet I call a brain (only to eventually get lost in the
    dust
    : of time).

    Lucky brain owner... heading to Oz.

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
     
    Roland Hall, May 23, 2005
    #15
  16. MyndPhlyp

    Roland Hall Guest

    "Mark Schupp" wrote in message news:...
    :> : It is an oversimplified example probably modified in haste. I think
    just
    : > : about everybody has been guilty of that at least once in their life.
    : Yes,
    : > : the Response.Write should be between the For and Next. My query was
    : > : interpreted correctly though - how to push a file to a browser. The
    key
    :
    : It was between the for and next when I tested the code. It pasted into the
    : message very strangely. I did notice and thought I fixed it (my whole life
    : has been weird lately).

    That is weird. You must have a special browser. Could probably call it Ed.
    (O;=

    : IIRC the "action canceled" is a weird bug (or maybe a "feature") in IE.
    : Having to do with whether the page is called using GET or POST. Try using
    : GET.

    I'll try that. I would assume (cough) this means this is not an option to
    send an attachment by server-side email, or is it, meaning gathering data
    and sending an attachment by CDOSYS without first saving it as a file?

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
     
    Roland Hall, May 23, 2005
    #16
  17. MyndPhlyp

    MyndPhlyp Guest

    "Roland Hall" <nobody@nowhere> wrote in message
    news:%...
    > "MyndPhlyp" wrote in message news:...
    > :
    > : I too was unaware ... 'till now. It has since been permanently recorded

    in
    > : that feeble cabinet I call a brain (only to eventually get lost in the
    > dust
    > : of time).
    >
    > Lucky brain owner... heading to Oz.


    I am not too sure about the "lucky" part. There appears to be significant
    irreversible damage and I strongly suspect it is a hand-me-down from a
    research project at a remote asylum. Whether or not it is even accurate to
    call it a "brain" is left up to the medical examiner that will perform the
    eventual autopsy hopefully many years from now. But thanks for the optimism.
     
    MyndPhlyp, May 24, 2005
    #17
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Buderman

    Using Visual Slick Edit for Python

    Brian Buderman, Jul 18, 2006, in forum: Python
    Replies:
    3
    Views:
    574
  2. Mufasa
    Replies:
    5
    Views:
    305
    Mufasa
    Nov 8, 2007
  3. palewire
    Replies:
    1
    Views:
    225
    Paul Rubin
    Jul 7, 2009
  4. Replies:
    3
    Views:
    125
    pcx99
    Jan 29, 2007
  5. richard

    A slick trick applied

    richard, May 22, 2012, in forum: HTML
    Replies:
    5
    Views:
    477
    dorayme
    May 27, 2012
Loading...

Share This Page