zoukankan      html  css  js  c++  java
  • excel数据批量导入

    1.  html

              <form id="form_search" action="@Url.Action("UpLoadFile")" enctype="multipart/form-data" method="post">

                                     <td>
                                    上传文件:<input class="easyui-filebox" id="fileTxt" name="fileName" style=" 200px" data-options="prompt:'Choose a file...'" />
                                    <a id="UpLoadFile" class="easyui-linkbutton" style="" data-options="iconCls:'icon-fresh',70" onclick="upLoadFile()">
                                        上传
                                    </a>
                                </td>
                                <script>
                                    $('#fileTxt').filebox({
                                        buttonText: '选择文件',
                                        buttonAlign: 'right'
                                    })
                                </script>

    2.JavaScript

           //文件上传
           function upLoadFile() {
            $("#UpLoadFile").click(function () {
                debugger;
                var upfile = $("#fileTxt").filebox("getValue");
                if (upfile.length <= 0) {
                    $.mapuni.tips("请选择要上传的文件");
                    return;
                }
                var ext = upfile.split('.');
                //$("#searchForm_dg").submit()
                $("#form_search").ajaxSubmit(function (message) {
                    alert(message);
                    window.location.reload();
                });
            });
        }

    3.后台

               public string UpLoadFile()
            {
                HttpPostedFileBase file = Request.Files["fileName"];
                string fileName = Path.GetFileName(file.FileName);
                string fileExt = Path.GetExtension(fileName);
                if (fileExt == ".xls" || fileExt == ".xlsx")
                {
                    //string dir=excelPath    
                    Directory.CreateDirectory(Path.GetDirectoryName(excelPath));
                    string fullDir = excelPath + fileName;
                    file.SaveAs(fullDir);
                    return "文件保存成功";
                }
                else
                {
                    return "文件保存失败";
                }
            }

     private string excelPath = ConfigurationManager.AppSettings["DailyPublicationFilePath"];//"D:\Test\";//上传到服务器的路径

    4.配置文件  AppSettingConfig.xml

        <!--上传excel存放路径-->
      <add key="ExcelFilePath" value="D:HeNan" />

  • 相关阅读:
    window7环境下VMWare自定义安装Linux虚拟机完全教程
    Extjs的GridPanel分页前后台完整代码实例
    python数据持久存储:pickle模块的基本使用
    一个 11 行 Python 代码实现的神经网络
    Hadoop入门实例——WordCount统计单词
    Linux环境搭建Hadoop伪分布模式
    函数
    循环
    docker环境下gitlab配置ci
    docker部署mysql配置过程记录
  • 原文地址:https://www.cnblogs.com/huangf714/p/7199900.html
Copyright © 2011-2022 走看看