We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Databiding to SfDataGrid of a CSV file with XlsIO

Thread ID:

Created:

Updated:

Platform:

Replies:

123602 Apr 2,2016 06:21 PM UTC Apr 7,2016 05:48 AM UTC UWP 3
loading
Tags: SfDataGrid
Alessandro Del Sole
Asked On April 2, 2016 06:21 PM UTC

Hi,
I'm trying to open a CSV file with XlsIO in a Universal Windows app and I want to databind the result to a SfDataGrid column with auto-generate columns as true. I'm struggling as I can't find any help. I'm writing this:

var picker = new FileOpenPicker();

picker.ViewMode = PickerViewMode.List;

picker.SuggestedStartLocation =

PickerLocationId.DocumentsLibrary;

picker.FileTypeFilter.Add(".csv");

var tempFile = await picker.PickSingleFileAsync();

if (tempFile != null)

{

var exStream = await tempFile.OpenStreamForReadAsync();

ExcelEngine excelEngine = new ExcelEngine();

IApplication application = excelEngine.Excel;

IWorkbook workbook = await application.Workbooks.OpenAsync(exStream, ",");

var data = workbook.Worksheets[0].Rows;

this.CsvGrid.ItemsSource = data;

exStream.Dispose();

}

Of course this databinding does not work and throws an exception. And because this should not be read-only, I would need to generate an ObservableCollection from the CSV's rows but I can't figure out how to extract a collection of rows from the worksheet. Any help please?


Jai Ganesh S [Syncfusion]
Replied On April 4, 2016 03:49 PM UTC

Hi Alessandro,


We have analyzed your query and we regret to inform you that, you cannot directly get the items from WorkBook and assign it to Grid’s ItemSource. We need to manually get the items from Worksheet and assign it to a collection then assign the Grid’s ItemSource.


UG Links:

http://help.syncfusion.com/wpf/sfdatagrid/export-to-excel


http://help.syncfusion.com/file-formats/xlsio/working-with-excel-worksheet#save-worksheet-as-csv


Regards,

Jai Ganesh S


Alessandro Del Sole
Replied On April 6, 2016 07:35 AM UTC

Thanks for your kind reply, I'll be looking through the links you provided.

Jai Ganesh S [Syncfusion]
Replied On April 7, 2016 05:48 AM UTC

Hi Alessandro,

Thank you for the update.

Please let us know if you need further assistance on this.

Regards,
Jai Ganesh S

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;