You can open an existing Excel-formatted (BIFF8 format or XLSX) file or stream. With the SheetView object, you can open a specific Excel sheet to a specific sheet, the currently active sheet, in Spread. You can specify which sheet in Excel to open, either by the sheet index or by the sheet name. There are several OpenExcel methods each with several options.
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, etc. In order to keep any document caching settings (changes would be lost during a postback), open the original file with the document caching only setting and then save the file using the document caching setting.
You can also open a file from inside Spread Designer.
For more information about how the data is imported from the Excel format, see the Import and Export Reference.
Return to the overview at Opening Existing Files.
Using Code
Use the FpSpread object’s OpenExcel method, providing the path and file name for the file to open, or providing additional information using one of the overloaded methods.
Example
This example code opens an Excel-formatted file, loads the data from the specified Excel sheet into this sheet, and sets the number of rows displayed on a single page to match the number of rows in the Excel file.
C# | Copy Code |
---|---|
FpSpread1.OpenExcel("c:\\excelfile.xls", 2);
FpSpread1.ActiveSheetView.PageSize = FpSpread1.Rows.Count;
|
VB | Copy Code |
---|---|
FpSpread1.OpenExcel("c:\excelfile.xls", 2)
FpSpread1.ActiveSheetView.PageSize = FpSpread1.Rows.Count
|
Using the Spread Designer
- Select the File menu.
- Choose the Open option.
- A dialog appears warning you that you will overwrite your existing settings if you open a file. Click Yes to continue with the file open.
The Open dialog appears.
- Change the Files of type box to Excel files (*.XLS).
- 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.
- Set the PageSize property to the number of rows in the page.
- Click OK to close the Spread Designer.