当前位置:编程学习 > C#/ASP.NET >>

.net中excel导出问题,急急急

我从DataSet里将数据导出到Excel文件,在本机上运行程序能打开此文件,将程序上传到web服务器,找开文件Excel报以下错误:       
                加载期间出现问题           
            加载期间在下述区域中出现了问题(P):       
            丢失文件:..\Themes\Css\PageCss\AppleGreen.css   
没有任何数据显示!!!!!!!    
  请高手解答,急,在线等 --------------------编程问答-------------------- 很明显,找开文件链接或需要AppleGreen.css样式表,服务器没有此文件而本机有.
你把此文件上传到服务器就好了. --------------------编程问答-------------------- 你是如何导出Excel的,导出肯定有问题 --------------------编程问答-------------------- 代碼怎樣寫的? --------------------编程问答-------------------- 你导出的Excel格式编码有问题,加上它了没: Response.Write("<meta http-equiv=Content-Type content=text/html;charset=gb2312>") --------------------编程问答-------------------- 上传的路径有问题吧
看一下你上传的路径是不是存在 --------------------编程问答-------------------- 应该是丢失CSS文件造成的吧!
重新检查一下你的文件看是否有丢失,或是重新定义试试看。 --------------------编程问答-------------------- 我得函数这样写的大家看看!!!!!!
    Public Shared Sub ToExcel(ByVal page As System.Web.UI.Page, ByVal tab As DataTable, ByVal FileName As String, ByVal tempBt As String)

        Dim httpResponse As System.Web.HttpResponse = page.Response
        Dim dataGrid As New dataGrid
        dataGrid.DataSource = tab.DefaultView
        dataGrid.AllowPaging = False
        dataGrid.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"


        Dim tw As New System.IO.StringWriter
        tw.WriteLine(tempBt & vbTab)

        Dim hw As New System.Web.UI.HtmlTextWriter(tw)
        dataGrid.RenderControl(hw)

        Dim filePath As String = page.Server.MapPath("..") + "\Files\" + FileName

        Dim sw As New System.IO.StreamWriter(filePath, False)
        sw.Write(tw.ToString())
        sw.Close()

        DownFile(httpResponse, FileName, filePath)

        httpResponse.End()
    End Sub
    Public Shared Sub DownFile(ByVal Response As System.Web.HttpResponse, ByVal fileName As String, ByVal fullPath As String)

        Try
            Response.ContentType = "application/octet-stream"

            Response.AppendHeader("Content-Disposition", "attachment;filename=" & UrlEncode(fileName, System.Text.Encoding.UTF8) + ";charset=GB2312")

            Dim fs As System.IO.FileStream = System.IO.File.OpenRead(fullPath)
            Dim fLen As Long = fs.Length
            Dim size As Integer = 102400  '每100K同时下载数据     
            Dim readData(size) As Byte      '//指定缓冲区的大小     
            If (size > fLen) Then
                size = Convert.ToInt32(fLen)
            End If
            Dim fPos As Long = 0
            Dim isEnd As Boolean = False
            While (Not isEnd)

                If ((fPos + size) > fLen) Then

                    size = Convert.ToInt32(fLen - fPos)
                    ReDim readData(size)
                    isEnd = True
                End If
                fs.Read(readData, 0, size)    '//读入一个压缩块     
                Response.BinaryWrite(readData)
                fPos += size
            End While
            fs.Close()
            System.IO.File.Delete(fullPath)
        Catch ex As Exception
        End Try

    End Sub --------------------编程问答-------------------- 先留个记号,晚上来看. --------------------编程问答-------------------- 我也遇到问题。我用了一个最笨的方法。
就是把EXCEL存成HTML格式。然后把EXCEL的头提出来了。·  --------------------编程问答-------------------- 来打酱油
补充:.NET技术 ,  VB.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,