日期:2014-05-18  浏览次数:20499 次

一个技术小"坎儿",兄弟我就是绕不过去,快疯掉了,shit!
各位兄弟,我这个是EXCEL文件下载函数,打开了就报DDE错误,保存后打开报 "文件格式错误 ",确定后打开的是1.Aspx的Html代码,还有,我想运行后只有 "保存 "和 "取消 "按钮,我快疯了,两天了,仍然没有解决,求兄弟们帮我看看!
public   bool   BrowseExcel(string   strTblname)
{
if(conn.State!=ConnectionState.Open)
{
conn.Open();
}
System.Web.HttpResponse   Response=System.Web.HttpContext.Current.Response;
bool   flag=false;
ds.Clear();
//取得文档编号
string   strSql_Annex_Select= "SELECT   TBLNAME,   COMPANYID,   TBRQ,   TBR,   DWFZR,   JDFZR,   EXBODY,   BZ1,   BZ2,   BZ3,   DOCNAME     FROM   JSJD.TBLEXCELBODY   WHERE   TBLNAME= ' "+strTblname+ " ' ";
da   =   new   OracleDataAdapter();
cmd_Select   =   new   OracleCommand(strSql_Annex_Select,conn);
try
{
da.SelectCommand   =   cmd_Select;
da.Fill(ds);
//声明字节数组,为从数据库读取二进制文档做准备
byte[]   img   =   new   byte[0];
DataRow   dr;
dr   =   ds.Tables[0].Rows[0];
if   (!ds.Tables[0].Rows[0][ "EXBODY "].ToString().Equals( " "))
{
string   FileName   =   System.Web.HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(dr[ "DOCNAME "].ToString()));
//定义文档的查看方式-----在线?下载到本地
Response.AddHeader( "Connection ",   "Keep-Alive ");
Response.ContentType   =   "application/octet-stream ";
Response.AddHeader(   "Content-Type ", "application/x-download ");
Response.AddHeader(   "Content-Type ", "application/vnd.ms-excel ");      
Response.AddHeader( "Content-Disposition ",   "attachment;filename= "   +   FileName);
//赋值
img   =     (byte[])dr[ "EXBODY "];
}
//还原原文件
Response.Flush();
Response.Clear();
Response.BinaryWrite(img);
// Response.End();
System.Web.HttpContext.Current.ApplicationInstance.CompleteRequest();
flag=true;
}
catch(Exception   e)
{
string   str=e.Message;
flag=false;
conn.Close();
}
finally
{
conn.Close();
}
return   flag;
}

------解决方案--------------------

------解决方案--------------------
帮顶,不懂啊!~
------解决方案--------------------
你不要使用下载工具,下载的文件就是对的;具体是什么原因,看有谁知道了
------解决方案--------------------
Response.ContentType = "application/octet-stream ";
Response.AddHeader( "Content-Disposition ", "attachment;filename= " + FileName);
------解决方案--------------------
有点冷,帮顶一下
------解决方案--------------------
首先你拿到数据,即填充完DataSet后,应该关闭数据库
而不是现在这样

http://www.pconline.com.cn/pcedu/empolder/net/0412/513965.html