zoukankan      html  css  js  c++  java
  • c# 导入excle数据

    //热力图
            [AcceptVerbs("Post")]
            [LogInfo("导入监测点位", true)]
            public HttpResponseMessage ImportPoint([FromUri] int structId)
            {
                try
                {
                    HttpPostedFile file = HttpContext.Current.Request.Files[0];
    
                    string timenow = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                    string path = HttpContext.Current.Server.MapPath("~/");
                    //检查和创建存储目录
                    if (Directory.Exists(path + "\rpt") == false)
                    {
                        Directory.CreateDirectory(path + "\rpt");
                    }
                    if (Directory.Exists(path + "\rpt\" + timenow) == false)
                    {
                        Directory.CreateDirectory(path + "\rpt\" + timenow);
                    }
                    string realPath = "rpt\" + timenow + "\" + file.FileName;
                    path += realPath;
                    file.SaveAs(path);
    
                    Aspose.Cells.Workbook wk = new Aspose.Cells.Workbook(path);
                    Aspose.Cells.Cells cells = wk.Worksheets[0].Cells;
                    System.Data.DataTable dt = cells.ExportDataTable(1, 0, cells.MaxDataRow, cells.MaxColumn);//noneTitle
    
                    string cmdText = "";
                    string points = "";
    
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        points += "'" + dt.Rows[i][0].ToString() + "',";
                    }
    
    
                    if (points != "")
                    {
                        points = points.Substring(0, points.Length - 1);
                        cmdText = string.Format("Select Count(*) From T_HOTSPOT_MAIN_INFO a Where a.structId = '{0}' and a.Point in ({1})", structId, points);
    
                        string count = SqlHelper.ExecuteScalarText(cmdText).ToString();
                        if (count != "0")
                        {
                            return Request.CreateResponse(HttpStatusCode.Accepted, "数据中包含已上传的监测点位,请检查后再提交!");
                        }
                    }
    
    
                    string time = DateTime.Now.ToString();
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        string point = dt.Rows[i][0].ToString();
                        string x = dt.Rows[i][1].ToString();
                        string y = dt.Rows[i][2].ToString();
                        cmdText = string.Format("Insert Into T_HOTSPOT_MAIN_INFO(point,x,y,structId,createtime) Values('{0}','{1}','{2}','{3}','{4}')", point, x, y, structId, time);
                        SqlHelper.ExecteNonQueryText(cmdText);
                    }
    
                    return Request.CreateResponse(HttpStatusCode.OK, "导入成功!");
                }
                catch (Exception ex)
                {
                    return Request.CreateResponse(HttpStatusCode.InternalServerError, "导入失败!" + ex.Message + ex.StackTrace);
                }
            }
  • 相关阅读:
    ModuleNotFoundError: No module named 'rest_framework_swagger'
    ModuleNotFoundError: No module named 'suit'
    HTTPS连接的前几毫秒发生了什么
    网络通信之 字节序转换原理与网络字节序、大端和小端模式
    聊聊HTTPS和SSL/TLS协议
    ECShop 调用自定义广告
    ECSHOP商城网站建设之自定义调用广告方法(二)
    https原理:证书传递、验证和数据加密、解密过程解析
    图解openssl实现私有CA
    SSL/TLS协议运行机制的概述
  • 原文地址:https://www.cnblogs.com/lvqianqian/p/15148403.html
Copyright © 2011-2022 走看看