Urgent Pls!!!!! Problem while exporting data to excel sheet in asp

G

Guest

Hi

I am exporting data from database to an excel sheet. Some of the data have
"+/-" .For example: "120+/-10"

When i connect to the local database and export the data, it does export
correctly say "120+/-10" . But when i connect to production database, it does
not export data correctly say "120 10" .

Does any have idea of what is going wrong here. Ihave attached test file
also.
Pls Help



here is test.aspx file
----------------------

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="test.aspx.vb"
Inherits="TycoMIS.test"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>
test
</title>
<meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<LINK href="resources/newClass.css" type="text/css" rel="STYLESHEET">
</HEAD>
<body class="pagebackground" leftMargin="1" topMargin="1" rightMargin="2">
<form id="Form2" method="post" runat="server">
<table id="TestTable" runat=server cellSpacing="0" cellPadding="0"
width="100%" border="0">
</table>
</form>
</body>
</HTML>

here is test.aspx.vb file
-------------------------

Public Class test
Inherits System.Web.UI.Page
Protected WithEvents TestTable As System.Web.UI.HtmlControls.HtmlTable
#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

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
Response.Buffer = True
Response.AddHeader("Content-Disposition",
"attachment;filename=test.xls")
Response.ContentType = "application/vnd.ms-excel"
'
Dim i As Integer
For i = 0 To 9
Dim Ptr As New HtmlTableRow()
addData(Ptr, "70+/-2")
TestTable.Controls.AddAt(i, Ptr)
Next
'
End Sub
'
Public Sub addData(ByRef Ptr As HtmlTableRow, ByVal txtStr As String)
Dim Ptc1 As New HtmlTableCell()
'
Ptc1.InnerText = txtStr
Ptr.Controls.Add(Ptc1)
'
End Sub
'
End Class


Now if we run this file it should open excel file and write "70+/-2" in 10
lines. but it is writing "702" in 10 lines.

if i comment following 3 lines in page_load events then it is displaying
"70+/-2" in 10 lines on browser.

Response.Buffer = True
Response.AddHeader("Content-Disposition",
"attachment;filename=test.xls")
Response.ContentType = "application/vnd.ms-excel"

please help me.
 
J

Jim Corey

Sileesh,

Try adding hard-coded quotation marks around the strings.
This can prevent excel from formatting the data.

I don't have any code in front on me, but if I recall correctly, sending
<td>"4.5"</td>
meant excel would treat this as a string (the quotes would not be
displayed), whereas
<td>4.5</td>
meant excel would treat it as a number.

Maybe this would help in your situation.

Jim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top