zoukankan      html  css  js  c++  java
  • GridView to Excel

    1.EnableEventValidation = "false"

    <%@ Page Language="VB" EnableEventValidation = "false" AutoEventWireup="false" CodeFile="frmNextPlan.aspx.vb" Inherits="frmTrainRecord" %>

    2.Code:

     Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click

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

            Response.ClearContent()
            Response.Buffer = True
            Response.Charset = "GB2312"
            Response.ContentEncoding = System.Text.Encoding.UTF8
            Response.AddHeader("content-disposition", "attachment; filename=MyExcelFile.xls")

            Response.ContentType = "application/excel"

        '防止乱码关键
            Response.Write("<meta http-equiv=Content-Type content=text/html; charset=utf-8>")

            Dim sw As New StringWriter()

            Dim htw As New HtmlTextWriter(sw)
            GridView1.AllowPaging = False
            GridView1.DataBind()
            GridView1.RenderControl(htw)

            ' Style is added dynamically

            Response.Write(style)

            Response.Write(sw.ToString())

            Response.End()
            GridView1.AllowPaging = True
            GridView1.DataBind()
        End Sub

        Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)


        End Sub

  • 相关阅读:
    redis整合springboot
    安装k8s
    线程池工具类几种实现
    数据库mysql注意点及sql优化
    五年规划
    在 Ubuntu 16.04 安装ROS Kinetic 教程
    谈谈form-data请求格式 js
    C# Body为form-data file文件上传至第三方接口 http请求
    .net c# 使用form-data方式发起http请求
    使用form-data和raw作为body发起POST请求的区别
  • 原文地址:https://www.cnblogs.com/songrun/p/2171519.html
Copyright © 2011-2022 走看看