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. [Solved] Saving a excel file In specific folder- name itself time stamp
Forum Updated to NodeBB v4.3 + New Features

[Solved] Saving a excel file In specific folder- name itself time stamp

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 3.3k 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.
  • S Offline
    S Offline
    Swinetha
    wrote on 24 Sept 2013, 04:52 last edited by
    #1

    hai I am using libxl to read and write the data into excel file.

    I am able to save the file name with time stamp in current directory only.

    code for this one is

    @
    QDateTime dateTime = QDateTime::currentDateTime();
    QString dat=dateTime.toString();
    dat=dat.append(".xls");
    book->save(dat.toLatin1().data());
    @

    I want to save a file with this name(time stamp) in specified folder.

    I tried to use QFileDialog,,,

    But I didn't save file with this name.

    QFileDialog::getSaveFileName() it will save the file in specific folder only.

    My problem was to save a excel file with time stamp in user specified folder

    Is there any possible, If it is please suggest me

    1 Reply Last reply
    0
    • R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 24 Sept 2013, 06:33 last edited by
      #2

      what is the type of "book"?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Swinetha
        wrote on 24 Sept 2013, 07:11 last edited by
        #3

        book is

        @
        Book* book = xlCreateBook();
        @
        Book is from libxl.h

        1 Reply Last reply
        0
        • R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 24 Sept 2013, 08:31 last edited by
          #4

          since i don't know if the class Book supports this (and can't figure it out from the "docs":http://www.libxl.com/workbook.html) you can try this:
          @
          QString dir = QFileDialog::getExistingDirectory(this, tr("Get save directory"),
          "",
          QFileDialog::ShowDirsOnly
          | QFileDialog::DontResolveSymlinks);

          QDateTime dateTime = QDateTime::currentDateTime();
          QString file = dat=dat.append(".xls");
          file.prepend( dir % QDir::separator() % dateTime.toString() );

          book->save(file.toLatin1().data());
          @

          If it doesn't work this should definitely work:
          @
          const char* data;
          unsigned int size;

          if(book->saveRaw(&data, &size))
          {
          QString dir = QFileDialog::getExistingDirectory(this, tr("Get save directory"),
          "",
          QFileDialog::ShowDirsOnly
          | QFileDialog::DontResolveSymlinks);

              QDateTime dateTime = QDateTime::currentDateTime();
              QString file =  dat=dat.append(".xls");
                      file.prepend( dir % QDir::separator() % dateTime.toString() );
          
              QFile f( file );
              if( f.open(QIODevice::WriteOnly) )
              {
                      f.write( data, size );
                      f.close();
              }
          

          }
          @

          please forgive any possible compiler error since i wrote the code from my mind and haven't tested it.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Swinetha
            wrote on 24 Sept 2013, 09:58 last edited by
            #5

            file.prepend( dir % QDir::separator() % dateTime.toString() );
            in this line you are used a operator, why sir?

            1 Reply Last reply
            0
            • R Offline
              R Offline
              raven-worx
              Moderators
              wrote on 24 Sept 2013, 10:17 last edited by
              #6

              [quote author="Swinetha" date="1380016720"]file.prepend( dir % QDir::separator() % dateTime.toString() );
              in this line you are used a operator, why sir?[/quote]
              just convenience. You could also use the +-operator, but the %-operator is more efficient (see the QString docs for more info about QStringBuilder)

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Swinetha
                wrote on 24 Sept 2013, 10:38 last edited by
                #7

                thank u for your reply

                @
                QString dir = QFileDialog::getExistingDirectory(this, tr("Get save directory"),
                "",
                QFileDialog::ShowDirsOnly
                | QFileDialog::DontResolveSymlinks);

                QDateTime dateTime = QDateTime::currentDateTime();
                QString file =  dat=dat.append(".xls");
                file.prepend( dir + QDir::separator()  );
                 
                 book->save(file.toLatin1().data());
                

                @

                this is working but If I use % operator I am getting an error in place of % I "+" is working
                thank you

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  raven-worx
                  Moderators
                  wrote on 24 Sept 2013, 10:57 last edited by
                  #8

                  QDir::separator() returns a QChar, propably the string builder can't handle it.

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply
                  0

                  1/8

                  24 Sept 2013, 04:52

                  • Login

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