# Accessing Data from Header or Footer

Learn how to access and utilize header and footer data in spreadsheets to enhance your formulas and calculations. Find detailed examples and code snippets for adding formulas to headers and footers.

## Content

You can add formulas to headers and footers while performing spreadsheet calculations. These formulas can contain references to a cell, cell range, other worksheets, or to itself. In addition to this, the data available in the header or footer can be accessed from any worksheet within the workbook in order to ensure it can be used anywhere in the formulas as and when required.
Different keywords are supported for different regions of a worksheet. These keywords are used in formulas to retrieve data available in specific regions. The table shared below lists the keywords that are supported for a valid formula:

| **Keyword** | **Description** |
| ------- | ----------- |
| #Headers | This keyword refers to the column header rows area. |
| #Data | This keyword refers to the spreadsheet rows area. |
| #Totals | This keyword refers to the column footer rows area. |
| #RowHeaders | This keyword refers to the row header rows area. |

The [Formula](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Cell.Formula.html) property can be used to add formulas for header and footer. When values of referenced cells in source worksheets are modified (using the copy, move, insert or delete operations), the formulas are automatically updated along with the calculated values in the worksheet.
After applying formulas, you can save the workbook to an excel file along with the flags.
Refer to the following table for the detailed list and description of flags that can be applied while saving to an excel file.

| **Keyword** | **Description** |
| ------------------------- | -------------------------------------------------------------------------- |
| SaveCustomRowHeaders flag | Row header is changed to a new range, and the row header formula is saved. |
| SaveCustomColumnHeaders flag | Column header is changed to a new range, and the column header formula is saved. |
| Other flags | Only the data area is saved. |

Users can also make use of structured reference syntax in order to refer to the header or footer area. For more information, refer to the topic [Using Structured References](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-tables/spwin-structref/spwin-structuse) in the documentation.
**Using Code**
You can add formula by specifying the [Formula](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.Cell.Formula.html) property for header or footer.
**Example**
This example shows how to set a formula in different scenarios.

```csharp
// Sheets refer to headers or footers
fpSpread1.Sheets[1].Cells[0, 0].Formula = "SUM(Sheet1[[#Headers],$A$1:$B$2])";
fpSpread1.Sheets[1].Cells[0, 2].Formula = "Sheet2[[#Totals],$A$1]";

// Headers or footers refer to itself
fpSpread1.Sheets[2].ColumnHeader.Cells[0, 3].Formula = "Sheet1[[#Headers],[$B$2]]";
fpSpread1.Sheets[2].ColumnFooter.Cells[0, 5].Formula = "Sheet1[[#Totals],[A3])";

// ColumnFooter refers to sheets
fpSpread1.ActiveSheet.ColumnFooter.Cells[0, 3].Formula = "$A$1";
```

```vbnet
' Sheets refer to headers or footers
fpSpread1.Sheets(1).Cells(0, 0).Formula = "SUM(Sheet1[[#Headers],$A$1:$B$2])"
fpSpread1.Sheets(1).Cells(0, 2).Formula = "Sheet2[[#Totals],$A$1]"

' Headers or footers refer to itself
fpSpread1.Sheets(2).ColumnHeader.Cells(0, 3).Formula = "Sheet1[[#Headers],[$B$2]]"
fpSpread1.Sheets(2).ColumnFooter.Cells(0, 5).Formula = "Sheet1[[#Totals],[A3])"

' ColumnFooter refers to sheets
fpSpread1.ActiveSheet.ColumnFooter.Cells(0, 3).Formula = "$A$1"
```

**Example**
This example shows how to set a formula in RowHeader in order to refer to the data available in a table.

```csharp
// RowHeader refers to table
fpSpread1.ActiveSheet.RowHeader.Cells[9, 0].Formula = "SUM(Table1[[#Totals])";
```

```vbnet
' RowHeader refers to table
fpSpread1.ActiveSheet.RowHeader.Cells(9, 0).Formula = "SUM(Table1[[#Totals])"
```

**Example**
This example shows how to use a custom name for the formula.

```csharp
fpSpread1.AsWorkbook().Names.Add("name_1","Sheet2[[#Headers],$A$1:$B$5]");
fpSpread1.Sheets[1].ColumnHeader.Cells[0, 3].Formula = "name_1 + 2";
```

```vbnet
fpSpread1.AsWorkbook().Names.Add("name_1","Sheet2[[#Headers],$A$1:$B$5]")
fpSpread1.Sheets(1).ColumnHeader.Cells(0, 3).Formula = "name_1 + 2"
```

> !type=note
> **Note:** The worksheet header or footer formulas doesn't support external reference i.e. reference to a cell or a cell range of another workbook is not supported. Also, the references to column footer cannot be exported to XLSX format.

## See Also

[Formulas in Cells](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-cell-formula)
[Placing a Formula in Cells](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-cell-formula/spwin-formulaplace)
[Specifying a Cell Reference in a Formula](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-cell-formula/spwin-formulacellref)
[Specifying a Sheet Reference in a Formula](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-cell-formula/spwin-formulasheetref)
[Specifying an External Reference in a Formula](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-cell-formula/spwin-externalref)
[Using a Circular Reference in a Formula](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-cell-formula/spwin-formulacircref)
[Nesting Functions in a Formula](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-cell-formula/spwin-formulanested)
[Recalculating and Updating Formulas Automatically](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-cell-formula/spwin-formularecalc)
[Finding a Value Using GoalSeek](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-cell-formula/spwin-formula-goalseek)
[Allowing the User to Enter Formulas](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-cell-formula/spwin-formulaallowuser)
[Creating and Using a Custom Name](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-cell-formula/spwin-formulacustomname)
[Creating and Using a Custom Function](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-cell-formula/spwin-formulacustomfunc)
[Creating and Using External Variable](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-cell-formula/spwin-external-variable)
[Using the Array Formula](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-cell-formula/spwin-arrayformula)
[Working with the Formula Text Box](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-cell-formula/spwin-formulabar)
[Setting up the Name Box](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-cell-formula/spwin-namebox)
[Using Language Package](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-cell-formula/UsingLanguagePackage)
[Managing External Reference](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-cell-formula/spwin-extrenalreference)
[Working With Dynamic Array Formulas](/spreadnet/docs/latest/online-win/overview/spwin-devguide/spwin-cell-formula/WorkingWithDynamicArrayFormulas)