[]
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.
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. |
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.
Use matching brackets for specifiers
All table, column, or special item specifiers must be enclosed inside brackets. A specifier that contains other specifiers requires outer matching brackets to enclose the inner matching brackets of the other specifiers. For example,
=DeptSales[[SalesPerson]:[Region]]
Do not use quotes for column headers
All column headers are text strings, but there’s no need to put quotes around them in a structured reference. Even if a column header contains numbers or dates (like 2004 or 1/1/2004), they are still considered text strings. Also, you cannot use expressions within the brackets for the column headers. For example,
=DeptSalesFYSummary[[2004]:[2002]]
Use matching brackets for column headers with special characters
If a column header has special characters, enclose the whole header in matching brackets. These special characters include space, tab, line feed, carriage return, comma (,), colon (:), period (.), left bracket ([), right bracket (]), pound sign (#), single quotation mark ('), double quotation("), left brace ({), right brace (}), dollar sign ($), caret (^), ampersand (&), asterisk (*), plus sign (+), equal sign (=), minus sign (-), greater than symbol (>), less than symbol (<), and division sign (/). For example,
=DeptSalesFYSummary[[Total$Amount]]
!type=note
Note: The only exception to this is if the only special character that is used is a space character. For example,
=DeptSales[Total Amount]
Use single quotation marks for special characters
If a column header contains a character having a special meaning, such as bracket ([), right bracket (]), pound sign(#), and single quotation mark ('), you should use a single quotation mark (') as an escape character for it. The following example illustrates a structured reference that contains a character with a special meaning. For example,
=DeptSalesFYSummary['#OfItems]
Use space characters to improve the readability
You can add space characters to improve the readability of a structured reference. You can use one space after the first left bracket ([) and before the last right bracket (]). You can also add a space after a comma, as shown in the following example. For example,
=DeptSales[ [SalesPerson]:[Region] ]
=DeptSales[[#Headers], [#Data], [ComPct]]
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.
C#
// 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;
VB
' 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