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. QAxObject format Excel cell
Qt 6.11 is out! See what's new in the release blog

QAxObject format Excel cell

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.1k 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.
  • I Offline
    I Offline
    Indrek M
    wrote on last edited by
    #1

    Hi,

    I'm using Qt 5.11 and C++.
    The question is hot format Excel cells to be as a text.
    E.g., if I set the value to 1.1, then it gets converted to date.
    The output of this code snippet is:
    Set value to "1.1"
    "01.jaan"

    QAxObject* cell = sheet->querySubObject("Cells(int,int)", row, col);
    
    if (cell != nullptr)
    {
    	QString testValue = QString("%1.%2").arg(row).arg(col);
    	qDebug() << "Set value to" << testValue;
    
    	cell->setProperty("Value", testValue);
    	QString newValue = cell->dynamicCall("Text()").toString();
    
    	qDebug() << newValue;
    }
    
    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      Try QString testValue = QString("'%1.%2").arg(row).arg(col);

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      JonBJ I 2 Replies Last reply
      1
      • VRoninV VRonin

        Try QString testValue = QString("'%1.%2").arg(row).arg(col);

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @VRonin
        Hi. I assumed this (the leading ') would be the answer.

        But I am also intrigued. I don't want to go look up the Excel docs, which is where this comes from. Do you know why Excel treats an unquoted 1.1 as a date rather than a floating point number? My thought would be that although one does sometimes type dates into cells, it is considerably more likely to type a floating point number (e.g. a price), so seems strange to me that the default interpretation is selected as date rather than number?

        VRoninV 1 Reply Last reply
        0
        • JonBJ JonB

          @VRonin
          Hi. I assumed this (the leading ') would be the answer.

          But I am also intrigued. I don't want to go look up the Excel docs, which is where this comes from. Do you know why Excel treats an unquoted 1.1 as a date rather than a floating point number? My thought would be that although one does sometimes type dates into cells, it is considerably more likely to type a floating point number (e.g. a price), so seems strange to me that the default interpretation is selected as date rather than number?

          VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          From

          @Indrek-M said in QAxObject format Excel cell:

          "01.jaan"

          Google tells me this is Estonian and QLocale(QLocale::Estonian,QLocale::Estonia).decimalPoint() returns , that's why . is not interpreted as a decimal point

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          JonBJ 1 Reply Last reply
          2
          • VRoninV VRonin

            From

            @Indrek-M said in QAxObject format Excel cell:

            "01.jaan"

            Google tells me this is Estonian and QLocale(QLocale::Estonian,QLocale::Estonia).decimalPoint() returns , that's why . is not interpreted as a decimal point

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @VRonin
            LOL, wow, OK, thanks! :)

            1 Reply Last reply
            0
            • VRoninV VRonin

              Try QString testValue = QString("'%1.%2").arg(row).arg(col);

              I Offline
              I Offline
              Indrek M
              wrote on last edited by
              #6

              Hi,

              The leading ' is a nice trick, and I can use it as a workaround.
              Thanks!

              1 Reply Last reply
              0

              • Login

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