Display an Excel Range in GridView

4 posts, 1 answers
  1. Raymond
    Raymond avatar
    65 posts
    Member since:
    Oct 2013

    Posted 28 Aug 2014 Link to this post

    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?
  2. Answer
    Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1218 posts

    Posted 01 Sep 2014 Link to this post

    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.
     
  3. Raymond
    Raymond avatar
    65 posts
    Member since:
    Oct 2013

    Posted 01 Sep 2014 in reply to Ivan Ivanov Link to this post

    Thanks Ivan,

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

    Regards,

    Ray
  4. Raymond
    Raymond avatar
    65 posts
    Member since:
    Oct 2013

    Posted 07 Sep 2014 in reply to Raymond Link to this post

    Hi Ivan,

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

    Regards,

    Ray
Back to Top