Excel And C#

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

    #1

    Excel And C#


    How can we change excel column's data type thru c#??

    I have 1 column which contains data like 1:30 , 3:30 etc.

    I need this data in this format (1:30) to excel, but when i export it to
    excel it shows.. 1:30:00 AM , it converts it to time, that i don't
    want..

    any ideas??



    Regards,
    Mansi Shah.

    *** Sent via Developersdex http://www.developersdex.com ***
  • raylopez99

    #2
    Re: Excel And C#

    You need to be more specific. Post some code please.

    On Nov 4, 1:36 am, Mansi Shah <ma...@devdex.c omwrote:
    How can we change excel column's data type thru c#??
    >
    I have 1 column which contains data like 1:30 , 3:30 etc.
    >
    I need this data in this format (1:30) to excel, but when i export it to
    excel it shows..  1:30:00 AM , it converts it to time, that i don't
    want..
    >
    any ideas??
    >
    Regards,
    Mansi Shah.
    >
    *** Sent via Developersdexht tp://www.developersd ex.com***

    Comment

    • Nicholas Paldino [.NET/C# MVP]

      #3
      Re: Excel And C#

      Mansi,

      You will want to check the Format property of the Range instance you are
      dealing with to format the contents of the cell appropriately.


      --
      - Nicholas Paldino [.NET/C# MVP]
      - mvp@spam.guard. caspershouse.co m

      "Mansi Shah" <mansi@devdex.c omwrote in message
      news:ObpzZDmPJH A.4152@TK2MSFTN GP04.phx.gbl...
      >
      How can we change excel column's data type thru c#??
      >
      I have 1 column which contains data like 1:30 , 3:30 etc.
      >
      I need this data in this format (1:30) to excel, but when i export it to
      excel it shows.. 1:30:00 AM , it converts it to time, that i don't
      want..
      >
      any ideas??
      >
      >
      >
      Regards,
      Mansi Shah.
      >
      *** Sent via Developersdex http://www.developersdex.com ***

      Comment

      • Mansi Shah

        #4
        Re: Excel And C#


        DataTable dt = new DataTable();

        dt.Columns.Add( new DataColumn("Col 1"));
        dt.Columns.Add( new DataColumn("Col 2"));

        DataRow dr = dt.NewRow();
        dr[0] = "Employee Time: ";
        dr[1] = "13:58"; //total hours:total minutes
        dt.Rows.Add(dr) ;

        GridView gv = new GridView();
        gv.DataSource = dt;
        gv.DataBind();

        Then i am exporting this grid to excel.
        In excel it shows me "13:58:00 AM" instead of "13:58"

        so I need to change the format of excel column, but i don't know how to
        do that..


        Regards,
        Mansi Shah.

        *** Sent via Developersdex http://www.developersdex.com ***

        Comment

        • Nicholas Paldino [.NET/C# MVP]

          #5
          Re: Excel And C#

          Mansi,

          You have to automate excel to do that.

          How are you exporting it to Excel? If you aren't working with an Excel
          sheet directly (instead, creating a CSV, for instance), you really have no
          control over this.


          --
          - Nicholas Paldino [.NET/C# MVP]
          - mvp@spam.guard. caspershouse.co m

          "Mansi Shah" <mansi@devdex.c omwrote in message
          news:ORWXogwPJH A.4372@TK2MSFTN GP04.phx.gbl...
          >
          DataTable dt = new DataTable();
          >
          dt.Columns.Add( new DataColumn("Col 1"));
          dt.Columns.Add( new DataColumn("Col 2"));
          >
          DataRow dr = dt.NewRow();
          dr[0] = "Employee Time: ";
          dr[1] = "13:58"; //total hours:total minutes
          dt.Rows.Add(dr) ;
          >
          GridView gv = new GridView();
          gv.DataSource = dt;
          gv.DataBind();
          >
          Then i am exporting this grid to excel.
          In excel it shows me "13:58:00 AM" instead of "13:58"
          >
          so I need to change the format of excel column, but i don't know how to
          do that..
          >
          >
          Regards,
          Mansi Shah.
          >
          *** Sent via Developersdex http://www.developersdex.com ***

          Comment

          Working...