locked
how can i open an excelfile in client side and get the data in it. RRS feed

  • Question

  • hi all i have a requirement where the user can open an excel file on client side and display the contents ( say datagrid). how can i get the contents of the excel ? i did this for csv files. but how can i do it for excel. regards Balu.
    Tuesday, January 13, 2009 1:20 AM

Answers

  • Hey balukr~

    First, in Winapp, you can use Excel(Interop dll) Object to shell local "Excel process", and use C#- Platform Invoker or something to Retrive data from the Object.

    But in Silverlight, there's no Platform Invoker, no Interop-Local dll, no excel object, and Even no Writable Stream!! --the Last one is just my Complain.. but I know it is good for Fs Securty.

    If your Excelfile is an open-xml File ("xlsx"), then you can use OpenfileDialog to show a Dialog, and let user select file-> You would get a Read-only File stream, which is actually a ZIP-FILE's Stream. And you could transfer it on to your server's WCF service to request Server to deal with it.

    Of course, your WCF service should has a function of operating ZIPFILE, and another function of OPEN-XML- Operating.

    And then, push data to Silverlight-Client. As a List or something more suitable.

     

    If your Excel file is an "xls" file... The same, transfer it to Server and let server to deal with it.

    But to read XLS file is seems to be more difficult.. Can't imagine...

     

    Have a try.......      Better begin with WCF service! it will be the Core...

     

    TIP: Maybe your server can use Database Connection to connect XLS file Directly, in that case, you should take a look at OleDb Connection String.

     

     

    Hope those helps~

    Tuesday, January 13, 2009 2:17 AM
  •  thankk you mark for your responce.

    i have another doubt..i have a workaround.

    when the user selects the excel he needs first we need to save the excel in server. in server we can open the excel and return the file contents(webservice  .asmx).

    my doubt is how can we save the excel file on server?

    thanks

    balu

     

    That's probably an easier strategy, although now you have to track the uploads (client may go away and leave the files on the server), and handle more failure states. Here is a link to a file upload library that might get you started.

    Tuesday, January 13, 2009 2:46 AM

All replies

  • I can't see a direct method for querying Excel from Silverlight on the client side. You'd need either OLEDB/ADO.NET or access to automation interfaces. Of course if your users can save as XML then you can use Linq-to-XML. If not, then I think you will have to put something together yourself. There is a library w/source on Codeproject for reading Excel files. From a quick glance at it I think it could be adapted to work with Silverlight if you first open the file and read it into isolated storage. But I'm sure the library won't be directly usable against the Silverlight runtime, so at the very least you'll have to rebuild it and deal with any reference issues. Maybe someone knows an easier way.
    Tuesday, January 13, 2009 1:39 AM
  •  thankk you mark for your responce.

    i have another doubt..i have a workaround.

    when the user selects the excel he needs first we need to save the excel in server. in server we can open the excel and return the file contents(webservice  .asmx).

    my doubt is how can we save the excel file on server?

    thanks

    balu

    Tuesday, January 13, 2009 1:54 AM
  • Hey balukr~

    First, in Winapp, you can use Excel(Interop dll) Object to shell local "Excel process", and use C#- Platform Invoker or something to Retrive data from the Object.

    But in Silverlight, there's no Platform Invoker, no Interop-Local dll, no excel object, and Even no Writable Stream!! --the Last one is just my Complain.. but I know it is good for Fs Securty.

    If your Excelfile is an open-xml File ("xlsx"), then you can use OpenfileDialog to show a Dialog, and let user select file-> You would get a Read-only File stream, which is actually a ZIP-FILE's Stream. And you could transfer it on to your server's WCF service to request Server to deal with it.

    Of course, your WCF service should has a function of operating ZIPFILE, and another function of OPEN-XML- Operating.

    And then, push data to Silverlight-Client. As a List or something more suitable.

     

    If your Excel file is an "xls" file... The same, transfer it to Server and let server to deal with it.

    But to read XLS file is seems to be more difficult.. Can't imagine...

     

    Have a try.......      Better begin with WCF service! it will be the Core...

     

    TIP: Maybe your server can use Database Connection to connect XLS file Directly, in that case, you should take a look at OleDb Connection String.

     

     

    Hope those helps~

    Tuesday, January 13, 2009 2:17 AM
  •  thankk you mark for your responce.

    i have another doubt..i have a workaround.

    when the user selects the excel he needs first we need to save the excel in server. in server we can open the excel and return the file contents(webservice  .asmx).

    my doubt is how can we save the excel file on server?

    thanks

    balu

     

    That's probably an easier strategy, although now you have to track the uploads (client may go away and leave the files on the server), and handle more failure states. Here is a link to a file upload library that might get you started.

    Tuesday, January 13, 2009 2:46 AM
  • Hi Balu,

                   I have done this..Silverlight doesnt support to read the excel files.So u have to store the execel file  in the app_data or wherever u wish in the server side by using  openFileDialog (ref http://silverlight.net/learn/learnvideo.aspx?video=69793) ... After saving navigate to the server side by

    Html.window.Navigate(.aspxpage) from here you can read the excel file... As mentioned in the previous post use interop.excel dll in your sever page..

    Tuesday, January 13, 2009 7:14 AM
  • this is the solution for out of browser concept.I want to read the file from clinet side, my file is in the hosted application.

    there is any way to do it from WCF service


    Give proper solution for the same.

    Tuesday, August 10, 2010 1:23 AM