zoukankan      html  css  js  c++  java
  • Excel下载控制

     1 private   static   bool   DownFile(System.Web.HttpResponse   Response,string   fileName,string   fullPath)  
     2   {  
     3   try  
     4   {  
     5   Response.ContentType   =   "application/octet-stream";  
     6       
     7   Response.AppendHeader("Content-Disposition","attachment;filename="   +   
     8   System.Web.HttpUtility.UrlEncode(fileName,System.Text.Encoding.UTF8)   +   ";charset=GB2312");   
     9   System.IO.FileStream   fs=   System.IO.File.OpenRead(fullPath);  
    10   long   fLen=fs.Length;  
    11   int   size=102400;//每100K同时下载数据   
    12   byte[]   readData   =   new   byte[size];//指定缓冲区的大小   
    13   if(size>fLen)size=Convert.ToInt32(fLen);  
    14   long   fPos=0;  
    15   bool   isEnd=false;  
    16   while   (!isEnd)   
    17   {   
    18   if((fPos+size)>fLen)  
    19   {  
    20   size=Convert.ToInt32(fLen-fPos);  
    21   readData   =   new   byte[size];  
    22   isEnd=true;  
    23   }  
    24   fs.Read(readData,   0,   size);//读入一个压缩块   
    25   Response.BinaryWrite(readData);  
    26   fPos+=size;  
    27   }   
    28   fs.Close();   
    29   System.IO.File.Delete(fullPath);  
    30   return   true;  
    31   }  
    32   catch  
    33   {  
    34   return   false;  
    35   }  
    36   }  
  • 相关阅读:
    JavaScript表单验证年龄
    PHP会话处理相关函数介绍
    SpringCloud(第一天)
    springboot加强
    SpringBoot的第一个demo
    ElasticSearch(分布式全文搜索引擎)
    Redis集群
    NoSql和Redis
    ElementUI实现CRUD(修改前端页面),前后台解决跨域问题
    SSM+ElementUI综合练习和Swagger和postman的使用(第二天)
  • 原文地址:https://www.cnblogs.com/cxy521/p/1048795.html
Copyright © 2011-2022 走看看