上载后导出到excel无法正常工作 [英] Export to excel not working after upload

查看:102
本文介绍了上载后导出到excel无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我编写了一个将Excel导出到Excel的函数
该功能在上传网站之前有效,但在上传网站之后无效,请帮助我

我的代码是:

Hi I write a function to Export gridview to excel
the function is working before upload site but it is not working after uploading site please help me

my code is:

Protected Sub btnExportExcel_Click(ByVal sender As Object,

ByVal e As EventArgs)

  Response.Clear()

  Response.Buffer = True



  Response.AddHeader("content-disposition",

  "attachment;filename=GridViewExport.xls")

  Response.Charset = ""

  Response.ContentType = "application/vnd.ms-excel"



  Dim sw As New StringWriter()

  Dim hw As New HtmlTextWriter(sw)



  GridView1.AllowPaging = False

  GridView1.DataBind()



  'Change the Header Row back to white color

  GridView1.HeaderRow.Style.Add("background-color", "#FFFFFF")



  'Apply style to Individual Cells

  GridView1.HeaderRow.Cells(0).Style.Add("background-color", "green")

  GridView1.HeaderRow.Cells(1).Style.Add("background-color", "green")

  GridView1.HeaderRow.Cells(2).Style.Add("background-color", "green")

  GridView1.HeaderRow.Cells(3).Style.Add("background-color", "green")



  For i As Integer = 0 To GridView1.Rows.Count - 1

   Dim row As GridViewRow = GridView1.Rows(i)



   'Change Color back to white

   row.BackColor = System.Drawing.Color.White



   'Apply text style to each Row

   row.Attributes.Add("class", "textmode")



   'Apply style to Individual Cells of Alternating Row

   If i Mod 2 <> 0 Then

    row.Cells(0).Style.Add("background-color", "#C2D69B")

    row.Cells(1).Style.Add("background-color", "#C2D69B")

    row.Cells(2).Style.Add("background-color", "#C2D69B")

    row.Cells(3).Style.Add("background-color", "#C2D69B")

   End If

  Next

  GridView1.RenderControl(hw)



  'style to format numbers to string

  Dim style As String = "<style>.textmode{mso-number-format:\@;}</style>"

  Response.Write(style)

  Response.Output.Write(sw.ToString())

  Response.Flush()

  Response.End()

End Sub

推荐答案

如果要将DataGridView导出到Excel,则可以使用OleDb进行操作:
使用OLEDB读写Excel [ http://support.microsoft.com/kb/301982 [
IF you are going to export a DataGridView to Excel you can do it with OleDb:
Reading and Writing Excel using OLEDB[^]

or use office interop:
http://support.microsoft.com/kb/301982[^]

I actually dont know what you are doing in your code though :)


这篇关于上载后导出到excel无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆