Documents for Excel .NET Edition | GCDocuments
File Operations / Import and Export .xlsx Document
In This Topic
    Import and Export .xlsx Document
    In This Topic

    This section summarizes how GcExcel .NET handles the spreadsheet documents(.xlsx files).

    When you create a workbook using GcExcel .NET and save it, you automatically export it to an external location or folder. When bringing an Excel file into GcExcel .NET (importing a file or opening a file) and when saving GcExcel .NET files to an Excel format (exporting), most of the data can be imported or exported successfully. The intention of providing the support for import and export capability is to enable users to handle as much of the data and formatting of a spreadsheet as possible.

    GcExcel .NET also provides support for preserving the Japanese Ruby characters while executing the import and export operations on an Excel file. Also, users can adjust cells containing Japanese Ruby characters with utmost accuracy after performing other spreadsheet tasks like Insert, Delete, Copy, Cut, Merge, Clear, Sort operations etc.

    Working With Import Flags

    While opening a workbook, GcExcel .NET also provides you with several open options that can be used during the import operation.

    The ImportFlags enumeration allows users to import the workbook with the specified open options (a total of ten options are available: NoFlag, Data and Formulas, Table, mergeArea, Style, ConditionalFormatting, DataValidation, PivotTable and Shapes) as described in the table shared below.

    Import Flag Option Description
    NoFlag Refers to "No option". This option is used when you don't want to put any import flag while opening the Excel file. This means that all the data in the worksheet will be imported as it is.
    Data Refers to "Read the Data". This option is used when you want to import only the data in the worksheet while opening the Excel file.
    Formulas Refers to "Read the Data and Formulas". This option is used when you want to import both the data and the formulas in the worksheet while opening the Excel file.
    Table Refers to "Read the Tables". This option is used when you want to import only the tables in the worksheet while opening the Excel file.
    MergeArea Refers to "Read the Merge Cells". This option is used when you want to import only the merged cells or spanned cells in the worksheet while opening the Excel file.
    Style Refers to "Read the Styles".  This option is used when you want to import only the styles applied to the cells in the worksheet while opening the Excel file.
    ConditionalFormatting Refers to "Read the Conditional Formatting". This option is used when you want to import only the conditional formatting rule applied to the worksheet while opening the Excel file.
    DataValidation Refers to "Read the Data Validation". This option is used when you want to import only the data validation rule applied to the worksheet while opening the Excel file.
    PivotTable Refers to "Read the Pivot Tables". This option is used when you want to import only the pivot tables in the worksheet while opening the Excel file.
    Shapes Refers to "Read all the Shapes". This option is used when you want to import only the shapes embedded in the worksheet while opening the Excel file.

    The DoNotRecalculateAfterOpened property of the XlsxOpenOptions class allows users to set a boolean value (True or False) which specifies whether or not the formulas will be recalculated when the file is being imported.

    Refer to the following example code in order to import and export .xlsx document.

    C#
    Copy Code
    // Create workbook and access its first worksheet
    Workbook workbook = new Workbook();
    IWorksheet worksheet = workbook.Worksheets[0];
                
    // Assigning value to range
    worksheet.Range["A3"].Value = 5;
    worksheet.Range["A2"].Value = 5;
    worksheet.Range["A1"].Value = 5;
    worksheet.Range["B1"].Value = 5;
                
    // Exporting .xlsx document
    workbook.Save(@"savingfile.xlsx", SaveFileFormat.Xlsx);
    
    // Exporting .xlsx document while setting password
    XlsxSaveOptions options = new XlsxSaveOptions();
    options.Password = "Pwd";
    workbook.Save(@"savingfile.xlsx", options);
    
    // Importing .xlsx document
    workbook.Open(@"Source.xlsx", OpenFileFormat.Xlsx);
    
    // Importing .xlsx document with Open options
    
    // Import only data from .xlsx document.
    XlsxOpenOptions options = new XlsxOpenOptions();
    options.ImportFlags = ImportFlags.Data;
    workbook.Open(@"Source.xlsx", options);
    
    // Don't recalculate after opened.
    XlsxOpenOptions options1 = new XlsxOpenOptions();
    options1.DoNotRecalculateAfterOpened = true;
    workbook.Open(@"Source.xlsx", options1);