Back to Devexpress

Workbook.BeginUpdate() Method

officefileapi-devexpress-dot-spreadsheet-dot-workbook-5faad678.md

latest8.6 KB
Original Source

Workbook.BeginUpdate() Method

Locks the Workbook object until the Workbook.EndUpdate method is called.

You need a license for the DevExpress Office File API Subscription or DevExpress Universal Subscription to use this method in production code.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Docs.v25.2.dll

NuGet Package : DevExpress.Document.Processor

Declaration

csharp
public void BeginUpdate()
vb
Public Sub BeginUpdate

Remarks

Enclose your code in the BeginUpdate - EndUpdate() method calls to improve performance when you apply multiple modifications to a document.

Each call to BeginUpdate must be paired with the EndUpdate() call. You can use the try…finally statement to ensure that EndUpdate() is always called even if an exception occurs.

The following example shows how to use the BeginUpdate - EndUpdate() methods.

csharp
// Create a new document.
Workbook workbook = new Workbook();

workbook.BeginUpdate();
try
{
    Worksheet worksheet = workbook.Worksheets[0];
    workbook.Unit = DevExpress.Office.DocumentUnit.Point;

    // Create a multiplication table.
    worksheet.Cells["A1"].Value = "*";
    for(int i = 1; i < 11; i++)
    {
        // Create a header column.
        worksheet.Columns["A"][i].Value = i;
        // Create a header row.
        worksheet.Rows["1"][i].Value = i;
    }

    // Multiply values of header cells.
    worksheet.Range["B2:K11"].Formula = "=B$1*$A2";

    // Obtain the data range.
    CellRange tableRange = worksheet.GetDataRange();

    // Specify the row height and column width.
    tableRange.RowHeight = 40;
    tableRange.ColumnWidth = 40;

    // Align the table content.
    tableRange.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
    tableRange.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;

    // Fill the header cells.
    CellRange headerCells = worksheet.Range.Union(worksheet.Range["A1:K1"], worksheet.Range["A2:A11"]);
    headerCells.FillColor = Color.FromArgb(0xf7, 0x9b, 0x77);
    headerCells.Font.Bold = true;

    // Fill cells that contain multiplication results.
    worksheet.Range["B2:K11"].FillColor = Color.FromArgb(0xfe, 0xf2, 0xe4);
}
finally
{
    workbook.EndUpdate();
}
vb
' Create a new document.
Dim workbook As New Workbook()

workbook.BeginUpdate()
Try
    Dim worksheet As Worksheet = workbook.Worksheets(0)
    workbook.Unit = DevExpress.Office.DocumentUnit.Point

    ' Create a multiplication table.
    worksheet.Cells("A1").Value = "*"
    For i As Integer = 1 To 10
        ' Create a header column.
        worksheet.Columns("A")(i).Value = i
        ' Create a header row.
        worksheet.Rows("1")(i).Value = i
    Next i

    ' Multiply values of header cells.
    worksheet.Range("B2:K11").Formula = "=B$1*$A2"

    ' Obtain the data range.
    Dim tableRange As CellRange = worksheet.GetDataRange()

    ' Specify the row height and column width.
    tableRange.RowHeight = 40
    tableRange.ColumnWidth = 40

    ' Align the table content.
    tableRange.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center
    tableRange.Alignment.Vertical = SpreadsheetVerticalAlignment.Center

    ' Fill the header cells.
    Dim headerCells As CellRange = worksheet.Range.Union(worksheet.Range("A1:K1"), worksheet.Range("A2:A11"))
    headerCells.FillColor = Color.FromArgb(&Hf7, &H9b, &H77)
    headerCells.Font.Bold = True

    ' Fill cells that contain multiplication results.
    worksheet.Range("B2:K11").FillColor = Color.FromArgb(&Hfe, &Hf2, &He4)
Finally
    workbook.EndUpdate()
End Try

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

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-import-data-from-data-sources/CS/DataImportExample/Form1.cs#L22

csharp
Workbook workbook = new Workbook();
workbook.BeginUpdate();
try

spreadsheet-document-api-examples-part2/CS/SpreadsheetDocServerAPIPart2/CodeExamples/PictureActions.cs#L16

csharp
#region #InsertPicture
workbook.BeginUpdate();
// Set the measurement unit to Millimeter.

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

csharp
{
    workbook.BeginUpdate();
    codeEditor.BeforeCompile();

spreadsheet-document-api-chart-examples/CS/SpreadsheetDocServerChartAPISamples/CodeExamples/SeriesActions.cs#L95

csharp
workbook.Worksheets.ActiveWorksheet = worksheet;
workbook.BeginUpdate();

spreadsheet-document-api-examples-part1/CS/SpreadsheetExamples/SpreadsheetActions/CellActions.cs#L56

csharp
static void SetValueFromText(Workbook workbook) {
    workbook.BeginUpdate();
    try {

spreadsheet-document-api-import-data-from-data-sources/VB/DataImportExample/Form1.vb#L17

vb
Dim workbook As New Workbook()
workbook.BeginUpdate()
Try

spreadsheet-document-api-examples-part2/VB/SpreadsheetDocServerAPIPart2/CodeExamples/PictureActions.vb#L13

vb
' #Region "#InsertPicture"
            workbook.BeginUpdate()
            ' Set the measurement unit to Millimeter.

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

vb
Private Sub evaluator_OnBeforeCompile(ByVal sender As Object, ByVal e As EventArgs)
    workbook.BeginUpdate()
    codeEditor.BeforeCompile()

spreadsheet-document-api-chart-examples/VB/SpreadsheetDocServerChartAPISamples/CodeExamples/SeriesActions.vb#L89

vb
workbook.Worksheets.ActiveWorksheet = worksheet
workbook.BeginUpdate()

See Also

EndUpdate()

Workbook Class

Workbook Members

DevExpress.Spreadsheet Namespace