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



  • 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


  • Moderators

    what is the type of "book"?



  • book is

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


  • Moderators

    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.



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


  • Moderators

    [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)



  • 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


  • Moderators

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.