Back to Devexpress

DocumentOptions.CalculationMode Property

officefileapi-devexpress-dot-spreadsheet-dot-documentoptions-f17afee6.md

latest7.9 KB
Original Source

DocumentOptions.CalculationMode Property

Gets or sets the calculation mode that specifies when to calculate formulas in a Workbook or Spreadsheet control.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
[Browsable(false)]
public WorkbookCalculationMode CalculationMode { get; set; }
vb
<Browsable(False)>
Public Property CalculationMode As WorkbookCalculationMode

Property Value

TypeDescription
WorkbookCalculationMode

An enumeration member that specifies the calculation mode. The default is UseDocumentSettings for the WinForms and WPF Spreadsheet, and Manual for a Workbook component.

|

Available values:

NameDescription
UseDocumentSettings

Uses the calculation mode specified in the document (this value is stored in the CalculationOptions.Mode property).

| | Manual |

Ignores the document’s calculation mode and starts calculation only on user request or after the Calculate method call. Never recalculates formulas when the document is loaded or before it is saved.

| | Automatic |

Ignores the document’s calculation mode and recalculates formulas each time a cell value, formula, or defined name changes.

|

Property Paths

You can access this nested property as listed below:

Object TypePath to CalculationMode
ISpreadsheetComponent

.Options .CalculationMode

|

Remarks

The CalculationMode property allows you to override the calculation mode of the loaded document (this setting is stored in the IWorkbook.DocumentSettings.Calculation.Mode property).

For instance, use Automatic mode for the Spreadsheet control if it should recalculate all dependent formulas every time a value, formula, or name referenced in these formulas changes.

csharp
spreadsheetControl1.Options.CalculationMode = WorkbookCalculationMode.Automatic;
vb
spreadsheetControl1.Options.CalculationMode = WorkbookCalculationMode.Automatic

Use Manual mode for a non-visual Workbook to improve document generation speed for large workbooks with multiple formulas. Call the Workbook.Calculate, Worksheet.Calculate, or CellRange.Calculate method to calculate formulas in the document.

csharp
using (Workbook workbook = new Workbook())
{
    // Disable automatic calculations.
    workbook.Options.CalculationMode = WorkbookCalculationMode.Manual;
    // ...
    // Generate the document content.
    // ...
    // Perform calculations if needed.
    workbook.Calculate();
}
vb
Using workbook As New Workbook()
  ' Disable automatic calculations.
  workbook.Options.CalculationMode = WorkbookCalculationMode.Manual
  ' ...
  ' Generate the document content.
  ' ...
  ' Perform calculations if needed.
  workbook.Calculate()
End Using

The following code snippets (auto-collected from DevExpress Examples) contain references to the CalculationMode property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

spreadsheet-document-api-examples-part1/CS/SpreadsheetExamples/Form1.cs#L18

csharp
InitTreeListControl();
    workbook.Options.CalculationMode = WorkbookCalculationMode.Automatic;
}

spreadsheet-document-api-pivot-table-examples/CS/SpreadsheetDocServerPivotAPI/Form1.cs#L22

csharp
InitTreeListControl();
    workbook.Options.CalculationMode = WorkbookCalculationMode.Automatic;
}

spreadsheet-document-api-chart-examples/CS/SpreadsheetDocServerChartAPISamples/Form1.cs#L27

csharp
InitTreeListControl();
    workbook.Options.CalculationMode = WorkbookCalculationMode.Automatic;
}

spreadsheet-document-api-examples-part2/CS/SpreadsheetDocServerAPIPart2/Form1.cs#L18

csharp
InitTreeListControl();
    workbook.Options.CalculationMode = WorkbookCalculationMode.Automatic;
}

spreadsheet-document-api-examples-part1/VB/SpreadsheetExamples/Form1.vb#L19

vb
InitTreeListControl()
    workbook.Options.CalculationMode = WorkbookCalculationMode.Automatic
End Sub

spreadsheet-document-api-pivot-table-examples/VB/SpreadsheetDocServerPivotAPI/Form1.vb#L21

vb
InitTreeListControl()
    workbook.Options.CalculationMode = WorkbookCalculationMode.Automatic
End Sub

spreadsheet-document-api-chart-examples/VB/SpreadsheetDocServerChartAPISamples/Form1.vb#L22

vb
InitTreeListControl()
    workbook.Options.CalculationMode = WorkbookCalculationMode.Automatic
End Sub

spreadsheet-document-api-examples-part2/VB/SpreadsheetDocServerAPIPart2/Form1.vb#L17

vb
InitTreeListControl()
    workbook.Options.CalculationMode = WorkbookCalculationMode.Automatic
End Sub

See Also

DocumentOptions Class

DocumentOptions Members

DevExpress.Spreadsheet Namespace