I have the following data table, how can I export the column using JSL:
1. string = 561193, 542003, 527679...
2. export the data to .txt where the values show: 561193, 542003, 527679...
s
Here is one way to do it
Names Default To Here( 1 ); // Create an example data table dt = New Table( "Example", add rows( 100 ), New Column( "Number", character, set each value( Char( Random Integer( 1000, 9999 ) ) ) ) ); // Convert character column to a literal string value string = Concat Items( dt:number[Index( 1, N Rows( dt ) )], "," ); // Write the string variable to a .txt file Save Text File( "$TEMP/savedfile.txt", string );
@txnelson ,thank you very much for reply. it really works.
I am new JSLer. I have to seek for your help here: How can I use the selected column to replace "dt:number" in following JSL?
Names Default To Here( 1 ); dt = Current Data Table( ); // Stop the script if no open data tables If( Is Empty( dt ), Stop()); // Make list of column names colNames = dt << get column names(); // Select the column nw = New Window("Column names", <<Modal, PanelBox("Pick a column", dtlb = ListBox(colNames, MaxSelected(1), columnSelected = (dtlb << get selected)[1] ) ), H List Box( ButtonBox("OK"), button box("Cancel"); ) ); If( nw["button"] == -1, throw() ); // Convert character column to a literal string value inString = "'" || Concat Items( dt:number[Index( 1, N Rows( dt ) )], "','" ) || "'";
Names Default To Here( 1 ); dt = Current Data Table( ); // Stop the script if no open data tables If( Is Empty( dt ), Stop()); // Make list of column names colNames = dt << get column names(); // Select the column nw = New Window("Column names", <<Modal, PanelBox("Pick a column", dtlb = ListBox(colNames, MaxSelected(1), columnSelected = (dtlb << get selected)[1] ) ), H List Box( ButtonBox("OK"), button box("Cancel"); ) ); If( nw["button"] == -1, throw() ); // Convert character column to a literal string value inString = "'" || Concat Items( column(columnSelected)<<get values, "','" ) || "'"; // The above will work only if the column selected is a character column // I suggest that you change your "<< get column names()" to // "<< get column names(character)"
@txnelson thank you very much!