ruibrinuits
New Member
I want to export \[code\]DataTabel\[/code\] to \[code\]Excel\[/code\] file, where each cell in the \[code\]DataTable\[/code\] is converted to only on cell in the Excel The problem is when a cell in \[code\]DataTable\[/code\] has a text with multiple line ( break) .. in the the excel it will consume more than one cell and will appear in the following line .. I have used the following function to convert the \[code\]DataTable\[/code\] to \[code\]Excel\[/code\] file .. \[code\]Public Sub exportExcel(ByVal p As Page, ByRef dt As DataTable) Dim pageName As String = p.Request.RawUrl() Dim attachment As String = "attachment; filename=ExcelData.xls" p.Response.ClearContent() p.Response.ContentType = "application/vnd.ms-excel" p.Response.AddHeader("content-disposition", attachment) p.Response.ContentEncoding = System.Text.Encoding.Unicode p.Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble()) p.Response.Cache.SetCacheability(HttpCacheability.NoCache) Dim stringWrite As StringWriter = New StringWriter Dim htmlWrite As HtmlTextWriter = New HtmlTextWriter(stringWrite) Dim tab As String = "" For Each dc As DataColumn In dt.Columns htmlWrite.Write(tab + dc.ColumnName) tab = vbTab Next Dim i As Integer For Each dr As DataRow In dt.Rows tab = "" For i = 0 To dt.Columns.Count - 1 htmlWrite.Write(tab & dr(i).ToString()) tab = vbTab Next p.Response.Write(vbLf) Next p.Response.Write(stringWrite.ToString()) p.Response.[End]()End Sub\[/code\]