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. Can't download xls or xlsx files

Can't download xls or xlsx files

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 760 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.
  • M Offline
    M Offline
    Mark58
    wrote on last edited by
    #1

    Hi
    I try to download an Excel-file, but I always get the following error:
    "QZip: invalid header signature, index may be incomplete".

    When I download the file via the browser, everything is okay; I can open the excel-file.
    When I try to download the file via my application, Excel tells me that the file format or file extension is not valid. To load the downloaded file with QXlsx does not work either.

    QString downloadaddress ="https://file-examples.com/wp-content/uploads/2017/02/file_example_XLSX_50.xlsx";
    
    QNetworkAccessManager *manager = new QNetworkAccessManager(this);
    
          connect(manager, SIGNAL(finished(QNetworkReply*)),
                this, SLOT(replyFinished(QNetworkReply*)));
         const QUrl url = QUrl(file_to_download);
    
        QNetworkRequest request;
        request.setUrl(url);
    
        QSslConfiguration configSsl = QSslConfiguration::defaultConfiguration();
        configSsl.setProtocol(QSsl::AnyProtocol);
        request.setSslConfiguration(configSsl);
    
        manager->get(request);
    
    void MainWindow::replyFinished (QNetworkReply *reply)
    {
    qDebug() << "read rawHeaderList:" <<reply->rawHeaderList();
    qDebug() << "read contentheadertype:" << reply->header(QNetworkRequest::ContentTypeHeader).toString();
     qDebug() << "read serverheader:" << reply->header(QNetworkRequest::ServerHeader).toString();
    
     QString filename = "C:/downloaded.xlsx";
    QFile *file = new QFile(filename);
    
    if(!file->open(QIODevice::ReadWrite)) {
    qDebug() << "Error";
              }
    else {
     QTextStream outStream(file);
                  outStream << reply->readAll();
                  file->close();
    }
    QFile excelfile(excel_file);
        if (!excelfile.exists()) {
            qDebug() << "file does not exist"; }
        else {
            if (excelfile.isReadable()) {qDebug() << "is readable";} 
            else { qDebug() << "ist NOT readable";}
    }
    

    reply->header(QNetworkRequest::ContentTypeHeader).toString() is: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

    qDebug tells me that the file is NOT readable and then it gives me the message: "QZip: invalid header signature, index may be incomplete"

    What is wrong?
    Any help would be appreciated.

    Thanks

    K 1 Reply Last reply
    0
    • M Offline
      M Offline
      Mark58
      wrote on last edited by
      #6

      Thanks,

      file->write(reply->readAll()) 
      

      really worked.
      Obviously it was a problem of QFile.

      The error message "QZip: invalid header signature, index may be incomplete" came from QXlsx.

      Pablo J. RoginaP 1 Reply Last reply
      0
      • M Mark58

        Hi
        I try to download an Excel-file, but I always get the following error:
        "QZip: invalid header signature, index may be incomplete".

        When I download the file via the browser, everything is okay; I can open the excel-file.
        When I try to download the file via my application, Excel tells me that the file format or file extension is not valid. To load the downloaded file with QXlsx does not work either.

        QString downloadaddress ="https://file-examples.com/wp-content/uploads/2017/02/file_example_XLSX_50.xlsx";
        
        QNetworkAccessManager *manager = new QNetworkAccessManager(this);
        
              connect(manager, SIGNAL(finished(QNetworkReply*)),
                    this, SLOT(replyFinished(QNetworkReply*)));
             const QUrl url = QUrl(file_to_download);
        
            QNetworkRequest request;
            request.setUrl(url);
        
            QSslConfiguration configSsl = QSslConfiguration::defaultConfiguration();
            configSsl.setProtocol(QSsl::AnyProtocol);
            request.setSslConfiguration(configSsl);
        
            manager->get(request);
        
        void MainWindow::replyFinished (QNetworkReply *reply)
        {
        qDebug() << "read rawHeaderList:" <<reply->rawHeaderList();
        qDebug() << "read contentheadertype:" << reply->header(QNetworkRequest::ContentTypeHeader).toString();
         qDebug() << "read serverheader:" << reply->header(QNetworkRequest::ServerHeader).toString();
        
         QString filename = "C:/downloaded.xlsx";
        QFile *file = new QFile(filename);
        
        if(!file->open(QIODevice::ReadWrite)) {
        qDebug() << "Error";
                  }
        else {
         QTextStream outStream(file);
                      outStream << reply->readAll();
                      file->close();
        }
        QFile excelfile(excel_file);
            if (!excelfile.exists()) {
                qDebug() << "file does not exist"; }
            else {
                if (excelfile.isReadable()) {qDebug() << "is readable";} 
                else { qDebug() << "ist NOT readable";}
        }
        

        reply->header(QNetworkRequest::ContentTypeHeader).toString() is: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

        qDebug tells me that the file is NOT readable and then it gives me the message: "QZip: invalid header signature, index may be incomplete"

        What is wrong?
        Any help would be appreciated.

        Thanks

        K Offline
        K Offline
        koahnig
        wrote on last edited by koahnig
        #2

        @mark58

        Hi and welcome to devent forum

        Did you check if the file is there where you expect?
        Possibly an AV scanner is preventing you from access.

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply
        2
        • M Offline
          M Offline
          Mark58
          wrote on last edited by
          #3

          Hi,

          Yes, the file is where it should be. There is some downloading, but to my mind, the download process seems to be incomplete. When I try to open the Excel-file with Excel, it tells me that the "file format or file extension is not valid".
          Qt tells me "QZip: invalid header signature, index may be incomplete" when I try to open the file with my qt-application.

          I turned off the AV-scanner and got the same result.

          K 1 Reply Last reply
          0
          • M Mark58

            Hi,

            Yes, the file is where it should be. There is some downloading, but to my mind, the download process seems to be incomplete. When I try to open the Excel-file with Excel, it tells me that the "file format or file extension is not valid".
            Qt tells me "QZip: invalid header signature, index may be incomplete" when I try to open the file with my qt-application.

            I turned off the AV-scanner and got the same result.

            K Offline
            K Offline
            koahnig
            wrote on last edited by
            #4

            @mark58

            You are using QTextStream which is probably causing some translations in the byte stream. Try QDataStream since it is a binary dataset you are downloading.

            Vote the answer(s) that helped you to solve your issue(s)

            1 Reply Last reply
            5
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #5

              Why not simply using QFile::write(reply->readAll()) instead a QTextStream or QDataStream?

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              4
              • M Offline
                M Offline
                Mark58
                wrote on last edited by
                #6

                Thanks,

                file->write(reply->readAll()) 
                

                really worked.
                Obviously it was a problem of QFile.

                The error message "QZip: invalid header signature, index may be incomplete" came from QXlsx.

                Pablo J. RoginaP 1 Reply Last reply
                0
                • M Mark58

                  Thanks,

                  file->write(reply->readAll()) 
                  

                  really worked.
                  Obviously it was a problem of QFile.

                  The error message "QZip: invalid header signature, index may be incomplete" came from QXlsx.

                  Pablo J. RoginaP Offline
                  Pablo J. RoginaP Offline
                  Pablo J. Rogina
                  wrote on last edited by
                  #7

                  @mark58 said in Can't download xls or xlsx files:

                  really worked.

                  So if your issue is solved, please don't forget to mark your post as such. Thanks.

                  Upvote the answer(s) that helped you solve the issue
                  Use "Topic Tools" button to mark your post as Solved
                  Add screenshots via postimage.org
                  Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                  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