Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Ho can set date and time value in excel by excel automation?

Ho can set date and time value in excel by excel automation?

Scheduled Pinned Locked Moved C / C++ / MFC
questiontestingtools
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Le rner
    wrote on last edited by
    #1

    Hi all, i m using excel automation to write excel file. everything is working fine but when i insert date and time value in excel sheet it not displayed in proper format. i m inserting date and time value in this format "Dec 16, 2010 06:17:00 PM" but it display in this format "16/12/2010 6:17:00 PM" and also if date and column width is small it display only # here. please tell me how can i insert the date and time value to show in same format in excel file. thanks in advance.

    L F 2 Replies Last reply
    0
    • L Le rner

      Hi all, i m using excel automation to write excel file. everything is working fine but when i insert date and time value in excel sheet it not displayed in proper format. i m inserting date and time value in this format "Dec 16, 2010 06:17:00 PM" but it display in this format "16/12/2010 6:17:00 PM" and also if date and column width is small it display only # here. please tell me how can i insert the date and time value to show in same format in excel file. thanks in advance.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You need to set the format for the column to display the time in the way you want, and the width of the column to display all its content. The # string merely indicates that the column is not wide enough for Excel to display its content.

      Just say 'NO' to evaluated arguments for diadic functions! Ash

      L 1 Reply Last reply
      0
      • L Lost User

        You need to set the format for the column to display the time in the way you want, and the width of the column to display all its content. The # string merely indicates that the column is not wide enough for Excel to display its content.

        Just say 'NO' to evaluated arguments for diadic functions! Ash

        L Offline
        L Offline
        Le rner
        wrote on last edited by
        #3

        Richard MacCutchan wrote:

        You need to set the format for the column to display the time in the way you want

        please tell me how can i do this?

        L 1 Reply Last reply
        0
        • L Lost User

          Le@rner wrote:

          please tell me how can i do this?

          Check the options for cell properties in the documentation; I suspect that the actual details may vary depending on which version of Excel you are using.

          Just say 'NO' to evaluated arguments for diadic functions! Ash

          L Offline
          L Offline
          Le rner
          wrote on last edited by
          #4

          No how can set it from vc++ code.

          L 1 Reply Last reply
          0
          • L Le rner

            Richard MacCutchan wrote:

            You need to set the format for the column to display the time in the way you want

            please tell me how can i do this?

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Le@rner wrote:

            please tell me how can i do this?

            Check the options for cell properties in the documentation; I suspect that the actual details may vary depending on which version of Excel you are using.

            Just say 'NO' to evaluated arguments for diadic functions! Ash

            L 1 Reply Last reply
            0
            • L Le rner

              No how can set it from vc++ code.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              As I said above check the documentation[^] for the exact details.

              Just say 'NO' to evaluated arguments for diadic functions! Ash

              1 Reply Last reply
              0
              • L Le rner

                Hi all, i m using excel automation to write excel file. everything is working fine but when i insert date and time value in excel sheet it not displayed in proper format. i m inserting date and time value in this format "Dec 16, 2010 06:17:00 PM" but it display in this format "16/12/2010 6:17:00 PM" and also if date and column width is small it display only # here. please tell me how can i insert the date and time value to show in same format in excel file. thanks in advance.

                F Offline
                F Offline
                FilipKrnjic
                wrote on last edited by
                #7

                Hi, with this Excel .NET component you can easily do this: Here is a sample Excel C# code (managed C++/CLI shouldn't be much different):

                var ef = new ExcelFile();

                var cell = ef.Worksheets.Add("Sheet 1").Cells[0, 0];
                cell.Value = new DateTime(2010, 12, 16, 18, 17, 00);
                cell.Style.NumberFormat = "mmm dd, yyyy hh:mm:ss AM/PM";

                ef.SaveXls(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "DateTime.xls"));

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups