// demonstration of grabbing formulas from columns that have them and making a .CSV // file using the column name with the formula as text data. This does NOT make an // excel formula, but does make a cell with a character string of the formula. // Note that column 3 is intentionally messy (embedded quotation marks in name) just // to test the "quote" function. dt = New Table( "Untitled", Add Rows( 1 ), New Column( "Fred",Set Values( [1] ) ), New Column( "Wilma",Formula( :Fred + :Barney ) ), New Column( "The \!"Flintstones\!"",Set Values( [2] ) ), New Column( "Barney",Formula( :Fred - :Name( "The \!"Flintstones\!"" ) ) ) ); quote = Function( {input}, {}, // the regex doubles all embedded quotation marks, // then the outer quotation marks are added "\!"" || Regex( input, "\!"", "\!"\!"", GLOBALREPLACE ) || "\!"" ); cols = dt << getColumnNames; text = ""; // CSV file built in this string // build the CSV column names for columns with formulas For( i = 1, i <= N Items( cols ), i++, f = cols[i] << getFormula; If( !Is Empty( f ), text = text || quote( Char( cols[i] ) ) || "," ); ); text = Substr( text, 0, Length( text ) - 1 ) || "\!n"; // remove trail comma, add newline // build the CSV data for columns with formulas For( i = 1, i <= N Items( cols ), i++, f = cols[i] << getFormula; If( !Is Empty( f ), text = text || quote( Char( Name Expr( f ) ) ) || "," ); ); text = Substr( text, 0, Length( text ) - 1 ); // remove trail comma Close( dt, "nosave" ); Save Text File( "$TEMP\deleteme.csv", text ); // write the CSV to disk Open( "$TEMP\deleteme.csv" ); // load the CSV