问题描述
我得函数这样写的大家看看!!!!!!PublicSharedSubToExcel(ByValpageAsSystem.Web.UI.Page,ByValtabAsDataTable,ByValFileNameAsString,ByValtempBtAsString)DimhttpResponseAsSystem.Web.HttpResponse=page.ResponseDimdataGridAsNewdataGriddataGrid.DataSource=tab.DefaultViewdataGrid.AllowPaging=FalsedataGrid.DataBind()httpResponse.AppendHeader("Content-Disposition","attachment;filename="+UrlEncode(FileName,System.Text.Encoding.UTF8))'filename="*.xls";httpResponse.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312")httpResponse.ContentType="application/vnd.ms-excel"DimtwAsNewSystem.IO.StringWritertw.WriteLine(tempBt&vbTab)DimhwAsNewSystem.Web.UI.HtmlTextWriter(tw)dataGrid.RenderControl(hw)DimfilePathAsString=page.Server.MapPath("..")+"Files"+FileNameDimswAsNewSystem.IO.StreamWriter(filePath,False)sw.Write(tw.ToString())sw.Close()DownFile(httpResponse,FileName,filePath)httpResponse.End()EndSubPublicSharedSubDownFile(ByValResponseAsSystem.Web.HttpResponse,ByValfileNameAsString,ByValfullPathAsString)TryResponse.ContentType="application/octet-stream"Response.AppendHeader("Content-Disposition","attachment;filename="&UrlEncode(fileName,System.Text.Encoding.UTF8)+";charset=GB2312")DimfsAsSystem.IO.FileStream=System.IO.File.OpenRead(fullPath)DimfLenAsLong=fs.LengthDimsizeAsInteger=102400'每100K同时下载数据DimreadData(size)AsByte'//指定缓冲区的大小If(size>fLen)Thensize=Convert.ToInt32(fLen)EndIfDimfPosAsLong=0DimisEndAsBoolean=FalseWhile(NotisEnd)If((fPos+size)>fLen)Thensize=Convert.ToInt32(fLen-fPos)ReDimreadData(size)isEnd=TrueEndIffs.Read(readData,0,size)'//读入一个压缩块Response.BinaryWrite(readData)fPos+=sizeEndWhilefs.Close()System.IO.File.Delete(fullPath)CatchexAsExceptionEndTryEndSub
解决方案
解决方案二:
我从DataSet里将数据导出到Excel文件,在本机上运行程序能打开此文件,将程序上传到web服务器,找开文件Excel报以下错误:加载期间出现问题加载期间在下述区域中出现了问题(P):丢失文件:..ThemesCssPageCssAppleGreen.css没有任何数据显示!!!!!!!请高手解答,急,在线等
解决方案三:
AppleGreen.css你也说是CSS的问题了。.跟EXCEL关系应该不大。.你把CSS设置的地方去掉再试试..如果能显示数据的话再检查CSS
解决方案四:
是不是没有安装后office的控件