QXlsx
QXlsx copied to clipboard
reading the existed xlsx file seams to be failed.
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
Dear @maoliangwu
Please show us the full test code
If you show me the entire code you tested, we or someone can help you.
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!'.
}
}
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 <QCoreApplication>
#include "xlsxdocument.h" #include "xlsxchartsheet.h" #include "xlsxcellrange.h" #include "xlsxchart.h" #include "xlsxrichstring.h" #include "xlsxworkbook.h" #include <QDebug> 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
:one: Is the file(c1.xlsx) in the same path as the executable program(*.exe)?
// check current directory
qDebug() << "[debug] current directory is " << QDir::currentPath();
:two: Does the value exist in cell (1,1) in the c1.xlsx file?
:three: 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.
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?
Can you show me whole test code? (All files including excel files. such as c1.xlsx)
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
Thanks for reporting.
:one: 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"
- The namespace for strict Open XML is
http://purl.oclc.org/ooxml
. - See XLSX Strict (Office Open XML), ISO 29500-1:2008-2016 for more information.
:two: QXlsx and current ECMA-376 version uses http://schemas.openxmlformats.org
.
-
See ECMA-376 5th for more information.
-
QXlsx does not support strict format.
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"
- The namespace for strict Open XML is
http://purl.oclc.org/ooxml
.- See XLSX Strict (Office Open XML), ISO 29500-1:2008-2016 for more information.
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.