使用 OLEDB 访问 Excel 2007 文件格式

发布于 2024-08-10 20:04:47 字数 573 浏览 2 评论 0原文

我当前正在尝试访问不包含 Microsoft Office 的服务器上的 Excel 2007 文件。我的连接字符串是这样的。

  String connString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
  "Data Source=" + file_path + ";Extended Properties=Excel 8.0;";

但这是 2003 格式的,效果很好。我想利用 2007 xml 格式。但我无法通过以下连接访问该文件。(目标服务器上没有安装 Office,不确定是否是这个原因。

  String connString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
 "DataSource=" + file_path + ";HDR=Yes;IMEX=1;Extended Properties=Excel 12.0;";

我不断收到“无法找到可安装的 isam。”错误。

编辑 我正在使用 Visual Studio 2005 并使用 C# 进行开发,如果这有助于清除任何内容。

I'm currently trying to access an excel 2007 file on a server that doesn't contain Microsoft Office on it. My connectionstring is something like this.

  String connString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
  "Data Source=" + file_path + ";Extended Properties=Excel 8.0;";

But this is for 2003 format, which works fine. I would like to take advantage of the 2007 xml format. But I'm unable to access the file through the following connection.(The target server doesn't have Office installed on it, not sure if thats the reason.

  String connString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
 "DataSource=" + file_path + ";HDR=Yes;IMEX=1;Extended Properties=Excel 12.0;";

I'm keep getting the "could not find installable isam." Error.

EDIT
I'm using visual studio 2005 and developing in C# if this helps clear anything up.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

落叶缤纷 2024-08-17 20:04:47

您可以尝试使用此连接字符串:

string connectionString = 
    "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + 
    file_name + 
    ";Extended Properties=\"Excel 12.0 Xml;HDR=YES\"";

但请注意,x64 系统不支持此驱动程序,因此它无法工作。

You may try with this connection string:

string connectionString = 
    "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + 
    file_name + 
    ";Extended Properties=\"Excel 12.0 Xml;HDR=YES\"";

Please note though that this driver is not supported on x64 systems and it won't work.

开始看清了 2024-08-17 20:04:47

您应该尝试使用 Linq to Excel 开源项目来查询 Excel 电子表格中的数据。您可以使用 LINQ 语句来查询数据,Linq to Excel 负责建立 OLEDB 连接并创建 SQL 语句。

以下示例展示了如何轻松地从 Excel 电子表格查询数据

var book = new ExcelQueryFactory("pathToExcelFile");
var rows = from x in book.Worksheet() 
           select new                
           {
             Name = x["Name"],
             BirthDate = x["BirthDate"].Cast<DateTime>()
           };

查看Linq to Excel 介绍视频有关开源项目的更多信息。

You should try using the Linq to Excel open source project to query data from Excel spreadsheets. You can use LINQ statements to query the data, and Linq to Excel takes care of making the OLEDB connection and creating the SQL statement.

Here's an example of how easy it is to query data from an Excel spreadsheet

var book = new ExcelQueryFactory("pathToExcelFile");
var rows = from x in book.Worksheet() 
           select new                
           {
             Name = x["Name"],
             BirthDate = x["BirthDate"].Cast<DateTime>()
           };

Checkout the Linq to Excel intro video for more information about the open source project.

旧情别恋 2024-08-17 20:04:47

SpreadsheetGear for .NET 将允许您打开工作簿,而不依赖于 OleDB、COM Interop 或任何其他 API可能会在服务器上造成问题。

您可以此处查看实时 ASP.NET 示例并下载免费试用版此处

免责声明:我拥有 SpreadsheetGear LLC

SpreadsheetGear for .NET will let you open the workbook with no reliance on OleDB, COM Interop or any other API which can create problems on a server.

You can see live ASP.NET samples here and download the free trial here.

Disclaimer: I own SpreadsheetGear LLC

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文