QuickStart: Excel for Silverlight > Step 3 of 4: Saving the XLSX File |
Add the following code to save the Excel workbook. When you run the application, the code will open the Save As dialog box so you can save your .xlsx file wherever you'd like.
Visual Basic |
Copy Code
|
---|---|
Private Sub SaveBook(action As Action(Of C1XLBook)) Dim dlg = New SaveFileDialog() dlg.Filter = "Excel Files (*.xlsx)|*.xlsx" If dlg.ShowDialog() = True Then Try Dim book = New C1XLBook() RaiseEvent action(book) Using stream = dlg.OpenFile() book.Save(stream) End Using Catch x As Exception MessageBox.Show(x.Message) End Try End If End Sub |
C# |
Copy Code
|
---|---|
private void SaveBook(Action<C1XLBook> action) { var dlg = new SaveFileDialog(); dlg.Filter = "Excel Files (*.xlsx)|*.xlsx"; if (dlg.ShowDialog() == true) { try { var book = new C1XLBook(); if (action != null) { action(book); } using (var stream = dlg.OpenFile()) { book.Save(stream); } } catch (Exception x) { MessageBox.Show(x.Message); } } } |