Spreadsheet.GetData

This function gets spreadsheet data as 2-D array of variant. Text type variables returned as strings, numeric as numbers (or text labels if desired.).

Syntax Parameters Return Value
Function Spreadsheet.GetData( _
    StartCase As Long, _
    nbCases As Long, _
    StartVar As Long, _
    nbVars As Long, _
    Optional LabelsAsText As Boolean = True) As Variant
  • StartCase [in]

The case to start from.

Type: Long

  • nbCases [in]

The number of cases to retrieve.

Type: Long

  • StartVar [in]

The variable to start from.

Type: Long

  • nbVars [in]

The number of variables to retrieve.

Type: Long

  • LabelsAsText [in,optional]

Whether to return labels as strings.

Type: Boolean

Default value: True

Variant

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!");