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. 物流运输(最短路+dp)

    这道题是相当的火,但是在tyher的讲解下我一遍就AC了!!! Part 1 理解题目 从第一天到最后一天,总会有一些点莫名其妙地走不了,所以导致我们不能按照上一次的最短路一直运输得到最少费用,而需要 ...

  2. python学习第七天流程控制循环while和循环for区别

    流程控制循环是任何编程语言都有一种循环结构,在python while 和break continue 搭配使用,还一种while ....else ......,for循环有序列表和字符串 whil ...

  3. Android应用程序开发之图片操作(二)——工程图片资源的加载及OOM的处理

    (一)工程图片资源的加载方法 在Android应用程序开发之图片操作(一)中,详细说明了如何操作各种资源图片,只是有的没有附上示例代码,在此,我将针对项目工程中的图片资源的显示加载进行说明.官方说明, ...

  4. cdn.bootcss.com无法访问 解决方法

    今天angularjs的网站突然加载报错,提示Refused to execute script from 'https://cdnjs.com/' because its MIME type ('t ...

  5. 【问题解决方案】GitHub的md中使用库中图片

    参考链接: 在GitHub中使用图片功能 步骤: 在github上的仓库建立一个存放图片的文件夹,文件夹名字随意.如:image 将需要在插入到文本中的图片,push到image文件夹中. 然后打开g ...

  6. CSS中quotes属性以及content的open(close)-quotes属性

    定义和用法 quotes 属性设置嵌套引用(embedded quotation)的引号类型. 可能的值 值 描述 none 规定 "content" 属性的 "open ...

  7. eclipse不小心删除文件如何恢复

    转自:https://blog.csdn.net/u012129031/article/details/78791277 1.右键点击java项目工程名,选择restort from history, ...

  8. 阿里云搭建香港代理服务器 shadownsocks

    阿里云香港代理服务器搭建方式: 1.阿里云官网购买轻量级服务器即可,流量,配置套餐自己选择,CENTOS7,进入控制台后打开端口管理列表,打开9000即可. 2.安装shadownsocks服务端: ...

  9. spark- PySparkSQL之PySpark解析Json集合数据

    PySparkSQL之PySpark解析Json集合数据 数据样本 12341234123412342|asefr-3423|[{"}] 正菜: #-*- coding:utf-8 –*- ...

  10. [Luogu2365]任务安排(斜率优化)

    [Luogu2365]任务安排 题目描述 N个任务排成一个序列在一台机器上等待完成(顺序不得改变),这N个任务被分成若干批,每批包含相邻的若干任务.从时刻0开始,这些任务被分批加工,第i个任务单独完成 ...