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

Discussion in 'ASP .Net' started by =?Utf-8?B?U2lsZWVzaA==?=, Nov 8, 2004.

  1. 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.
     
    =?Utf-8?B?U2lsZWVzaA==?=, Nov 8, 2004
    #1
    1. Advertising

  2. =?Utf-8?B?U2lsZWVzaA==?=

    Jim Corey Guest

    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

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Jim Corey, Nov 8, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. http://www.visual-basic-data-mining.net/forum

    Exporting Datagrid's data to an Excel Sheet.

    http://www.visual-basic-data-mining.net/forum, Oct 25, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    611
    Steve C. Orr [MVP, MCSD]
    Oct 25, 2004
  2. =?Utf-8?B?U2lsZWVzaA==?=
    Replies:
    4
    Views:
    420
    =?Utf-8?B?U2lsZWVzaA==?=
    Nov 5, 2004
  3. =?Utf-8?B?U3JpZGhhcg==?=

    change the sheet name while exporting datagrid data to excel

    =?Utf-8?B?U3JpZGhhcg==?=, Nov 9, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    554
    =?Utf-8?B?U3JpZGhhcg==?=
    Nov 9, 2006
  4. AD1234
    Replies:
    5
    Views:
    1,713
  5. Open the excel in new page while exporting

    , Aug 21, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    129
Loading...

Share This Page