视图

publicPartialViewResult UploadIndex()
{returnPartialView();
}

<div><fieldsetstyle="height:100px;"><legend>说明</legend><h6style="color: red; font-size: 15px;">请从IV查询中进行下载数据,按其中的表格格式进行数据上传,否则会导致上传失败或数据出错!</h6></fieldset><fieldsetstyle="height: 50px;"><legend>工单号</legend><divstyle="margin-top: 10px;"><formid="formAkIvUpload"name="formToUpload"method="post"action="AkIv/UploadProcess"enctype="multipart/form-data"target="msgAkIvUpload"><inputid="fileAkIvUpload"type="file"size="45"name="fileAkIvUpload" /><inputtype="submit"style="cursor: pointer;"value="上传" /></form><iframeid="msgAkIvUpload"name="msgAkIvUpload"style="display: none;"></iframe></div></fieldset>
</div>

处理

public voidUploadProcess()
{//用于反馈执行信息string strReturn =
@"<!DOCTYPE html>
<html>
<head><title></title><script type='text/javascript'>alert('@msg');</script>
</head>
<body>
</body>
</html>";//获取文件var file = Request.Files["fileAkIvUpload"];string msg = "";//保存if (file != null && file.ContentLength > 0){//文件目录string path = Server.MapPath("~") + "Content\\File\\";if (!Directory.Exists(path)){Directory.CreateDirectory(path);}//文件类型验证string[] allowExtension = { "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"};if (!allowExtension.Contains(file.ContentType)){msg= "上传xlsx类型文件";}else{string filePath = path + "\\" +file.FileName;if(System.IO.File.Exists(filePath))System.IO.File.Delete(filePath);file.SaveAs(filePath);//文件try{NPOI.XSSF.UserModel.XSSFWorkbook hssfworkbook;using (FileStream fs = newFileStream(filePath, FileMode.Open, FileAccess.Read)){hssfworkbook= newNPOI.XSSF.UserModel.XSSFWorkbook(fs);}NPOI.SS.UserModel.ISheet sheet= hssfworkbook.GetSheetAt(0);System.Collections.IEnumerator rows=sheet.GetRowEnumerator();while(rows.MoveNext()){NPOI.SS.UserModel.IRow row=(NPOI.SS.UserModel.IRow)rows.Current;if (row.GetCell(0).ToString() == "条码" || row.GetCell(0) == null || string.IsNullOrEmpty(row.GetCell(0).ToString()))continue;try{float power = 0;try{power= row.GetCell(19) == null ? 0 : float.Parse(row.GetCell(19).ToString());}catch{ }AkIv akIv= newAkIv(){BarCode= row.GetCell(0) == null ? "" : row.GetCell(0).ToString(),DateTime= row.GetCell(1) == null ? DateTime.Now : Convert.ToDateTime(row.GetCell(1).ToString()),Eff= row.GetCell(2) == null ? 0 : float.Parse(row.GetCell(2).ToString()),Isc= row.GetCell(3) == null ? 0 : float.Parse(row.GetCell(3).ToString()),Voc= row.GetCell(4) == null ? 0 : float.Parse(row.GetCell(4).ToString()),Rs= row.GetCell(5) == null ? 0 : float.Parse(row.GetCell(5).ToString()),Rsh= row.GetCell(6) == null ? 0 : float.Parse(row.GetCell(6).ToString()),Pmax= row.GetCell(7) == null ? 0 : float.Parse(row.GetCell(7).ToString()),Vpm= row.GetCell(8) == null ? 0 : float.Parse(row.GetCell(8).ToString()),Ipm= row.GetCell(9) == null ? 0 : float.Parse(row.GetCell(9).ToString()),FF= row.GetCell(10) == null ? 0 : float.Parse(row.GetCell(10).ToString()),Sun= row.GetCell(11) == null ? 0 : float.Parse(row.GetCell(11).ToString()),Temp= row.GetCell(12) == null ? 0 : float.Parse(row.GetCell(12).ToString()),Class= row.GetCell(13) == null ? "" : row.GetCell(13).ToString(),Employee= row.GetCell(14) == null ? "" : row.GetCell(14).ToString(),LineTitle= row.GetCell(15) == null ? "" : row.GetCell(15).ToString(),StationTitle= row.GetCell(16) == null ? "" : row.GetCell(16).ToString(),OrderNumber= row.GetCell(17) == null ? "" : row.GetCell(17).ToString(),BatterySupplier= row.GetCell(18) == null ? "" : row.GetCell(18).ToString(),Power=power,InterconnectId= row.GetCell(20) == null ? "" : row.GetCell(20).ToString(),InterconnectSpec= row.GetCell(21) == null ? "" : row.GetCell(21).ToString()};_akIvRepository.Insert(akIv);}catch(Exception e){}}SaveUserLog("AkIv上传", filePath, true);msg= "上传功成成功!";}catch(Exception e){msg=e.ToString();}}}else{msg= "请选择文件!";}System.Web.HttpContext.Current.Response.ContentType= "text/html";System.Web.HttpContext.Current.Response.Write(strReturn.Replace("@msg", msg));
}

npoi上传xlsx文件,并读取数据相关推荐

  1. 服务器上传excel文件并读取数据,asp.net上传Excel文件并读取数据的实现方法

    前言 本文主要给大家介绍了关于asp.net上传Excel文件并读取数据的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧 实现如下: 前台代码:使用服务端控件实现上传 服务端 ...

  2. 使用curl上传带有文件的POST数据

    本文翻译自:Using curl to upload POST data with files I would like to use cURL to not only send data param ...

  3. xlswriter-用于Excel 2007+XLSX文件中读取数据

    介绍: xlswriter是一个 ,可用于在 Excel 2007+ XLSX 文件中读取数据,插入多个工作表,写入文本.数字.公式.日期.图表.图片和超链接. 特点: 一.写入 100%兼容的Exc ...

  4. Django框架(上传Excel文件并读取)

    博主今天整理下Django框架中上传Excel文件并读取 博主是要在管理平台中新增用例的维护功能,想着通过上传Excel文件来展示用例,下面是项目的路径图: 首先先建数据库模型 model.py 可以 ...

  5. java excel导入前台_java上传excel表格并读取数据返回到前台

    如果你对里面的代码不熟悉不知道的话,建议先浏览一遍代码再拿去用, 这里我介绍一下这个过程的思路: 1.定义变量那些就不说了 , 2.首先是上传文件并保存的代码 3.根据excel表的路径来读取文件,之 ...

  6. java 导出文件上传模板,上传Excel文件批量导入数据

    后端代码 controller层 @RequestMapping(value = "/importExcel", method = {RequestMethod.POST, Req ...

  7. C++ vs2017 - libcurl - http请求 代码大全(请求数据,上传下载文件,多线程上传下载文件)

    在网上搜寻各种libcurl的用法,将代码集合于此! 目录 一.配置curl项目 二.Curl 请求参数 1. CURLOPT_POST 2. CURLOPT_URL 3. CURLOPT_HTTPH ...

  8. springboot实现上传Excel文件与数据库中的数据进行比对

    springboot实现上传Excel文件与数据库中的数据进行比对 首先先写好文件上传的接口,然后上传需要比对数据的文件,在点击数据比对 下面是一部分数据比对的代码: 后端controller部分: ...

  9. springMVC从上传的Excel文件中读取数据

    示例:导入客户文件(Excle文件) 一.编辑customer.xlsx 二.在spring的xml文件设置上传文件大小 <!-- 上传文件拦截,设置最大上传文件大小 10M=10*1024*1 ...

最新文章

  1. 二进制补码求值用c语言,C语言程序设计第2章数据类型.运算符与表达式.ppt
  2. android 生成推广图片保存_flutter 如何生成图片并保存到手机相册?
  3. 前端学习(3251):dom的diff算法2
  4. 《C Traps and Pitfalls》 笔记
  5. 【C语言进阶深度学习记录】二十四 指针与数组的本质分析一
  6. 衰减学习率真的有用吗?
  7. SAP PS:项目进度计划管理
  8. 基于暗通道先验的单幅图像去雾
  9. ubuntu-键盘映射
  10. 我酸了,曝光几个腾讯 阿里P8前同事的副业收入
  11. Layui页面元素之导航
  12. 迅雷 极速版 1.0.35.366
  13. H.264/H.265/H.266三代视频编码的图像划分
  14. 利用Instrumentation单元测试模块控制安卓手机进行各项操作(微信)
  15. 小白如何购买阿里云服务器(图文教程)
  16. 一些恶搞人的C++程序(千万别试,会哭的)
  17. python基础包的functools的reduce方法-亢保星
  18. 支持jesd204b协议高速DAC芯片AD9144-FMC-EBZ配置笔记
  19. 【Metal2剖析(四):基于MPS的GPU加速光线追踪(Accelerating Ray Tracing)】
  20. node.js+uniapp计算机毕业设计安卓英语答题APP(程序+APP+LW)

热门文章

  1. 深度学习原理—代码分析线性分类与神经网络分类的区别
  2. 2019年值得关注的九个AI创业风口
  3. SAP MM ME1M报表结果不科学?
  4. 透彻理解高斯核函数背后的哲学思想与数学思想
  5. Python中的张量分解
  6. 掌握可视化卷积神经网络模型,带你畅游图像识别技术领域
  7. 观点丨机器学习未必是人工智能 未必依赖于大数据
  8. 干货丨从概念到案例:初学者须知的十大机器学习算法
  9. 利用numpy对已知样本点进行多项式拟合
  10. 理解人类世界的常识对于人工智能是一项挑战