This is a migrated thread and some comments may be shown as answers.

Display an Excel Range in GridView

3 Answers 53 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Raymond
Top achievements
Rank 1
Raymond asked on 28 Aug 2014, 05:20 AM
I am using the following code to get an array of values from Excel;
rng = ws.Range[sCell1, sCell2];
object dataRows = rng.Value;

I then try to bind the array to a GridView using;
gvText.ItemsSource = dataRows;

However I get the error; "Array was not a one-dimensional array".

I have tried converting the array to an observable collection;
ObservableCollection<object> colRows = new ObservableCollection<object>(dataRows);

but this displays the error; ​"The best overloaded method match for 'System.Collections.ObjectModel.ObservableCollection<object>.ObservableCollection(System.Collections.Generic.IEnumerable<object>)' has some invalid arguments".

How can I bind the Excel data returned to the grid?

3 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Ivanov
Telerik team
answered on 01 Sep 2014, 04:07 PM
Hi,

Range.Value is actually a two dimensional object-type array. You can iterate over it and write it in some more appropriate format. I have prepared a sample project that uses DynamicObject. You only have to change the file path to run it on your side.

Regards,
Ivan Ivanov
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Raymond
Top achievements
Rank 1
answered on 02 Sep 2014, 04:14 AM
Thanks Ivan,

Won't have time to try this until tomorrow but will let you know how I go.

Regards,

Ray
0
Raymond
Top achievements
Rank 1
answered on 08 Sep 2014, 12:50 AM
Hi Ivan,

Tried your solution and it worked a treat.  Thanks for your help.

Regards,

Ray
Tags
GridView
Asked by
Raymond
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Raymond
Top achievements
Rank 1
Share this question
or