template::list::write_csv (public)
template::list::write_csv -name name [ -label_headers ] \ [ -delimiter delimiter ]
Defined in packages/acs-templating/tcl/list-procs.tcl
Writes a CSV to the connection
- Switches:
- -name (required)
- template::list name
- -label_headers (optional, boolean, defaults to
"true"
)- -delimiter (optional, defaults to
","
)- CSV delimiter
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
Source code: # Creates the '_eval' columns and aggregates template::list::prepare_for_rendering -name $name get_reference -name $name set __list_name $name set __output {} set __groupby $list_properties(groupby) # Output header row set __cols [list] set __csv_cols [list] set __csv_labels [list] foreach __element_name $list_properties(display_elements) { template::list::element::get_reference -list_name $name -element_name $__element_name if {!$element_properties(hide_p)} { lappend __csv_cols $__element_name lappend __csv_labels $element_properties(label) } } lappend __output [expr {$label_headers_p ? $__csv_labels : $__csv_cols}] set __rowcount [template::multirow size $list_properties(multirow)] set __rownum 0 # Output rows template::multirow foreach $list_properties(multirow) { set group_lastnum_p 0 if {$__groupby ne ""} { if {$__rownum < $__rowcount} { # check if the next row's group column is the same as this one set next_group [template::multirow get $list_properties(multirow) [expr {$__rownum + 1}] $__groupby] if {[set $__groupby] ne $next_group} { set group_lastnum_p 1 } } else { set group_lastnum_p 1 } incr __rownum } if {$__groupby eq "" || $group_lastnum_p} { set __cols [list] foreach __element_name $__csv_cols { if {![string match "*___*_group" $__element_name]} { template::list::element::get_reference -list_name $__list_name -element_name $__element_name -local_name __element_properties if { [info exists $__element_properties(csv_col)] } { lappend __cols [set $__element_properties(csv_col)] } else { lappend __cols [set $__element_name] } } { lappend __cols [set $__element_name] } } lappend __output $__cols } } package require csv set __output [::csv::joinlist $__output $delimiter] set oh [ns_conn outputheaders] ns_set put $oh Content-Disposition "attachment; filename=${__list_name}.csv" ns_return 200 text/csv $__output ad_script_abortXQL Not present: Generic, PostgreSQL, Oracle