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. 32.Group Anagrams(相同元素的不同组合)

    Level:   Medium 题目描述: Given an array of strings, group anagrams together. Example: Input: ["eat ...

  2. ssh - OpenSSH SSH 客户端 (远程登录程序)

    总览 (SYNOPSIS) ssh [-l login_name ] hostname | user@hostname [command ] ssh -words [-afgknqstvxACNTX1 ...

  3. Nginx学习总结:proxy与rewrite模块(三)

    斜体下划线,表示建议采用默认配置,无需显式的配置 一.ngx_http_upstream_module 此模块中可配置的指令并不是很多.nginx的负载均衡算法包括: 1)round-robin:轮询 ...

  4. 98-基于FPGA Spartan6 的双路光纤PCIe采集卡(2路光纤卡) 光纤PCIe卡

    1.板卡概述 板卡采用xilinx Spartan6系列芯片,支持 PCI Express Base Specification 1.1 x1.内含丰富的逻辑资源和存储单元,板卡FPGA外接双片32M ...

  5. Cent OS 7 VNC 安装

    关闭防火墙 关闭selinux 挂载光盘到本地 #yum install tigervnc-server -y #cp /lib/systemd/system/vncserver@.service / ...

  6. 生成树计数 Matrix-Tree 定理 学习笔记

    一直都知道要用Matrix-Tree定理来解决生成树计数问题,但是拖到今天才来学.博主数学不好也只能跟着各位大佬博客学一下它的应用以及会做题,证明实在是不会. 推荐博客: https://www.cn ...

  7. springboot全局字符编码设置

    1.在application.properties中设置 #编码格式 spring.http.encoding.force=true spring.http.encoding.charset=UTF- ...

  8. 设备树中#address-cells和#size-cells作用

    device tree source Example1 / { #address-cells = <0x1>; // 在 root node 下使用 1 個 u32 來代表 address ...

  9. 洛谷4843 BZOJ2502 清理雪道

    有源汇有上下界的最小可行流. YY一下建图应该很好搞吧(? 就是对于每个雪道都是[1,inf]然后源点到所有点都是[0,inf]所有点到汇点都是[0,inf] 这样的话跑一个有源汇上下界最小可行流就可 ...

  10. BUUCTF | [HCTF 2018]admin

    首先爬一遍整个网站,发现有没注册的时候有“login”,"register",这两个页面,注册一个123用户登录后发现有 "index“,”post“,”logout“, ...