Spreadsheet.VariableNames
This property Get an array of all variable names.
C# Example
Converting a spreadsheet to tabular text:
using System.Data; // Note: run this code in a C# workspace node // Access spreadsheet ... var ssObj = InputContainer[0].DataSource; var nrows = ssObj.NumberOfCases; var ncols = ssObj.NumberOfVariables; // Create DataTable object ... DataTable dtObj = new DataTable(); Array varNames = (Array)(object)ssObj.VariableNames; // Add columns ..... foreach(object varName in varNames) { string sVarName = (string)varName; dtObj.Columns.Add(sVarName); } // Populate rows .... for(int i = 1; i <= nrows; i++) { var rowObj = ssObj.GetData(i, 1, 1, ncols, true); DataRow row = dtObj.NewRow(); for(int j = 0; j < ncols; j++) { row[j] = rowObj[1, j + 1]; } dtObj.Rows.Add(row); } // print Data Table ... Console.WriteLine("Data"); Console.WriteLine("-----------------------"); foreach(DataColumn colObj in dtObj.Columns) { Console.Write("{0}\t", colObj.ColumnName); } foreach(DataRow rowObj in dtObj.Rows) { Console.WriteLine(" "); for(int i = 0; i < ncols; i++) { Console.Write("{0}\t\t", rowObj[i]); } } Console.WriteLine("\n-----------------------"); Console.WriteLine("All done!");
Copyright © 2020. Cloud Software Group, Inc. All Rights Reserved.