Spread Silverlight Documentation
Importing and Exporting Excel Files
Spread Silverlight Documentation > Developer's Guide > Managing Data > Importing and Exporting Excel Files

You can save or load Excel-formatted files and specify various save or load options.

You can specify whether to save to a BIFF or OfficeXML formatted file. BIFF (Binary Interchange File Format) is well known as the default file format for Microsoft Office Excel 97-2003, and the default file extension is .XLS. Office Open XML is well known as the default file format for Microsoft Office Excel 2007, and the default file extension is .XLSX. You can use the ExcelSaveFlags enumeration in the SaveExcel method to specify additional options such as custom row and column headers or data only. You can also specify a password when exporting to a file.

You can specify additional load options with the ExcelOpenFlags enumeration in the OpenExcel method. You can also specify a password string when loading an Excel-formatted file.

You can use the ExcelError event and the ExcelWarning class to return error codes and get unsupported records.

Charts are not imported and formulas in tables may not be imported correctly when loading Excel-formatted files.

Using Code

The following example uses the SaveExcel and OpenExcel methods to save and load files.

CS
Copy Code

SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "Excel File (.xlsx)|*.xlsx";
bool? useClick = saveFileDialog.ShowDialog();
if (useClick == true)
{
    var stream = saveFileDialog.OpenFile();
    gcSpreadSheet1.SaveExcel(stream, GrapeCity.Windows.SpreadSheet.Data.ExcelFileFormat.XLSX);
    //gcSpreadSheet1.SaveExcel(stream, GrapeCity.Windows.SpreadSheet.Data.ExcelFileFormat.XLSX, GrapeCity.Windows.SpreadSheet.Data.ExcelSaveFlags.DataOnly);
    //gcSpreadSheet1.SaveExcel(stream, GrapeCity.Windows.SpreadSheet.Data.ExcelFileFormat.XLSX, GrapeCity.Windows.SpreadSheet.Data.ExcelSaveFlags.DataOnly, "12Test9");
    //gcSpreadSheet1.SaveExcel(stream, GrapeCity.Windows.SpreadSheet.Data.ExcelFileFormat.XLSX, "12Test9");
    stream.Dispose();
}

// Or

OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Excel File (.xlsx)|*.xlsx";
bool? useClick = openFileDialog.ShowDialog();
if (useClick == true)
{
    var stream = openFileDialog.File.OpenRead();
    stream.Seek(0, System.IO.SeekOrigin.Begin);
     gcSpreadSheet1.OpenExcel(stream);
    //gcSpreadSheet1.OpenExcel(stream, GrapeCity.Windows.SpreadSheet.Data.ExcelOpenFlags.DataOnly);
    //gcSpreadSheet1.OpenExcel(stream, GrapeCity.Windows.SpreadSheet.Data.ExcelOpenFlags.DataOnly, "12Test9");
    //gcSpreadSheet1.OpenExcel(stream, "12Test9");
    stream.Dispose();
}

VB.NET
Copy Code

Dim saveFileDialog = New SaveFileDialog()
saveFileDialog.Filter = "Excel File(.xlsx)|*.xlsx"
Dim useClick As Boolean = saveFileDialog.ShowDialog()
If (useClick = True) Then
    Dim stream = saveFileDialog.OpenFile()
    GcSpreadSheet1.SaveExcel(stream, GrapeCity.Windows.SpreadSheet.Data.ExcelFileFormat.XLSX)
    'GcSpreadSheet1.SaveExcel(stream, GrapeCity.Windows.SpreadSheet.Data.ExcelFileFormat.XLSX, GrapeCity.Windows.SpreadSheet.Data.ExcelSaveFlags.DataOnly)
    'GcSpreadSheet1.SaveExcel(stream, GrapeCity.Windows.SpreadSheet.Data.ExcelFileFormat.XLSX, GrapeCity.Windows.SpreadSheet.Data.ExcelSaveFlags.DataOnly, "12Test9")
    'GcSpreadSheet1.SaveExcel(stream, GrapeCity.Windows.SpreadSheet.Data.ExcelFileFormat.XLSX, "12Test9")
End If

' Or

Dim openFileDialog = New OpenFileDialog()
openFileDialog.Filter = "Excel File(.xlsx)|*.xlsx"
Dim useClick As Boolean = openFileDialog.ShowDialog()
If (useClick = True) Then
    Dim stream = openFileDialog.File.OpenRead()
    stream.Seek(0, IO.SeekOrigin.Begin)
    GcSpreadSheet1.OpenExcel(stream)
    'GcSpreadSheet1.OpenExcel(stream, GrapeCity.Windows.SpreadSheet.Data.ExcelOpenFlags.DataOnly)
    'GcSpreadSheet1.OpenExcel(stream, GrapeCity.Windows.SpreadSheet.Data.ExcelOpenFlags.DataOnly, "12Test9")
    'GcSpreadSheet1.OpenExcel(stream, "12Test9")
End If

See Also