使用C#.NET查询Excel电子表格,而不使用Jet OLE DB [英] Query Excel spreadsheet with C# .NET without using Jet OLE DB

查看:158
本文介绍了使用C#.NET查询Excel电子表格,而不使用Jet OLE DB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法查询Excel 2010电子表格,而不使用Jet或导出为CSV,并查询csv文件。

Is there any way to query an excel 2010 spreadsheet, without using Jet or exporting as a CSV and querying the csv file.

我不能使用Jet的原因是因为应用程序需要作为Web服务运行,在Windows Server 2008 R2上,没有32位支持,因此Jet将无法运行。这是一个给定的,因为WOW 64没有安装在目标服务器上。

The reason why I cannot use Jet is because the application needs to run as a web service, on Windows Server 2008 R2, with no 32 bit support - hence Jet will not work. This is a given, as WOW 64 is not installed on the target server.

这个线程建议使用32位代理机,但这也不是一个选项。

This thread suggests using a 32 bit proxy machine, but this is also not an option.

更多信息:服务器正在运行Sharepoint 2010。

Further info: The server is running Sharepoint 2010.

谢谢,

JD

推荐答案

是 - 您可以使用Excel.Interop - 通过添加对Microsoft.Office.Interop的引用从C#程序引用它.excel(版本13,我认为Excel 2010)在VS添加参考对话框的.Net选项卡。

Yes - you can use Excel.Interop - reference it from your C# program by adding a reference to the Microsoft.Office.Interop.Excel (version 13 I think for Excel 2010) in the .Net tab of VS add reference dialog.

FYI:它不是一个好使用Interop在服务器上运行守护程序的想法: http:/ /support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2 ,但是如果它是一个短的运行程序,由用户运行并监视它,它应该是可以的..

FYI: Its not a good idea to run daemons on a server using Interop: http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2, however if it is a short running program, run by a user and you monitor it, it should be ok..

如果您希望客户端运行程序,他们将需要安装主互操作程序集(PIA),如果他们没有安装办公室,他们可以在这里:

If you want your clients to run the program they will need to install the Primary Interop Assemblies (PIA's) if they didnt already when installing office, they can be got here:

XP: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=C41BD61E-3060-4F71-A6B4-01FEBA508E52

2003: http:/ /www.microsoft.com/downloads/en/details.aspx?FamilyID=3C9A983A-AC14-4125-8BA0-D36D67E0F4AD

2007: http://www.microsoft.com/downloads/en/details.aspx?FamilyID= 59DAEBAA-BED4-4282-A28C-B864D8BFA513

2010: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=938fe8ad-583b-4bd7-a345- 23250dc15855

我一直在我的x64 Vista机器上使用Office11,所以我不认为x64会造成任何问题。

I have been using Office11 on my x64 Vista machine so i dont think x64 will pose any problems.

警告文档是可怕的!有大约10个不同版本的帮助,文档在那里。我推荐:

Be warned the documentation is terrible! there are about 10 different versions of the help, documentation out there. I reccomend:

熟悉以下内容:


  • 应用程序

  • 工作簿

  • 工作表

  • 范围

  • Application
  • Workbook
  • Worksheet
  • Range

对象。您可以将数据读入List< List< string>> (在这种情况下,您的所有单元格都必须格式化为文本)或内存中的某些内容,那么您不必再处理Interop及其v。fast。从C#总是使用一个方法(一些文档错误地告诉你不能使用它们用于内部使用的方法),例如:
Range.get_Values(A1)
而不是:
Range.Cells;

objects. You can read data into a List<List<string>> (in which case all your cells would have to formatted as text) or something in memory then you dont have to deal with Interop anymore and its v. fast thereon. From C# always use a method (some documentation erroneously tells you you cannot use there methods they are for internal use) such as: Range.get_Values("A1") as opposed to: Range.Cells;

开始的好地方在这里: http://dotnetperls.com/excel-interop

A good place to start is here: http://dotnetperls.com/excel-interop

官方文档在这里: http://msdn.microsoft.com/en-us/library/bb726434(v = office.12).aspx ,但是它包含一个营销华夫饼的负载,直到你到达Interop图书馆的十年前的部分。

Official documentation is here: http://msdn.microsoft.com/en-us/library/bb726434(v=office.12).aspx, but it contains a load of marketing waffle until you get to the Interop library parts of which are a decade old.

请注意:Excel索引是基于1 ,即返回的2D数组中的第一个元素从my2DArray [1,1]!

And beware: Excel index's are 1 based, i.e. the first element in the returned 2D array starts at my2DArray[1,1]!

这篇关于使用C#.NET查询Excel电子表格,而不使用Jet OLE DB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆