zoukankan      html  css  js  c++  java
  • c# winform 程序 读取Excel

    /// <summary>
            
    /// 上传Excel文件到服务器端
            
    /// </summary>
            
    /// <param name="sender"></param>
            
    /// <param name="e"></param>

            protected void btnUpdateComment_Click(object sender, EventArgs e) {
                
    //第一步,上传EXCEL到服务器端
                if (FileUpload1.HasFile) {
                    
    //验证EXCEL文件格式
                    if (FileUpload1.FileName.ToLower().IndexOf(".xls"== -1{
                        RequiredFieldValidator1.ErrorMessage 
    = "不是有效的Excel文件";
                        RequiredFieldValidator1.IsValid 
    = false;
                        
    return;
                    }


                    
    //EXCEL评论保存位置
                    string _FilePath = string.Empty;
                    
    if (System.Configuration.ConfigurationManager.AppSettings["CommentExcelFile"!= null{
                        _FilePath 
    = System.Configuration.ConfigurationManager.AppSettings["CommentExcelFile"].ToString();
                    }


                    
    //如果此目录不存在则创建此目录
                    if (!System.IO.Directory.Exists(_FilePath)) {
                        System.IO.Directory.CreateDirectory(_FilePath);
                    }


                    
    //生成文件名称
                    string _FileName = DateTime.Now.ToString("yyyyMMddHHmmss"+ "-" + DateTime.Now.Ticks.ToString().Substring(04+ ".xls";
                    _FileName 
    = _FilePath + @"\" + _FileName;

                    
    //保存此文件到服务器指定位置
                    try {
                        FileUpload1.SaveAs(_FileName);
                        Response.Redirect(
    string.Format("CommentDetail.aspx?FileName={0}", _FileName));
                    }
     catch (Exception exp) {
                        
    throw exp;
                    }

                }

            }


    读取EXCEL

    try {
                        DataSet ds 
    = CommUtil.ExcelToDS(_FileName);
                        
    if (ds != null
                            
    && ds.Tables.Count > 0
                            
    && ds.Tables[0].Rows.Count > 0{

    //
  • 相关阅读:
    理解和解决MySQL乱码问题
    搞清字符集和字符编码
    linux下卸载mysql
    mysqldump备份
    mysql 数据类型
    微信对接HIS——微信可查检验结果
    Install Haskell on Ubuntu and CentOS
    php用类生成二维码
    UVA Team Queue
    总有一种正能量触动你的心灵,读刘丁宁的一封信
  • 原文地址:https://www.cnblogs.com/greatandforever/p/1528275.html
Copyright © 2011-2022 走看看