This section summarizes how Spread.Services handles the spreadsheet documents(.xlsx files).
When you create a workbook using Spread.Services and save it, you automatically export it to an external location or folder. When bringing an Excel file into Spread.Services (importing a file or opening a file) and when saving Spread.Services 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.
Also, while importing a workbook, Spread.Services provides you with several import options including Import Flags and DoNotRecalculateAfterOpened. The Import Flags option allows users to import the workbook with the specified open options (three options are available: NoFlag, Data and Formulas). The DoNotRecalculateAfterOpened option allows users to set a boolean value (True or False) in order to specify whether or not they want to get the formulas recalculated when the file is being opened.
Refer to the following example code 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"); // Importing .xlsx document workbook.Open("Source.xlsx"); // Importing .xlsx document with Open options //Import only data from .xlsx document. var openOptions = new OpenOptions(); openOptions.ImportFlags = ImportFlags.Data; workbook.Open("Source.xlsx", null, openOptions); //Don't recalculate after opened. var openOptions = new OpenOptions(); openOptions.DoNotRecalculateAfterOpened = true; workbook.Open("Source.xlsx", null, openOptions); |