Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How can I modify the date format in EXCEL with VBA?

How can I modify the date format in EXCEL with VBA?

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 880 Views
  • 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.
  • S Offline
    S Offline
    studyQt
    wrote on last edited by
    #1

    How can I modify the date format in EXCEL with VBA?this is my code:

    void ExcelEngine::setCellDateFormat(UINT row,UINT column)
    {
        QAxObject *cell = pWorksheet->querySubObject("Cells(int,int)",row,column);//获取单元格对象
        if ( cell )
        {
         //  cell->dynamicCall("NumberFormat([$-F800]dddd, mmmm dd, yyyy)");
            //     cell->dynamicCall("SetNumberFormat(mm/dd/yyyy)");//失败
           //    cell->dynamicCall("NumberFormat(yyyy""年""m""月""d""日"";@)");
       //  cell->setProperty("NumberFormat","[$-F800]dddd, mmmm dd, yyyy")  ;
        QAxObject  *format   = cell->querySubObject("NumberFormat ");
         format->setProperty("NumberFormat","mm/dd/yyyy")  ;
    
        }
        delete cell;
    
    }
    

    I don't know where it is wrong.

    jsulmJ 1 Reply Last reply
    0
    • S studyQt

      How can I modify the date format in EXCEL with VBA?this is my code:

      void ExcelEngine::setCellDateFormat(UINT row,UINT column)
      {
          QAxObject *cell = pWorksheet->querySubObject("Cells(int,int)",row,column);//获取单元格对象
          if ( cell )
          {
           //  cell->dynamicCall("NumberFormat([$-F800]dddd, mmmm dd, yyyy)");
              //     cell->dynamicCall("SetNumberFormat(mm/dd/yyyy)");//失败
             //    cell->dynamicCall("NumberFormat(yyyy""年""m""月""d""日"";@)");
         //  cell->setProperty("NumberFormat","[$-F800]dddd, mmmm dd, yyyy")  ;
          QAxObject  *format   = cell->querySubObject("NumberFormat ");
           format->setProperty("NumberFormat","mm/dd/yyyy")  ;
      
          }
          delete cell;
      
      }
      

      I don't know where it is wrong.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @studyQt Did you debug it? Is cell != nullptr? Is format != nullptr?
      I'm not sure

      delete cell;
      

      is correct as you're deleting a cell, but you just want to change it's format, right?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply
      2
      • jsulmJ jsulm

        @studyQt Did you debug it? Is cell != nullptr? Is format != nullptr?
        I'm not sure

        delete cell;
        

        is correct as you're deleting a cell, but you just want to change it's format, right?

        S Offline
        S Offline
        studyQt
        wrote on last edited by
        #3

        @jsulm
        oh,thank you for your help,format is NULLptr. Below is the code available:

        void ExcelEngine::setCellDateFormat(UINT row,UINT column)
        {
         QAxObject *cell = pWorksheet->querySubObject("Cells(int,int)",row,column);//获取单元格对象
            if ( cell )
            {
             cell->setProperty("NumberFormat","[$-F800]dddd, mmmm dd, yyyy")  ;
            }
        }
        
        jsulmJ 1 Reply Last reply
        0
        • S studyQt

          @jsulm
          oh,thank you for your help,format is NULLptr. Below is the code available:

          void ExcelEngine::setCellDateFormat(UINT row,UINT column)
          {
           QAxObject *cell = pWorksheet->querySubObject("Cells(int,int)",row,column);//获取单元格对象
              if ( cell )
              {
               cell->setProperty("NumberFormat","[$-F800]dddd, mmmm dd, yyyy")  ;
              }
          }
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @studyQt Does this code work?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply
          0
          • jsulmJ jsulm

            @studyQt Does this code work?

            S Offline
            S Offline
            studyQt
            wrote on last edited by
            #5

            @jsulm Right!

            jsulmJ 1 Reply Last reply
            0
            • S studyQt

              @jsulm Right!

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @studyQt Then please mark this thread as solved.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              S 1 Reply Last reply
              0
              • jsulmJ jsulm

                @studyQt Then please mark this thread as solved.

                S Offline
                S Offline
                studyQt
                wrote on last edited by
                #7

                @jsulm This is my first post. I don’t konw how to do it ?So,
                I am trying

                1 Reply Last reply
                1

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved