Excel for Silverlight supports saving and loading comma-separated values (CSV) files. CSV is a common file format that stores tabular data, including numbers and text, in plain text form for easy readability.
The following code provides an example of how to save a .csv file.
Visual Basic |
Copy Code
|
---|---|
Imports C1.Silverlight.Excel
|
C# |
Copy Code
|
---|---|
using C1.Silverlight.Excel;
|
C# |
Copy Code
|
---|---|
public partial class MainPage : UserControl { C1XLBook _book = new C1XLBook(); public MainPage() { InitializeComponent(); XLSheet sheet = _book.Sheets[0]; for (int i = 0; i <= 9; i++) { sheet[i, 0].Value = i + 1; sheet[i, 1].Value = 10 - i; } } } |
C# |
Copy Code
|
---|---|
private void _btnSave_Click(object sender, RoutedEventArgs e) { var dlg = new SaveFileDialog(); dlg.Filter = "Comma-Separated Values (*.csv)|*.csv"; if (dlg.ShowDialog().Value) { try { // information txt_Status.Text = string.Format("Saving {0}...", dlg.SafeFileName); // save workbook using (var stream = dlg.OpenFile()) { _book.Sheets[0].SaveCsv(stream); } txt_Status.Text = string.Format("Saved {0}", dlg.SafeFileName); ; } catch (Exception x) { MessageBox.Show(x.Message); } } } |