How to insert a collection directly into cells of xlsx file in WPF?

4 posts, 0 answers
  1. Srinivas
    Srinivas avatar
    9 posts
    Member since:
    Sep 2014

    Posted 03 Sep 2014 Link to this post

    Is direct insertion possible??
  2. Petya
    Admin
    Petya avatar
    975 posts

    Posted 04 Sep 2014 Link to this post

    Hello Srinivas,

    While there is no out of the box method that would do this for you, inserting the entries of a collection should be pretty straightforward if you enumerate over the collections. For example, the next snippet inserts the entries from the myData collection in the first column (A) of the active worksheet.
    List<string> myData = new List<string>() { "test", "TEST", "123" };
     
    for (int i = 0; i < myData.Count; i++)
    {
        this.radSpreadsheet.ActiveWorksheet.Cells[i, 0].SetValue(myData[i]);
    }

    I hope this is useful.

    Regards,
    Petya
    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. UI for WPF is Visual Studio 2017 Ready
  4. Srinivas
    Srinivas avatar
    9 posts
    Member since:
    Sep 2014

    Posted 05 Sep 2014 in reply to Petya Link to this post

    What you said is valid.. but...
    When I write this code​
    Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application();
    Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing);
    Microsoft.Office.Interop.Excel._Worksheet worksheet = null;

    and append yours.I am getting output as xls file but I want xlsx file.

  5. Petya
    Admin
    Petya avatar
    975 posts

    Posted 05 Sep 2014 Link to this post

    Hello Srinivas,

    I'm not sure what you mean. The code you sent seems to use the Microsoft Office Interop assemblies, while my suggestion and the section where this forum thread is are related to the RadSpreadsheet control which is part of the Telerik UI for WPF suite. Are you using the component in your application? If you are, please provide more details on the issue which you are experiencing.

    Regards,
    Petya
    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.
     
Back to Top