Documents for Excel .NET Edition | GCDocuments
Features / Workbook / Open and Save Workbook
In This Topic
    Open and Save Workbook
    In This Topic

    Once you create a workbook, you can open the workbook to make modifications and save the changes back to the workbook.

    This topic includes the following tasks:

    Open a workbook

    You can open an existing workbook by calling the Open method of the Workbook class.

    While opening a workbook, you can also choose from several import options listed in the below table:

                                    Open Options                                                Description
    Import Flags





    Read only the data from the worksheet

    Read only the data, formula, defined names and table from the worksheet. Table is included for table formula.

    DoNotRecalculateAfterOpened Do not recalculate when getting formula value after loading the file. Default is false

    Refer to the following example code to open a workbook.

    Copy Code
    // Opening a workbook
     workbook.Open(@"Source.xlsx", OpenFileFormat.Xlsx);
    //Opening a workbook with Import options
    //Import only data from .xlsx document.
    XlsxOpenOptions options = new XlsxOpenOptions();
    options.ImportFlags = ImportFlags.Data;
    workbook.Open(@"DemoOpen.xlsx", options);
    //Don't recalculate after opened.
    XlsxOpenOptions options1 = new XlsxOpenOptions();
    options1.DoNotRecalculateAfterOpened = true;
    workbook.Open(@"DemoOpen.xlsx", options1);

    Note: While opening the workbook, you can check whether it is password protected or not by using the IsEncryptedFile method of the Workbook class. If your workbook is password protected, you would need to provide a password everytime you open it.

    Apart from .xlsx files, you can also open the below file formats by using the overloads of Open method in Workbook class:

    However, an exception is thrown when unsupported file formats are opened. While opening a JSON file, the DeserializationOptions are supported as well.

    Refer to the following example code to open a JSON file with and without options.

    Copy Code
    //create a new workbook
    var workbook = new GrapeCity.Documents.Excel.Workbook();
    // Import JSON without options
    // Import JSON with options
    var options = new DeserializationOptions { IgnoreStyle = true };
    workbook.Open("file.json", options);

    Save a workbook

    You can save the changes made in the existing workbook by calling the Save method of the Workbook class.

    Refer to the following example code to save your workbook.

    Copy Code
    // Save the Excel file
    workbook.Save(@"createWorkbook.xlsx", SaveFileFormat.Xlsx);
    See Also