Export to Excel truncates numbers

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Reggie

    Export to Excel truncates numbers

    Hi and TIA! I'm exporting a dataset/datgrid to excel but some text fields
    get converted to numbers in excel and I loose leading zero's. I've tried
    several methods with no success. If anyone has come across this and can
    point me in the right direction I would appreciate it. Thanks!

    --

    *************** ***
    Reggie


  • Jeroen Mostert

    #2
    Re: Export to Excel truncates numbers

    Reggie wrote:
    Hi and TIA! I'm exporting a dataset/datgrid to excel but some text fields
    get converted to numbers in excel and I loose leading zero's. I've tried
    several methods with no success. If anyone has come across this and can
    point me in the right direction I would appreciate it. Thanks!
    >
    I'm setting followups for this question to microsoft.publi c.excel since this
    is not a .NET-specific question.

    The way to avoid is is to ensure that you are actually writing the data as
    text. In formula form, it should be ="00123" and not =00123, for example.
    How you do this depends on how you're doing the export. For automation, you
    can use the "Formula" property of a Range object, for export, you're
    probably best off with XML, as you can't specify data types in CSV.

    --
    J.

    Comment

    • Mark Rae [MVP]

      #3
      Re: Export to Excel truncates numbers

      "Reggie" <NoSpam_chief12 3101@NoSpam_hot mail.comwrote in message
      news:A5SdnccuXt uOH-fVnZ2dnUVZ_tnin Z2d@comcast.com ...
      Hi and TIA! I'm exporting a DataSet/DatGrid to Excel but some text fields
      get converted to numbers in Excel and I oose leading zeroes. I've tried
      several methods with no success. If anyone has come across this and can
      point me in the right direction I would appreciate it. Thanks!
      Please show your code...


      --
      Mark Rae
      ASP.NET MVP


      Comment

      • Reggie

        #4
        Re: Export to Excel truncates numbers

        Mark, Here is a link to the code I am using

        here is a link (http://www.codeproject.com/KB/dotnet/ExportToExcel.aspx) to
        code that looks like it would work, but I'm not exactly sure how to
        implement it. Thanks for your time!

        --

        *************** ***
        Reggie
        "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
        news:eKOyT0T5IH A.1176@TK2MSFTN GP02.phx.gbl...
        "Reggie" <NoSpam_chief12 3101@NoSpam_hot mail.comwrote in message
        news:A5SdnccuXt uOH-fVnZ2dnUVZ_tnin Z2d@comcast.com ...
        >
        >Hi and TIA! I'm exporting a DataSet/DatGrid to Excel but some text
        >fields get converted to numbers in Excel and I oose leading zeroes. I've
        >tried several methods with no success. If anyone has come across this
        >and can point me in the right direction I would appreciate it. Thanks!
        >
        Please show your code...
        >
        >
        --
        Mark Rae
        ASP.NET MVP
        http://www.markrae.net

        Comment

        • Reggie

          #5
          Re: Export to Excel truncates numbers

          Also forgot to mention I am using vb.net

          --

          *************** ***
          Reggie
          "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
          news:eKOyT0T5IH A.1176@TK2MSFTN GP02.phx.gbl...
          "Reggie" <NoSpam_chief12 3101@NoSpam_hot mail.comwrote in message
          news:A5SdnccuXt uOH-fVnZ2dnUVZ_tnin Z2d@comcast.com ...
          >
          >Hi and TIA! I'm exporting a DataSet/DatGrid to Excel but some text
          >fields get converted to numbers in Excel and I oose leading zeroes. I've
          >tried several methods with no success. If anyone has come across this
          >and can point me in the right direction I would appreciate it. Thanks!
          >
          Please show your code...
          >
          >
          --
          Mark Rae
          ASP.NET MVP
          http://www.markrae.net

          Comment

          • Mark Rae [MVP]

            #6
            Re: Export to Excel truncates numbers

            "Reggie" <NoSpam_chief12 3101@NoSpam_hot mail.comwrote in message
            news:9KudnajLSb 9rL-fVnZ2dnUVZ_h7in Z2d@comcast.com ...

            [top-posting corrected]
            >>Hi and TIA! I'm exporting a DataSet/DatGrid to Excel but some text
            >>fields get converted to numbers in Excel and I oose leading zeroes.
            >>I've tried several methods with no success. If anyone has come across
            >>this and can point me in the right direction I would appreciate it.
            >>Thanks!
            >>
            >Please show your code...
            >
            Here is a link to the code I am using
            http://www.dotnetjohn.com/articles.aspx?articleid=36
            That's a very old article. Have you contacted the author to see if there is
            a more up-to-date version...?
            Here is a link (http://www.codeproject.com/KB/dotnet/ExportToExcel.aspx)
            to code that looks like it would work, but I'm not exactly sure how to
            implement it.
            Create a new class file and drop the code into it. Unfortunately, you're
            using VB.NET so you'll either have to convert the code first, or create a
            separate assembly and drop that into your project.

            Then just pass it your DataSet and the path of the output file...


            --
            Mark Rae
            ASP.NET MVP


            Comment

            • Reggie

              #7
              Re: Export to Excel truncates numbers

              "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
              news:%23kW9JiX5 IHA.1420@TK2MSF TNGP06.phx.gbl. ..
              "Reggie" <NoSpam_chief12 3101@NoSpam_hot mail.comwrote in message
              news:9KudnajLSb 9rL-fVnZ2dnUVZ_h7in Z2d@comcast.com ...
              >
              [top-posting corrected]
              >
              >>>Hi and TIA! I'm exporting a DataSet/DatGrid to Excel but some text
              >>>fields get converted to numbers in Excel and I oose leading zeroes.
              >>>I've tried several methods with no success. If anyone has come across
              >>>this and can point me in the right direction I would appreciate it.
              >>>Thanks!
              >>>
              >>Please show your code...
              >>
              >Here is a link to the code I am using
              >http://www.dotnetjohn.com/articles.aspx?articleid=36
              >
              That's a very old article. Have you contacted the author to see if there
              is a more up-to-date version...?
              >
              >Here is a link (http://www.codeproject.com/KB/dotnet/ExportToExcel.aspx)
              >to code that looks like it would work, but I'm not exactly sure how to
              >implement it.
              >
              Create a new class file and drop the code into it. Unfortunately, you're
              using VB.NET so you'll either have to convert the code first, or create a
              separate assembly and drop that into your project.
              >
              Then just pass it your DataSet and the path of the output file...
              >
              >
              --
              Mark Rae
              ASP.NET MVP
              http://www.markrae.net
              Didn't notice how old that was. My bad. Creating an assembly sounds like a
              good plan. I'll give it a try and let you know. Thanks!


              Comment

              Working...