把excel文档中的内容读取到dataset中
来源:互联网 发布:奥数中最优化方法 编辑:程序博客网 时间:2024/04/30 11:21
如何把excel文档中的内容读取到dataset中呢?我查询了一些资料,并亲自试用,以下代码均通过vs2010编译:
以下是实现该功能的一个函数,直接调用即可:
函数的参数说明:filepath是excel所在的全路径,tablename是EXCEL文档里的一个表名,一般为sheet1
private DataSet xsldata(string filepath, string tablename)
{
string strCon = "";
string filemode = filepath.Substring(filepath.Length - 4, 4);
if (filemode == ".xls")
{
strCon = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + filepath + ";" + "Extended Properties='Excel 8.0;IMEX=1'"; //excel2003
}
else if (filemode == "xlsx")
{
strCon = "Provider=Microsoft.Ace.OLEDB.12.0;" + "Data Source=" + filepath + ";" + "Extended Properties='Excel 12.0;IMEX=1'"; //excel2007
}
System.Data.OleDb.OleDbConnection Conn = new System.Data.OleDb.OleDbConnection(strCon);
string strCom = "SELECT * FROM [" + tablename + "$]";
Conn.Open();
System.Data.OleDb.OleDbDataAdapter myCommand = new System.Data.OleDb.OleDbDataAdapter(strCom, Conn);
DataSet ds = new DataSet();
DataGridView dataGridView = new DataGridView();
myCommand.Fill(ds, "[" + tablename + "$]");
dataGridView.DataSource = ds.Tables[0];
Conn.Close();
return ds;
}
- 把excel文档中的内容读取到dataset中
- 把指定的DataSet中的内容导出到Excel中
- 把指定的DataSet中的内容导出到Excel中
- 把指定的DataSet中的内容导出到Excel中
- dataset读取excel中的数据到打dataset中
- 读取Excel文件内容到DataSet
- 将DATASET中的内容导出到EXCEL
- 把数据库中的内容导出到txt文档中
- 读取Excel文件,将内容存储在DataSet中
- 读取Excel中的信息 至DataSet,将DataSet中的资料导出到Excel
- 将DataSet中的内容输出到Excel文件
- 将DataSet中的内容输出到Excel文件
- 将DataSet中的内容输出到Excel文件
- C# 读取Excel到DataSet
- 读取Excel文件到DataSet
- 把TABLE中内容导出到EXCEL
- 从Excel中读取内容到java
- 把Excel文件内容转换为dataset
- 程序员面试宝典三
- 九种改变未来世界的革命性技术
- ZOJ 1577 GCD & LCM
- css3选择类别
- PIN码查询网站
- 把excel文档中的内容读取到dataset中
- Spring+JMX(Java Management Extensions)
- 多线程的使用
- 顺时针打印矩阵
- oracle服务启动批处理 提高开机及运行效率
- Lua 与 C混合编程 .
- 【Linux Rsync3.0 实用版安装】
- OpenGL中所有的变换,都是在变换坐标系。
- Spring配置定时器的xml文件