Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reading the existed xlsx file seams to be failed. #68

Open
maoliangwu opened this issue Feb 16, 2020 · 9 comments
Open

reading the existed xlsx file seams to be failed. #68

maoliangwu opened this issue Feb 16, 2020 · 9 comments

Comments

@maoliangwu
Copy link

I've created an excel file manually,there are data in the sheet.
When I use the hello world test code to read the content, it print nothing. xlsxR.load() can't be entered! But when I change the file created and saved by qxls code, it turned to to print the correct result.
Document xlsxR(filepath);
if (xlsxR.load()) // load excel file
{
int row = 1; int col = 1;
Cell* cell = xlsxR.cellAt(row, col); // get cell pointer.
if ( cell != NULL )
{
QVariant var = cell->readValue(); // read cell value (number(double), QDateTime, QString ...)
qDebug() << "1.1 "<<var; // display value. it is 'Hello Qt!'.
}
}
Dose it have any difference between the two files. Can I use this to read the files created by other applications? Also the "wsheet->getFullCells( &maxRow, &maxCol );" seams dose not work

@j2doll
Copy link
Member

j2doll commented Feb 16, 2020

Dear @maoliangwu

Please show us the full test code

If you show me the entire code you tested, we or someone can help you.

@maoliangwu
Copy link
Author

Dear @maoliangwu

Please show us the full test code

If you show me the entire code you tested, we or someone can help you.

// [2] Reading excel file(*.xlsx)
QString filepath=QFileDialog::getOpenFileName(this,tr("Open File"),".",("xlsx files (*.xlsx)"));//获取保存路径

Document xlsxR(filepath);
if (xlsxR.load()) // load excel file
{
    int row = 1; int col = 1;
    Cell* cell = xlsxR.cellAt(row, col); // get cell pointer.
    if ( cell != NULL )
    {
        QVariant var = cell->readValue(); 
        qDebug() << "1.1 value"<<var; // display value. it is 'Hello Qt!'.
    }
}

@maoliangwu
Copy link
Author

Dear @maoliangwu

Please show us the full test code

If you show me the entire code you tested, we or someone can help you.

Trust me these are the entire code
My office version is 2016
excel can open he show the correct data of c1.xlsx

this is the main.cpp.
#include

#include "xlsxdocument.h"
#include "xlsxchartsheet.h"
#include "xlsxcellrange.h"
#include "xlsxchart.h"
#include "xlsxrichstring.h"
#include "xlsxworkbook.h"
#include
using namespace QXlsx;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

QString filepath="c1.xlxs";//获取保存路径

Document xlsxR(filepath);
if (xlsxR.load()) // load excel file
{
    int row = 1; int col = 1;
    Cell* cell = xlsxR.cellAt(row, col); // get cell pointer.
    if ( cell != NULL )
    {
        QVariant var = cell->readValue();
        qDebug() << "1.1 "<<var; // display value. it is 'Hello Qt!'.
    }
}
return a.exec();

}

This is .pro
QT -= gui

CONFIG += c++11 console
CONFIG -= app_bundle

The following define makes your compiler emit warnings if you use

any feature of Qt which as been marked deprecated (the exact warnings

depend on your compiler). Please consult the documentation of the

deprecated API in order to know how to port your code away from it.

DEFINES += QT_DEPRECATED_WARNINGS

You can also make your code fail to compile if you use deprecated APIs.

In order to do so, uncomment the following line.

You can also select to disable deprecated APIs only up to a certain version of Qt.

#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

SOURCES += main.cpp

INCLUDEPATH += "C:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/ucrt"
LIBS += -L"C:/Program Files (x86)/Windows Kits/10/Lib/10.0.10240.0/ucrt/x64"

QXLSX_PARAENTPATH=./
QXLSX_HEADERPATH=./header/
QXLSX_SOURCEPATH=./source/
include(./QXlsx.pri)

Please help me to find the key,thanks

j2doll added a commit that referenced this issue Feb 16, 2020
@j2doll
Copy link
Member

j2doll commented Feb 16, 2020

1️⃣ Is the file(c1.xlsx) in the same path as the executable program(*.exe)?

// check current directory
qDebug() << "[debug] current directory is " << QDir::currentPath();

2️⃣ Does the value exist in cell (1,1) in the c1.xlsx file?

3️⃣ I have created the dev78 branch for you and have configured the IssueTest example.

If you can open a c1.xlsx file or some that you need to test, we can test it by putting it in the example.

@maoliangwu
Copy link
Author

1️⃣ Is the file(c1.xlsx) in the same path as the executable program(*.exe)?
YES

// check current directory
qDebug() << "[debug] current directory is " << QDir::currentPath();

this is the output : [debug] current directory is "E:/work/friends/dongmei/predict_tests/build_simplereadtest"
actually, there is a file named "c1.xlsx" in this directory

2️⃣ Does the value exist in cell (1,1) in the c1.xlsx file?
the debug step cannot enter load condition, if (xlsxR.load()) is false.
3️⃣ I have created the dev78 branch for you and have configured the IssueTest example.
https://github.com/QtExcel/QXlsx/blob/dev78/HelloWorld/main.cpp is a little different with mine.It created the xlsx using code "saveas". But my file is created manually on my computer sys. It is offered by someone else. dev78 works well, but it cannot solve my problem.

If you can open a c1.xlsx file or some that you need to test, we can test it by putting it in the example.
how can I send my xlsx file to you?

May be you didn't catch my problem. I use the QXlsx code to read,but not write. Is is a mistaken way?

@j2doll
Copy link
Member

j2doll commented Feb 17, 2020

Can you show me whole test code? (All files including excel files. such as c1.xlsx)

@maoliangwu
Copy link
Author

Can you show me whole test code? (All files including excel files. such as c1.xlsx)

please get the whole test code by the follows.Thanks
https://github.com/maoliangwu/worktest

@j2doll
Copy link
Member

j2doll commented Feb 18, 2020

Thanks for reporting.

1️⃣ c1.xlsx uses strict format, not transitional mode.

  • See workbook.xml of c1.xlsx
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workbook
  xmlns="http://purl.oclc.org/ooxml/spreadsheetml/main"
  xmlns:r="http://purl.oclc.org/ooxml/officeDocument/relationships"

2️⃣ QXlsx and current ECMA-376 version uses http://schemas.openxmlformats.org.

  • See ECMA-376 5th for more information.

  • QXlsx does not support strict format.

@maoliangwu
Copy link
Author

Thanks for reporting.

1️⃣ c1.xlsx uses strict format, not transitional mode.

  • See workbook.xml of c1.xlsx
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workbook
  xmlns="http://purl.oclc.org/ooxml/spreadsheetml/main"
  xmlns:r="http://purl.oclc.org/ooxml/officeDocument/relationships"

2️⃣ QXlsx and current ECMA-376 version uses http://schemas.openxmlformats.org.

  • See ECMA-376 5th for more information.
  • QXlsx does not support strict format.

Ok, I get it now, thanks. I will try QAxObject to read files in this format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants