views:

77

answers:

3

I'm building an ASP.NET MVC 2 intranet application in which users will upload data files. If a file is an excel spreadsheet, the user should be given the option to select which worksheet they would like to import. Some of these files can be very large, so will be imported asynchronously. But it would be great to grab a list of the worksheets without saving / opening the file.

Is this possible? Or can anyone suggest a decent workaround (without resorting to accepting worksheet names in a text box)?

+1  A: 

The only workaround I can think of, although I hesitate to call it decent, involves using Silverlight and relies on the Excel files being in the 2007 format (Open XML or whatever it's called). Then you can open the file locally with Silverlight and (hackishly) get a list of the worksheets. You can also use Silverlight to do the actual upload. Or you could extract the relevant worksheets and only upload those.

Alex Paven
Thanks Alex, didn't want to go the silverlight route, but may have to!
pjacko
+1  A: 

You can access that information by either using the System.IO.Packaging library, which would allow you to access the XML that makes up the Excel document and thus allow you to see what worksheets make up the Excel document.

The other option is to use the Open XML SDK 2.0 and access the Worksheets via strongly typed objects, ie a WorkSheetPart. Neither will be fast or clean as it will be a good amount of work, but are two other options in addition to Alex's suggestion.

amurra
This sounds promising, I'll look into and update the thread if i get it working. Thanks
pjacko
A: 

If you are simply importing the data to a Database you can use the OLE JET 4.0 Driver and access the schema using System.Data.SqlConnection.GetSchema (i think that is the function name).

Brad