zoukankan      html  css  js  c++  java
  • create Excel file

    http://www.codepal.co.uk/show/Line_breaks_lost_and_br_tags_show_when_exporting_to_Excel_file

     Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    
        Dim dt As New DataTable
        dt.Columns.Add(New DataColumn("Text1", GetType(System.String)))
    
        Dim dr As DataRow = dt.NewRow
        dr.Item("Text1") = String.Format("This is line one{0}This is line two{0}This is line three", "<br/>")
        dt.Rows.Add(dr)
    
        Response.Clear()
        Response.AddHeader("content-disposition", "attachment;filename=exported.xls")
        Response.AddHeader("Pragma", "public")
        Response.AddHeader("Cache-Control", "max-age=0")
        Response.ContentType = "application/vnd.ms-excel"
        Response.ContentEncoding = System.Text.Encoding.UTF8
    
        Dim gvEx As New GridView
        gvEx.AutoGenerateColumns = True
        gvEx.AllowSorting = False
        gvEx.AllowPaging = False
        Dim sw As New System.IO.StringWriter
        Dim hw As New System.Web.UI.HtmlTextWriter(sw)
        gvEx.DataSource = dt
        gvEx.DataBind()
        hw.AddAttribute("xmlns:x", "urn:schemas-microsoft-com:office:excel") ' optional'
        hw.RenderBeginTag(HtmlTextWriterTag.Html)
        hw.RenderBeginTag(HtmlTextWriterTag.Head)
        hw.RenderBeginTag(HtmlTextWriterTag.Style)
        hw.Write("br {mso-data-placement:same-cell;}")
        hw.RenderEndTag() ' /Style'
        hw.RenderEndTag() ' /Head'
        hw.RenderBeginTag(HtmlTextWriterTag.Body)
        gvEx.RenderControl(hw)
        hw.RenderEndTag() ' /Body'
        hw.RenderEndTag() ' /Html'
        Response.Write(HttpUtility.HtmlDecode(sw.ToString))    ' turns &lt;br/&gt; back into <br/>'
        Response.Flush()
        Response.End()
    
    End Sub
  • 相关阅读:
    MinGW
    zip ubuntu使用
    7zip ubuntu使用
    ffmpeg入门
    音频采样
    购房需知
    linux网络配置相关
    挂载与卸载
    spring boot启动异常:java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver
    获取配置文件yml的@ConfigurationProperties和@Value的区别
  • 原文地址:https://www.cnblogs.com/dufu/p/6627860.html
Copyright © 2011-2022 走看看