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

create Excel file - snippet的更多相关文章

  1. How to create Excel file in C#

    http://csharp.net-informations.com/excel/csharp-create-excel.htm Before you create an Excel file in ...

  2. Formatting Excel File Using Ole2 In Oracle Forms

    Below is the some useful commands of Ole2 to format excel file in Oracle Forms.-- Change font size a ...

  3. NetSuite SuiteScript 2.0 export data to Excel file(xls)

    In NetSuite SuiteScript, We usually do/implement export data to CSV, that's straight forward: Collec ...

  4. csharp:using OpenXml SDK 2.0 and ClosedXML read excel file

    https://openxmlexporttoexcel.codeplex.com/ http://referencesource.microsoft.com/ 引用: using System; u ...

  5. Creating Excel File in Oracle Forms

    Below is the example to create an excel file in Oracle Forms.Pass the Sql query string to the below ...

  6. Read / Write Excel file in Java using Apache POI

    Read / Write Excel file in Java using Apache POI 2014-04-18 BY DINESH LEAVE A COMMENT About a year o ...

  7. The 13th tip of DB Query Analyzer, powerful processing EXCEL file

    The 13thtip of DB Query Analyzer, powerful processing EXCEL file MA Genfeng (Guangdong UnitollServic ...

  8. A simple way to crack VBA password in Excel file

    Unbelivibale, but I found a very simple way that really works! Do the follwoing: 1. Create a new sim ...

  9. C# How To Read .xlsx Excel File With 3 Lines Of Code

    Download Excel.zip - 9.7 KB Download ExcelDLL.zip - 3.7 KB Introduction We produce professional busi ...

随机推荐

  1. SpringCloud-Eureka-服务注册是如何发起的

    原文:https://xsxy007.github.io Spring Cloud环境下,服务提供者和消费者启动后都会将自身注册到Eureka 一.将服务注册到Eureka 一个SpringBoot应 ...

  2. Nginx 教程 (1):基本概念

      简介 嗨!分享就是关心!所以,我们愿意再跟你分享一点点知识.我们准备了这个划分为三节的<Nginx教程>.如果你对 Nginx 已经有所了解,或者你希望了解更多,这个教程将会对你非常有 ...

  3. canvas 画正方形和圆形

    绘制正方形 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...

  4. rabbitmq windows安装 及 centos安装

     windows安装如下: 安装方法如下网址: https://baijiahao.baidu.com/s?id=1605656085633071281&wfr=spider&for= ...

  5. 创建工程时出现 A project with this name already exists 提示

    https://segmentfault.com/a/1190000018513060 创建项目时没注意,后来发现放错了位置或其他问题,想要重新创建同名项目,只在文件夹处删除是不行的.会出现以下提示 ...

  6. 64-基于TMS320C6455、XC5VSX95T 的6U CPCI无线通信处理平台

    基于TMS320C6455.XC5VSX95T 的6U CPCI无线通信处理平台   1. 板卡概述 本板卡由我公司自主研发,基于CPCI架构,符合PICMG2.0 D3.0标准,包含双TI TMS3 ...

  7. 激活密钥许可证VMware Workstation Pro 15 激活许可证

    虚拟机 VMware Workstation Pro 15.5.0 及永久激活密钥 虚拟机下载地址:https://download3.vmware.com/software/wkst/file/VM ...

  8. HDU 6686 Rikka with Travels 树的直径

    题意:定义两点之间的距离为从一个点到另一个点经过的点数之和(包括这两个点),设二元组(x, y)为两条不相交的路径,一条长度为x,一条长度为y,问二元组(x, y)出现了多少次? 思路:直接上jls的 ...

  9. 【python实例】判断是否是回文数

    """ 输入一个数,判断一个这个数是否是回文数.例如:121,这个数反过来还是121,所以这个是回文数: 再如:134,这个数反过来是431,所以这不是一个回文数: 12 ...

  10. PLC 控制系统资源

    之前整理的PC高级语言与PLC通讯代码下载链接:三菱:http://blog.sina.com.cn/s/blog_16d7d3ecb0102x6wj.html倍福:http://bbs.elecfa ...