You can open or save CSV files.
GcSpreadSheet has additional settings that are available when saving or loading CSV files. You can only save or load text, include row or column headers, save or load unformatted values, export or import formulas, and set the encoding.
You can use the OpenCsvAsync or SaveCsvAsync method in code.
This example opens a CSV file.
CS |
Copy Code |
---|---|
private async void Button_Click_1(object sender, RoutedEventArgs e) { try { var filePicker = new Windows.Storage.Pickers.FileOpenPicker(); filePicker.FileTypeFilter.Add(".csv"); Windows.Storage.StorageFile storageFile = await filePicker.PickSingleFileAsync(); if (storageFile != null) { using (var stream = await storageFile.OpenStreamForReadAsync()) { gcSpreadSheet1.Sheets[0].OpenCsvAsync(stream, GrapeCity.Xaml.SpreadSheet.Data.TextFileOpenFlags.IncludeColumnHeader); //gcSpreadSheet1.Sheets[0].OpenCsvAsync(stream, GrapeCity.Xaml.SpreadSheet.Data.TextFileOpenFlags.IncludeColumnHeader, System.Text.Encoding.UTF8); } } } catch (Exception ex) { Windows.UI.Popups.MessageDialog dialog = new Windows.UI.Popups.MessageDialog(ex.Message, "Error"); dialog.ShowAsync(); } } |
VB |
Copy Code |
---|---|
Private Async Sub Button_Click_1(sender As Object, e As RoutedEventArgs) Try Dim filePicker As New Windows.Storage.Pickers.FileOpenPicker() filePicker.FileTypeFilter.Add(".csv") Dim storageFile As Windows.Storage.StorageFile = Await filePicker.PickSingleFileAsync() If storageFile IsNot Nothing Then Using stream = Await storageFile.OpenStreamForReadAsync() GcSpreadSheet1.Sheets(0).OpenCsvAsync(stream, GrapeCity.Xaml.SpreadSheet.Data.TextFileOpenFlags.IncludeColumnHeader) 'GcSpreadSheet1.Sheets(0).OpenCsvAsync(stream, GrapeCity.Xaml.SpreadSheet.Data.TextFileOpenFlags.IncludeColumnHeader, System.Text.Encoding.UTF8) End Using End If Catch ex As Exception Dim dialog As Windows.UI.Popups.MessageDialog = New Windows.UI.Popups.MessageDialog(ex.Message, "Error") dialog.ShowAsync() End Try End Sub |