在网页中选择本地Excel文件并获取文件内容,需要将该文件首先上传到服务器上,然后再根据该文件在服务器上的地址获取该文件的内容,代码如下 :

 /// <summary>
    
/// 上传文件的根目录
    
/// </summary>
    private string bootPath = HttpContext.Current.Request.PhysicalApplicationPath + "Files\\";
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (file_note.HasFile)
        {
            //判断文件是否小于10Mb  
            if (file_note.PostedFile.ContentLength < 10485760)
            {
                string fileForm = file_note.FileName.Split('.')[file_note.FileName.Split('.').Length - 1];
                string filePath = bootPath + string.Format("{0:yyyyMMddHHmmss}", DateTime.Now) + "." + fileForm;
                file_note.PostedFile.SaveAs(filePath);

                DataSet a = CommonClassLib.ExcelHelper.ReturnDataSetFromExcelFile(filePath); 

                Response.Write("<script language:javascript>javascript:window.opener=null;window.close();</script>");
            }
        }    }  

 

 

相关文章:

  • 2022-12-23
  • 2021-08-31
  • 2021-09-11
  • 2022-12-23
  • 2021-12-03
  • 2021-10-31
  • 2022-12-23
猜你喜欢
  • 2021-10-28
  • 2022-12-23
  • 2022-12-23
  • 2021-12-08
  • 2021-06-21
  • 2021-05-22
相关资源
相似解决方案