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   }  
  • 相关阅读:
    linux查询php.ini位置
    laravel打印完整SQL语句
    python识别图片中的文字
    python -使用pytesseract识别文字时遇到的问题
    python弹出选择文件的弹出窗获取文件方法
    python将字符串中多个空格换为一个空格
    python生成word文档
    linux下tar命令
    python使用xpath获取内容
    正则表达式匹配空行
  • 原文地址:https://www.cnblogs.com/cxy521/p/1048795.html
Copyright © 2011-2022 走看看