Spread WPF 18
Features / Table / Structured References
In This Topic
    Structured References
    In This Topic

    Spread for WPF supports structured reference formulas in tables. This topic explains how structured references in spreadsheets help refer to table columns, rows, or specific data. It focuses on how to access data in structured formats within a table without using cell addresses.

    The components of a structured reference are illustrated in the following image. This formula adds total sales and tax amounts.

    Annotation Component Description
    1 Table name The name assigned to the table. The name references the table data, but not the header and total rows, if any.
    2 Column specifier It is derived from the column header and references the column data (excluding the column header and total, if any).
    3 Special Item specifier Refers to specific parts of tables or table columns, such as the Totals row.
    4 Table specifier Refers to the outer portion of the structured reference. The specifiers follow the table name and are enclosed in square brackets.
    4 Structured reference Refers to the entire string beginning with the table name and ending with the column specifier.

    Let's understand how to use structured references in tables in detail in the following sections.

    Using Operators and Special Fields

    You can use operators and special fields in the structured reference to manipulate data.

    Use the following reference operators to combine column specifiers to specify cell ranges more flexibly. The "Cell Range" column shows examples in the table below.

    Structured Reference Refers To Operator Cell Range
    =DeptSales[[SalesPerson]:[Region]] All of the cells in two or more adjacent columns : (colon) range operator A2:B7
    =DeptSales[SaleAmt],DeptSales[ComAmt] A combination of two or more columns , (comma) union operator C2:C7, E2:E7
    =DeptSales[[SalesPerson]:[SaleAmt]] DeptSales[[Region]:[ComPct]] The intersection of two or more columns  (space) intersection operator B2:C7

    Special fields allow you to refer to different parts of a table, such as a Total row, making it easier to refer to these parts in formulas. The following are the special field specifiers that can be used for structured references.

    Special Item Specifiers Reference Cell Range
    =DeptSales[#All] The entire table, including column headers, data, and totals (if any) A1:E8
    =DeptSales[#Data] Data only A2:E7
    =DeptSales[#Headers] Header row only A1:E1
    =DeptSales[#Totals] The total row only. If not exists, then it returns null A8:E8
    =DeptSales[#This Row] Only the part of the column in the current row. "#thisrow" cannot be used in combination with other special item specifiers. Use this special item specifier to force an implicit conjunction operation on a reference, or to override the implicit conjunction operation and reference a single value in a column.

    When you create a calculated column, you often use a structured reference to create the formula. A structured reference can be unqualified or fully qualified.

    An unqualified structured reference can be used within a table, for example, when creating a column that calculates a fee in dollars. However, when you use a structured reference outside a table, make sure it's a fully qualified structured reference.

    Structured Reference Example  Comment
    Unqualified =[SaleAmt]*[ComPct] Multiplies the corresponding values from the current row.
    Fully qualified =DeptSales[SaleAmt]*DeptSales[ComPct] Multiples the corresponding values for each row for both columns.

    Understanding Structured Reference Syntax Rules

    This section outlines the rules for writing structured references, such as how to reference table names, column headers, and ensure proper formats when using brackets and quotes.

    Using Structured References

    You can add structured references in a table using the Formula property of the IRange interface. A cell outside the table can have a formula with a table reference; make sure that the table name is unique and valid.

    The following example code shows how to use a structured reference in a formula. Here, it sums the "Value" column in the table.

    Copy Code
    // Use structured references.
    spreadSheet1.Workbook.Worksheets[0].Cells[1, 1].Text = "Name" ;
    spreadSheet1.Workbook.Worksheets[0].Cells[1, 2].Text = "value" ;
    spreadSheet1.Workbook.Worksheets[0].Cells[2, 1].Text = "Aoki" ;
    spreadSheet1.Workbook.Worksheets[0].Cells[2, 2].Value = 50;
    spreadSheet1.Workbook.Worksheets[0].Cells[3, 1].Text = "Gill" ;
    spreadSheet1.Workbook.Worksheets[0].Cells[3, 2].Value = 10;
    spreadSheet1.Workbook.Worksheets[0].Cells[4, 1].Text = "Smith" ;
    spreadSheet1.Workbook.Worksheets[0].Cells[4, 2].Value = 78;
    spreadSheet1.Workbook.Worksheets[0].Tables.Add(1, 1, 4, 2, YesNoGuess.Yes, null , "Table" );
    spreadSheet1.Workbook.Worksheets[0].Cells[5, 2].Formula = "SUM(Table[value])" ;
    spreadSheet1.Workbook.Worksheets[0].Columns[1, 2].ColumnWidth = 150;
    
    Copy Code
    ' Use structured references.
    spreadSheet1.Workbook.Worksheets(0).Cells(1, 1).Text = "Name"
    spreadSheet1.Workbook.Worksheets(0).Cells(1, 2).Text = "value"
    spreadSheet1.Workbook.Worksheets(0).Cells(2, 1).Text = "Aoki"
    spreadSheet1.Workbook.Worksheets(0).Cells(2, 2).Value = 50
    spreadSheet1.Workbook.Worksheets(0).Cells(3, 1).Text = "Gill"
    spreadSheet1.Workbook.Worksheets(0).Cells(3, 2).Value = 10
    spreadSheet1.Workbook.Worksheets(0).Cells(4, 1).Text = "Smith"
    spreadSheet1.Workbook.Worksheets(0).Cells(4, 2).Value = 78
    spreadSheet1.Workbook.Worksheets(0).Tables.Add(1, 1, 4, 2, YesNoGuess.Yes, Nothing, "Table")
    spreadSheet1.Workbook.Worksheets(0).Cells(5, 2).Formula = "SUM(Table[value])"
    spreadSheet1.Workbook.Worksheets(0).Columns(1, 2).ColumnWidth = 150