开发者

Get Worksheets in Excel Workbook without opening file

开发者 https://www.devze.com 2023-01-16 13:22 出处:网络
I\'m building an ASP.NET MVC 2 intranet application 开发者_如何学Cin which users will upload data files. If a file is an excel spreadsheet, the user should be given the option to select which workshee

I'm building an ASP.NET MVC 2 intranet application 开发者_如何学Cin 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)?


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.


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.


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消