locked
Import From Excel Extension C# Example

    Question

  • Hello,

    I am attempting to use the import from Excel Extension in Visual Studio Lightswitch and am unable to get the code to work.  I believe this to be a very very basic question so let me setup my scenerio.  I am fairly new to programming and have been working through some books and such to pick it up but it has been quite some time since I have been able to spend any time with it due to my current project workload.

    I have a need on our current project to create an issues tracking log and I thought it would be nice to give lightswitch a go.,  I am loving it so far but I have a need to import data from some Excel Spreadsheets.  So I have the extension loaded and the button created on my Editable Data Grid screen.  When I try to put in the code to execute when the button is pressed I am getting an intellisense error .  Is there a C# sample out there for the importer?  I do not get the "ImportFromExcel" option in my Intellisense.

    Again I am probably doing something wrong at the most basic level.  Thank you for any assistance.

    Marco

    Monday, June 20, 2011 3:00 PM

Answers

  • Hi Yann.  Yes I have it installed and selected in my project.  As I was replying to this I foudn out the issue.  It appears there is a typo in the document.  The actual code that I have working is:

     partial void ImportFromExcel_Execute()
        {
          // Write your code here.
          LightSwitchUtilities.Client.ExcelImporter.ImportFromExcel(this.Facilities);
        }

    It is all good now.  I guess had I spent a few more minutes of frustration I would have stumbled across it.  :)

     

    Thanks for the reply and help.

     

    Marco

    • Marked as answer by MCrank Monday, June 20, 2011 3:59 PM
    Monday, June 20, 2011 3:59 PM
  • That's interesting, I didn't need the "ExceImporter" part, just the code I gave you above. Intellisense after Client shows "ImportFromExcel", as indeed it shows "ExcelImporter" as well.

    Maybe it's a C# thing!

    Looking further, I noticed that ImportFromExcel is an extension method on IVisualCollection, so the code could also have been:

     

    VB:

    Imports LightSwitchUtilities.Client.ExcelImporter

    Me.YourCollectionName.ImportFromExcel()

    C#:

    using LightSwitchUtilities.Client.ExcelImporter;

      this.YourCollectionName.ImportFromExcel();

     


    Yann

    (plus ça change, plus c'est la même chose!)


    • Marked as answer by MCrank Monday, June 20, 2011 7:23 PM
    Monday, June 20, 2011 4:29 PM

All replies

  • Hi Marco,

    I assume you've "installed" the extension. Have you also activated it it in your LS project?

    If not, in your LS properties, there's an "Extensions" tab. You should see "LightSwitchUtilities" in the list, but it has to have its checkbox ticked. You should also tick "Use In New Projects" if you want to use the extension in any new projects.

    Once you've done that, the line to use the extension in code is:

    VB:

    LightSwitchUtilities.Client.ImportFromExcel(Me.YourCollectionName)
    

    C#:

    LightSwitchUtilities.Client.ImportFromExcel(this.YourCollectionName);
    

    I've used the extension successfully to import data from Excel, so let me know if it's still not working for you & we can figure out where else you may be going wrong.

     


    Yann

    (plus ça change, plus c'est la même chose!)



    Monday, June 20, 2011 3:37 PM
  • Hi Yann.  Yes I have it installed and selected in my project.  As I was replying to this I foudn out the issue.  It appears there is a typo in the document.  The actual code that I have working is:

     partial void ImportFromExcel_Execute()
        {
          // Write your code here.
          LightSwitchUtilities.Client.ExcelImporter.ImportFromExcel(this.Facilities);
        }

    It is all good now.  I guess had I spent a few more minutes of frustration I would have stumbled across it.  :)

     

    Thanks for the reply and help.

     

    Marco

    • Marked as answer by MCrank Monday, June 20, 2011 3:59 PM
    Monday, June 20, 2011 3:59 PM
  • That's interesting, I didn't need the "ExceImporter" part, just the code I gave you above. Intellisense after Client shows "ImportFromExcel", as indeed it shows "ExcelImporter" as well.

    Maybe it's a C# thing!

    Looking further, I noticed that ImportFromExcel is an extension method on IVisualCollection, so the code could also have been:

     

    VB:

    Imports LightSwitchUtilities.Client.ExcelImporter

    Me.YourCollectionName.ImportFromExcel()

    C#:

    using LightSwitchUtilities.Client.ExcelImporter;

      this.YourCollectionName.ImportFromExcel();

     


    Yann

    (plus ça change, plus c'est la même chose!)


    • Marked as answer by MCrank Monday, June 20, 2011 7:23 PM
    Monday, June 20, 2011 4:29 PM
  • Hi

     

    Today there is a good news for those who need to load data from Excel tables LightSwitch, came the extension update "Excel Importer Updated for Web Applications" so from any environment where you deploy the application can perform this task.

     

    http://blogs.msdn.com/b/lightswitch/archive/2011/06/27/excel-importer-updated-for-web-applications.aspx

     

    Jaime

    Tuesday, June 28, 2011 1:14 PM