• asp.net mvc Dateset读取Excel数据


    //处理Excel
    //读取Excel
    [NonAction]
            public static DataSet ExcelToDS(string Path)
            {
           //根据情况选择合适的连接字符,参考msdn
                string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;";
                //发布后开启此注释
                //string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;";
                OleDbConnection conn = new OleDbConnection(strConn);
                conn.Open();
                string strExcel = "";
                OleDbDataAdapter myCommand = null;
                DataSet ds = null;
                strExcel = "select * from [sheet1$]";
                myCommand = new OleDbDataAdapter(strExcel, strConn);
                ds = new DataSet();
                myCommand.Fill(ds, "table1");
                return ds;
            }
                 //业务处理
           var data = new DataSet(); //使用上述操作Excel的方法读取数据 var execl = ExcelToDS(Session["xlsPath"].ToString()); data= execl.Clone(); foreach (DataRow item in execl.Tables[0].Rows) { //检测是否末行 try { //表格中第一行存放编号,当无法转换为整型数时则表示数据异常并抛出 Convert.ToInt32(item[0]); data.Tables[0].Rows.Add(item.ItemArray); } catch (Exception) { break; } } //返回指定的view return View(finalInfo);
  • 相关阅读:
    vue视图更新---this.$set方法
    v-bind绑定属性样式——class的三种绑定方式
    摸鱼玩PS
    introduce to reinforcement learning ppt
    difference between sparse_softmax_cross_entropy_with_logits and softmax_cross_entropy_with_logits
    Tensorflow Keras tutotrials01
    一句话
    String字符串相关方法
    算是日记吧
    骑行入门
  • 原文地址:https://www.cnblogs.com/ives/p/6900842.html
Copyright © 2020-2023  润新知