Forum OpenACS Q&A: Re: csv download for Templating system, ad_table, List Builder?

Andrew,

I was thinking of a template::util::multirow_to_csv sort of tcl proc.

Try something like this where there exists a multirow datasource called report_data. This is copied from a working page.

if {[string equal $mode csv]} {
    upvar #[adp_level] report_data:columns columns
    set header_row ""
    set i 1
    foreach column $columns {
        append header_row "${column}"
        if {![string equal $i [llength $columns]]} {
            append header_row ","
        }
        incr i
    }
    append header_row "\r\n"
    set csv ""
    append csv "$header_row\r\n"
    template::multirow foreach report_data {
        set row ""
        set i 1
        foreach column $columns {
            append row "\"[util_escape_quotes_for_csv [subst $$column]]\""
            if {$i < [llength $columns]} {
                append row ","
            }
            incr i
        }
        append csv "${row}\r\n"
    }
#    ns_return 200 text/plain $csv
# uncomment the next two lines to download instead of view in browser
    ReturnHeaders "application/text"
    ns_write $csv"

    ad_script_abort
}

I created an index.vuh takes page_name.csv and rp_internal_redirects to page_name.tcl so that the filename shows up correctly for the downloader.

I am awating the list-builder myself. It will definitely make some tasks much easier.