Documents for Excel, Java Edition Documentation
File Operations / Import and Export .xlsx Document
In This Topic
    Import and Export .xlsx Document
    In This Topic

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

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

    GcExcel Java 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 Java 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 getDoNotRecalculateAfterOpened and the setDoNotRecalculateAfterOpened methods of the XlsxOpenOptions class allows users to get or 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 to import and export .xlsx document.

    Java
    Copy Code
    // Initialize workbook
    Workbook workbook = new Workbook();
            
    // Setting ImportFlags
    EnumSet<ImportFlags> impFlags;
    impFlags = 
    EnumSet.of(ImportFlags.Data, ImportFlags.Formulas, 
    ImportFlags.Table, ImportFlags.Style);
            
    // Setting XlsxOpenOptions
    XlsxOpenOptions options = new XlsxOpenOptions();
    options.setImportFlags(impFlags);
            
    // Opening excel file with XlsxOpenOptions
    workbook.open("test.xlsx", options);
    
    // Saving the workbook to xlsx
    workbook.save("ImportFlagsForOpenOptions.xlsx");