zoukankan      html  css  js  c++  java
  • C#将数据导入到Excel表格中

    public static DataTable GetExcelToDataTableBySheet(string FileFullPath, string SheetName)
    {
                //string strConn = "Provider=Microsoft.Jet.OleDb.4.0;" + "data source=" + FileFullPath(fup.postedfile.filename) + ";Extended Properties='Excel 8.0; HDR=NO; IMEX=1'"; //此连接只能操作Excel2007之前(.xls)文件
                string strConn = "Provider=Microsoft.Ace.OleDb.12.0;" + "data source=" + fup.postedfile.filename+ ";Extended Properties='Excel 12.0; HDR=NO; IMEX=1'"; //此连接可以操作.xls与.xlsx文件
                OleDbConnection conn = new OleDbConnection(strConn);
                conn.Open();
                DataSet ds = new DataSet();
                OleDbDataAdapter odda = new OleDbDataAdapter(string.Format("SELECT * FROM [{0}]", SheetName), conn);                    //("select * from [Sheet1$]", conn);
                odda.Fill(ds, SheetName);
                conn.Close();
                return ds.Tables[0];
    }


    fup.postedfile.filename如果获取的是文件名,则
    把工具~Internet选项~安全~Internet~自定义级别~其它~将文件上载到服务器时包含本地目录路径:设为启用

    每天积累一点,离成功就近一点
  • 相关阅读:
    Android设备驱动安装
    昨晚摆乌龙了
    生活
    SQLSTATE=57019
    IBM项目六
    不吸烟了
    清明短假
    『ExtJS』使用中需要注意的一些事(持续更新)
    『Spring.Net』IoC 容器
    『Spring.Net』为什么使用?
  • 原文地址:https://www.cnblogs.com/apes-monkeys/p/4031209.html
Copyright © 2011-2022 走看看