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~自定义级别~其它~将文件上载到服务器时包含本地目录路径:设为启用

    每天积累一点,离成功就近一点
  • 相关阅读:
    494 Target Sum 目标和
    493 Reverse Pairs 翻转对
    492 Construct the Rectangle 构建矩形
    491 Increasing Subsequences 递增子序列
    488 Zuma Game 祖玛游戏
    486 Predict the Winner 预测赢家
    485 Max Consecutive Ones 最大连续1的个数
    483 Smallest Good Base
    Django Form组件
    Django Auth组件
  • 原文地址:https://www.cnblogs.com/apes-monkeys/p/4031209.html
Copyright © 2011-2022 走看看