博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Read Excel file from C#
阅读量:7201 次
发布时间:2019-06-29

本文共 1665 字,大约阅读时间需要 5 分钟。

Common way is:

var fileName = string.Format("{0}\\fileNameHere", Directory.GetCurrentDirectory());var connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; data source={0}; Extended Properties=Excel 8.0;", fileName);var adapter = new OleDbDataAdapter("SELECT * FROM [workSheetNameHere$]", connectionString);var ds = new DataSet();adapter.Fill(ds, "anyNameHere");DataTable data = ds.Tables["anyNameHere"];

see details at: http://stackoverflow.com/questions/15828/reading-excel-files-from-c-sharp

 

the connect string is: 

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\myFolder\myExcel2007file.xlsx;

Extended Properties="Excel 12.0 Xml;HDR=YES";

(HDR=YES: read the header)

see the connect strings of Excel: http://www.connectionstrings.com/excel-2007/

 

There is an error if your system is your system is 64bit: 

Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.

Change the application to 32bit to avoid this problem, see: http://stackoverflow.com/questions/238625/microsoft-ace-oledb-12-0-provider-is-not-registered

 

If using this code to read Excel file on Windows Azure, we can't change it to 32bit, so we need find another way: 

http://stackoverflow.com/questions/3663245/read-excel-file-and-insert-records-in-database-in-c-windows-azure

that is: 

For the time being you are basically restricted to .NET-only options:

  •  for XLSX
  •  for XLS

 

EPPlus examples: 

http://www.codeproject.com/Articles/680421/Create-Read-Edit-Advance-Excel-2007-2010-Report-in#1

http://blog.fryhard.com/archive/2010/10/28/reading-xlsx-files-using-c-and-epplus.aspx

 

NPOI source: 

https://github.com/tonyqus/npoi

 

 

 

转载于:https://www.cnblogs.com/JasonBie/p/3612057.html

你可能感兴趣的文章
自定义控件实现(转)
查看>>
如何确认访客所在的国家
查看>>
跟着8张思维导图学习javascript
查看>>
InnoSQL/MySQL并行复制的实现与配置
查看>>
JDBC连接MySQL数据库及演示样例
查看>>
第38周五
查看>>
windows下Emacs的安装与配置
查看>>
WF4 常用类<第二篇>
查看>>
mongo文件空间
查看>>
NSArray中存的是实体时的排序
查看>>
搜索框中“请输入搜索keyword”
查看>>
CentOS6.5与XP双系统安装
查看>>
Python 更新set
查看>>
shell语法简单介绍
查看>>
Web服务器的工作原理
查看>>
使用WinSetupFromUSB来U盘安装windowsXP(不使用win PE系统)
查看>>
JAVA Calendar具体解释
查看>>
MongoDB入门简单介绍
查看>>
Git show-branch显示提交信息
查看>>
秒杀 ILSpy 等反编译利器 DotNet Resolver
查看>>