[]
        
(Showing Draft Content)

Load Files

You can open files of different formats into the Spread for WPF, where you can analyze the data or make any changes. Supported file formats include Excel files and XML data files.

This topic provides the methods for opening several file types.

Supported Formats

Load an Excel File

To open an existing Excel workbook, you can use the OpenExcel method of the GcSpreadSheet class. This method opens the specified Excel in the GcSpreadSheet control and replaces the current workbook with the newly opened workbook.

Refer to the following example code to open an Excel file using a filename.

C#

// Open an Excel file.
spreadSheet1.OpenExcel(@"D:\TestFile.xlsx");

VB

' Open an Excel file.
spreadSheet1.OpenExcel("D:\TestFile.xlsx")

Load an XML File

To load and open an XML data file in a workbook, use the OpenXML method of the IWorkbooks interface which accepts string type filename/stream as its parameter. It returns a new workbook in the same workbook set but does not replace the data of the current workbook. You need to keep the reference to the new workbook to perform further operations.

The following example code opens an XML data file using a filename.

C#

// Open an XML data file.
var book2 = spreadSheet1.Workbook.WorkbookSet.Workbooks.OpenXML(@"D:\\DataFormat.xml");
MessageBox.Show(book2.Worksheets[0].Cells["A1"].Value.ToString());

VB

' Open an XML data file.
Dim book2 = spreadSheet1.Workbook.WorkbookSet.Workbooks.OpenXML("D:\\DataFormat.xml")
MessageBox.Show(book2.Worksheets(0).Cells("A1").Value.ToString())