Spread Windows Forms 12.0 Product Documentation
Opening an Excel File
Spread Windows Forms 12.0 Product Documentation > Developer's Guide > Managing File Operations > Opening Existing Files > Opening an Excel File

You can open an existing Excel-formatted file (BIFF8 format or xlsx) in Spread. You can open the entire multiple-sheet file into the Spread component or specify a particular sheet (either by name or number) and open it into a specific sheet.

Spread can be used in both bound and unbound modes. When opening an Excel file, Spread is being used in the unbound mode and thus the DataSource property returns null (or Nothing in Visual Basic).

Use one of the OpenExcel methods of the FpSpread class to open all the sheets in the Excel file, providing the path and file name for the file to open and any additional information. You can specify additional open options with the ExcelOpenFlags enumeration. This enumeration allows you to determine how frozen columns and rows are imported, if data only is imported, and other options. To open a specific sheet of the Excel file, use one of the OpenExcel methods of the SheetView class, specifying the sheet by name or number.

The Document caching option in the ExcelOpenFlags or ExcelSaveFlags enumeration allows users to open, edit, and save without the loss of advanced document content and formatting. The content can be lossless only if the opening file format is similar to the saving file format. If the advanced document content uses files besides the xls(x) file, then the additional files need to be in the same folder with the xls(x) file. Advanced content could be macros, ActiveX controls, data connections, and so on.

Note that the sheet index referring to sheets in the Excel file is zero-based, so the first sheet in the Excel file is 0, the second is 1, and so on.

If the Excel file is open in another application (open in Excel for example) when you are trying to open it in Spread, nothing is imported, and the Spread opens without any imported data.

For more information about how the data is imported from an Excel-formatted file, see the Import and Export Reference.

Using Code

Use one of the OpenExcel methods of the FpSpread class to an Excel file. To open a specific sheet of the Excel file, use one of the OpenExcel methods of the SheetView class (using the Sheets or ActiveSheet shortcut).

Example

This example code opens an entire Excel-formatted file using the method in the FpSpread class, and loads the data from the specified Excel sheet into the specified sheet of the Spread component.

C#
Copy Code
// Open the fourth sheet of the Excel file.
fpSpread1.ActiveSheet.OpenExcel("C:\\excelfile.xls", 3);
VB
Copy Code
' Open the fourth sheet of the Excel file.
fpSpread1.ActiveSheet.OpenExcel("C:\excelfile.xls", 3)

Using the Spread Designer

  1. From the File menu, select Open.
  2. A dialog appears warning you that this overwrites your existing settings if you open a file. Click Yes to continue with the file open.

    The Open dialog appears.

  3. Change the Files of type box to Excel files (*.xls).

    To open a comma-delimited file, change the Files of type box to Comma-delimited files (*.csv).

  4. Specify the path and file name of the file to open, and then click Open.

    If the file is opened successfully, a message appears stating the file has been opened.

  5. Click OK to close the Spread Designer.