Purpose Process all table columns We want to process all table columns, e.g. download all columns to a file. |
Solution // column index Set V[m] 1 // text variable for test output Set text[msg] "" label next_header_column // get column header
Example 2
...
Our InputScript (below) uses GuiXT text variables instead of normal variables to generate the lines of the .csv file, since the size of one single row could exceed 4000 bytes for some tables, and 4000 is the maximum size of normal variables in GuiXT versions prior to 2024. GuiXT Script // add a button that downloads the order items to Excel size=(1,2) process="table_to_file.txt" using tabname = "All items"
// General script for table download including
all columns Parameter filename "&%[TEMP]\guixttemp.&V[today_ymdhms].csv"Parameter tabname Table // delimiter in CSV
file // Generate header row Set V[m] 1 // text variable for file generation Set text[txt] "" label next_header_columnGetFieldAttribute [&U[tabname],&V[m]] header="h" if Q[ok]if V[m>1] CopyText fromString="delimiter" toText="txt" -append endif CopyText fromString="h" toText="txt" -append // next column Set V[m] &V[m] + 1 goto next_header_column endif // Variables Set V[relrow] 1 // Relative row number Screen *GetTableAttribute T[&U[tabname]] _ firstVisibleRow=FVisRow _ lastVisibleRow=LVisRow _ lastRow=LastRow // First row on screen? if V[FVisRow=1] goto new_row endif // scroll to first line Enter "/scrollToLine=1" table="T[&U[tabname]]" label new_screen Screen *GetTableAttribute T[&U[tabname]] _ firstVisibleRow=FVisRow _ lastVisibleRow=LVisRow _ lastRow=LastRow Set V[relrow] 1 label new_row // end of table? if V[absrow>&V[LastRow]] goto end_of_table endif // end of screen? if V[absrow>&V[LVisRow]] Enter "/scrollToLine=&V[absrow]" table="T[&U[tabname]]" goto new_screen endif // loop through all columns Set V[m] 1 Set V[line] "" label next_column if cell[&U[tabname],&V[m],1] if V[m=1] Set V[line] "&cell[&U[tabname],&V[m],&V[relrow]]" CopyText fromString="line" toText="txt" -appendLine else Set V[line] ";&cell[&U[tabname],&V[m],&V[relrow]]" CopyText fromString="line" toText="txt" -append endif // next column Set V[m] &V[m] + 1 goto next_column endif Set V[absrow] &V[absrow] + 1 Set V[relrow] &V[relrow] + 1 goto new_row label end_of_table // Write text to file CopyText fromText="txt" toFile="&U[filename]" -utf8 // Display file Start "&U[filename]" // Back to line 1 Enter "/scrollToLine=1" table="T[&U[tabname]]" Leave |
Components |