I am frustated...

I am frustated...

Post by Cordo » Wed, 13 Jul 2005 03:34:46


y problem is very simple... (All codes are in ASP.NET & VB.NET)

There is a data grid like -

Name Age Height
KA 12 100.2300
ZX 14 101.0500
XY 9 98.1000


When I export it to excel it gets like, -

Name Age Height
KA 12 100.23
ZX 14 101.05
XY 9 98.1

I have following files in the project -
DataGridExport.aspx
DataGridExport.aspx.vb
cmpDataGridToExcel.vb

That is zero is removed by the excel. I have no idea how to fix this
problem. Anyone pls help me. Here is the DataGridExport.aspx.vb Page
code, -

Imports System.Configuration

Public Class DataGridExport
Inherits System.Web.UI.Page
Protected WithEvents SqlSelectCommand1 As
System.Data.SqlClient.SqlCommand

Protected WithEvents SqlConnection1 As
System.Data.SqlClient.SqlConnection
Protected WithEvents SqlDataAdapter1 As
System.Data.SqlClient.SqlDataAdapter
Protected WithEvents dgToExport As
System.Web.UI.WebControls.DataGrid
Protected WithEvents btnExport As System.Web.UI.WebControls.Button
Protected WithEvents Form1 As System.Web.UI.HtmlControls.HtmlForm
Protected WithEvents DataSet1 As System.Data.DataSet

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection
Me.SqlDataAdapter1 = New System.Data.SqlClient.SqlDataAdapter
Me.DataSet1 = New System.Data.DataSet
CType(Me.DataSet1,
System.ComponentModel.ISupportInitialize).BeginInit()
'
'SqlSelectCommand1
'
Me.SqlSelectCommand1.CommandText = "Select CustomerID,
OrderDate, Freight From Orders " 'Where CustomerID = like(A*) "
Me.SqlSelectCommand1.Connection = Me.SqlConnection1
'
'SqlConnection1
'
Me.SqlConnection1.ConnectionString = "workstation
id=""LOGICON-SERVER1"";packet size=4096;user id=sa;data
source=""LOGICON" & _
"-SERVER1"";persist security info=False;initial
catalog=Northwind"
'
'SqlDataAdapter1
'
Me.SqlDataAdapter1.SelectCommand = Me.SqlSelectCommand1
Me.SqlDataAdapter1.TableMappings.AddRange(New
System.Data.Common.DataTableMapping() {New
System.Data.Common.DataTableMapping("Table", "Orders", New
System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("CustomerID", "CustomerID"), New
System.Data.Common.DataColumnMapping("OrderDate", "OrderDate"), New
System.Data.Common.DataColumnMapping("Freight", "Freight")})})
'
'DataSet1
'
Me.DataSet1.DataSetName = "NewDataSet"
Me.DataSet1.Locale = New
System.Globalization.CultureInfo("en-US")
CType(Me.DataSet1,
System.ComponentModel.ISupportInitialize).EndInit()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

BindGrid()

 
 
 

I am frustated...

Post by Alvin Brun » Fri, 15 Jul 2005 02:59:01

don't think you can fix it because the export automation is not
customizable - at least, i don't have a way of customizing the export thru
content-disposition.

one approach that may work is to convert the items (numbers) into strings by
appending a quote before the digit. ex. 100.2300 to '100.2300

--
Regards,
Alvin Bruney - ASP.NET MVP

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @ www.lulu.com/owc, Amazon.com etc
"Cordon" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...