diff --git a/IssueTest/test.cpp b/IssueTest/test.cpp index f2054b0..6c71e0f 100644 --- a/IssueTest/test.cpp +++ b/IssueTest/test.cpp @@ -7,6 +7,9 @@ #include #include #include +#include +#include +#include #include using namespace std; @@ -18,39 +21,41 @@ using namespace std; #include "xlsxrichstring.h" #include "xlsxworkbook.h" -int test91( QVector params ); +int test95( QVector params ); int test( QVector params ) { qDebug() << "[debug] current path : " << QDir::currentPath(); - return test91( params ); + return test95( params ); } -// tested in Qt 5.14.1, MingW 7.3.0 64bit -int test91( QVector params ) +int test95( QVector params ) { using namespace QXlsx; - Document doc(":/91.xlsx"); // made by ms excel 2019 - if (!doc.isLoadPackage()) { - qDebug() << "Failed to load xlsx."; - return (-1); - } + Document xlsx; - QXlsx::CellRange range = doc.dimension(); - for (int i = 2; i < range.rowCount() + 1; i++) + for (int i=0; i<10; ++i) { - for (int j = 1; j < range.columnCount()+1; j++) - { - QString dataStr; - auto tmpCell = doc.cellAt(i, j); - if(tmpCell) - { - dataStr = tmpCell->value().toString().trimmed(); - qDebug() << dataStr; - } - } + QImage image(40, 30, QImage::Format_RGB32); + image.fill( uint(qrand() % 16581375) ); + + int index = xlsx.insertImage( 10*i, 5, image ); + + QImage img; + if ( xlsx.getImage( index, img ) ) + { + QString filename; + filename = QString("image %1.png").arg( index ); + img.save( filename ); + + qDebug() << " [image index] " << index; + } } + xlsx.saveAs("image1.xlsx"); + + QXlsx::Document xlsx2("image1.xlsx"); + xlsx2.saveAs("image2.xlsx"); return 0; } diff --git a/QXlsx/header/xlsxdocument.h b/QXlsx/header/xlsxdocument.h index da50fcb..e449c05 100644 --- a/QXlsx/header/xlsxdocument.h +++ b/QXlsx/header/xlsxdocument.h @@ -42,6 +42,7 @@ public: QVariant read(int row, int col) const; int insertImage(int row, int col, const QImage &image); + bool getImage(int imageIndex, QImage& img); Chart *insertChart(int row, int col, const QSize &size); diff --git a/QXlsx/header/xlsxdrawinganchor_p.h b/QXlsx/header/xlsxdrawinganchor_p.h index 2a90109..4a09310 100644 --- a/QXlsx/header/xlsxdrawinganchor_p.h +++ b/QXlsx/header/xlsxdrawinganchor_p.h @@ -51,7 +51,9 @@ public: DrawingAnchor(Drawing *drawing, ObjectType objectType); virtual ~DrawingAnchor(); + void setObjectPicture(const QImage &img); + bool getObjectPicture(QImage &img); void setObjectGraphicFrame(QSharedPointer chart); diff --git a/QXlsx/header/xlsxmediafile_p.h b/QXlsx/header/xlsxmediafile_p.h index 4b00c7a..1c18578 100644 --- a/QXlsx/header/xlsxmediafile_p.h +++ b/QXlsx/header/xlsxmediafile_p.h @@ -1,43 +1,8 @@ -/**************************************************************************** -** Copyright (c) 2013-2014 Debao Zhang -** All right reserved. -** -** Permission is hereby granted, free of charge, to any person obtaining -** a copy of this software and associated documentation files (the -** "Software"), to deal in the Software without restriction, including -** without limitation the rights to use, copy, modify, merge, publish, -** distribute, sublicense, and/or sell copies of the Software, and to -** permit persons to whom the Software is furnished to do so, subject to -** the following conditions: -** -** The above copyright notice and this permission notice shall be -** included in all copies or substantial portions of the Software. -** -** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -** -****************************************************************************/ +// xlsxmediafile_p.h #ifndef QXLSX_XLSXMEDIAFILE_H #define QXLSX_XLSXMEDIAFILE_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt Xlsx API. It exists for the convenience -// of the Qt Xlsx. This header file may change from -// version to version without notice, or even be removed. -// -// We mean it. -// - #include "xlsxglobal.h" #include @@ -51,6 +16,7 @@ public: MediaFile(const QString &fileName); MediaFile(const QByteArray &bytes, const QString &suffix, const QString &mimeType=QString()); +public: void set(const QByteArray &bytes, const QString &suffix, const QString &mimeType=QString()); QString suffix() const; QString mimeType() const; @@ -64,8 +30,8 @@ public: void setFileName(const QString &name); QString fileName() const; -private: - QString m_fileName; //... +protected: + QString m_fileName; QByteArray m_contents; QString m_suffix; QString m_mimeType; diff --git a/QXlsx/header/xlsxworksheet.h b/QXlsx/header/xlsxworksheet.h index 8cf4aab..80f1f74 100644 --- a/QXlsx/header/xlsxworksheet.h +++ b/QXlsx/header/xlsxworksheet.h @@ -98,6 +98,7 @@ public: Cell *cellAt(int row, int column) const; int insertImage(int row, int column, const QImage &image); + bool getImage(int imageIndex, QImage& img); Chart *insertChart(int row, int column, const QSize &size); bool mergeCells(const CellRange &range, const Format &format=Format()); diff --git a/QXlsx/source/xlsxdocument.cpp b/QXlsx/source/xlsxdocument.cpp index d1cb1e5..6f0825e 100644 --- a/QXlsx/source/xlsxdocument.cpp +++ b/QXlsx/source/xlsxdocument.cpp @@ -649,6 +649,14 @@ int Document::insertImage(int row, int column, const QImage &image) return 0; } +bool Document::getImage(int imageIndex, QImage& img) +{ + if (Worksheet *sheet = currentWorksheet()) + return sheet->getImage(imageIndex, img); + + return false; +} + /*! * Creates an chart with the given \a size and insert it to the current * active worksheet at the position \a row, \a col. diff --git a/QXlsx/source/xlsxdrawinganchor.cpp b/QXlsx/source/xlsxdrawinganchor.cpp index 409ac20..8c668f5 100644 --- a/QXlsx/source/xlsxdrawinganchor.cpp +++ b/QXlsx/source/xlsxdrawinganchor.cpp @@ -74,6 +74,15 @@ void DrawingAnchor::setObjectPicture(const QImage &img) m_objectType = Picture; } +bool DrawingAnchor::getObjectPicture(QImage &img) +{ + if ( m_pictureFile == nullptr ) + return false; + + bool ret = img.loadFromData( m_pictureFile->contents() ); + return ret; +} + //{{ liufeijin void DrawingAnchor::setObjectShape(const QImage &img) { diff --git a/QXlsx/source/xlsxworksheet.cpp b/QXlsx/source/xlsxworksheet.cpp index b2bd4f6..02da753 100644 --- a/QXlsx/source/xlsxworksheet.cpp +++ b/QXlsx/source/xlsxworksheet.cpp @@ -1117,6 +1117,35 @@ int Worksheet::insertImage(int row, int column, const QImage &image) return imageIndex; } +bool Worksheet::getImage(int imageIndex, QImage& img) +{ + Q_D(Worksheet); + + if( imageIndex <= (-1) ) + { + return false; + } + + if ( d->drawing == nullptr ) + { + return false; + } + + int realImageIndex = imageIndex - 1; // minus one + + DrawingAnchor* danchor = d->drawing->anchors.at( realImageIndex ); + // QSharedPointer // for multithread + if ( danchor == nullptr ) + { + return false; + } + + bool ret= danchor->getObjectPicture(img); + return ret; +} + + + /*! * Creates an chart with the given \a size and insert * at the position \a row, \a column. diff --git a/README.ko.md b/README.ko.md index 74e6fc0..f9c7593 100644 --- a/README.ko.md +++ b/README.ko.md @@ -40,13 +40,18 @@ - QXlsx 는 MIT 라이센스 입니다. [https://github.com/QtExcel/QXlsx](https://github.com/QtExcel/QXlsx) - 다음과 같은 놀라운 프로젝트들을 만들어 주신 분들에게 감사의 말씀을 올립니다. :+1: - Qt 는 LGPL v3 라이센스 또는 상업용 라이센스 입니다. [https://www.qt.io/](https://www.qt.io/) - - QtXlsx 는 MIT 라이센스 입니다. [https://github.com/dbzhang800/QtXlsxWriter](https://github.com/dbzhang800/QtXlsxWriter) + - QtXlsx 는 MIT 라이센스 입니다. :+1: [https://github.com/dbzhang800/QtXlsxWriter](https://github.com/dbzhang800/QtXlsxWriter) - Qt-Table-Printer 는 BSD 3-Clause 라이센스 입니다. [https://github.com/T0ny0/Qt-Table-Printer](https://github.com/T0ny0/Qt-Table-Printer) - recurse 는 MIT 라이센스 입니다. [https://github.com/pkoretic/recurse](https://github.com/pkoretic/recurse) - libfort 는 MIT 라이센스 입니다. [https://github.com/seleznevae/libfort](https://github.com/seleznevae/libfort) - colorprintf 는 MIT 라이센스 입니다. [https://github.com/VittGam/colorprintf](https://github.com/VittGam/colorprintf) - HelloActions-Qt 는 MIT 라이센스 입니다. [https://github.com/jaredtao/HelloActions-Qt](https://github.com/jaredtao/HelloActions-Qt) +## 축하 +- 우리의 코드가 북극에 갑니다. + ![](markdown.data/arcvalut.png) +- 자세한 정보는 링크를 보세요. https://archiveprogram.github.com/ + ## :email: 문의 - 이슈를 남겨 주세요. [https://github.com/QtExcel/QXlsx/issues](https://github.com/QtExcel/QXlsx/issues) - 프로젝트 참여에 관심이 있으신 분은 이슈로 연락주세요. diff --git a/README.md b/README.md index 8fc716b..a94db72 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,9 @@ - You can also use it as a static library. ## How to use -- See [examples](Example.md). -- See [wiki](https://github.com/QtExcel/QXlsx/wiki). -- See [FAQ](https://github.com/QtExcel/QXlsx/wiki/FAQ). +- See [examples](Example.md) +- See [wiki](https://github.com/QtExcel/QXlsx/wiki) +- See [FAQ](https://github.com/QtExcel/QXlsx/wiki/FAQ) ## How to set up (Installation) @@ -40,13 +40,18 @@ - QXlsx is under MIT license. [https://github.com/QtExcel/QXlsx](https://github.com/QtExcel/QXlsx) - Thank you for creating the following amazing projects. :+1: - Qt is under LGPL v3 license or Commercial license. [https://www.qt.io/](https://www.qt.io/) - - QtXlsxWriter is under MIT license. [https://github.com/dbzhang800/QtXlsxWriter](https://github.com/dbzhang800/QtXlsxWriter) + - QtXlsxWriter is under MIT license. :+1: [https://github.com/dbzhang800/QtXlsxWriter](https://github.com/dbzhang800/QtXlsxWriter) - Qt-Table-Printer is under BSD 3-Clause license. [https://github.com/T0ny0/Qt-Table-Printer](https://github.com/T0ny0/Qt-Table-Printer) - recurse is under MIT license. [https://github.com/pkoretic/recurse](https://github.com/pkoretic/recurse) - libfort is under MIT license. [https://github.com/seleznevae/libfort](https://github.com/seleznevae/libfort) - colorprintf is under MIT license. [https://github.com/VittGam/colorprintf](https://github.com/VittGam/colorprintf) - HelloActions-Qt is under MIT license. [https://github.com/jaredtao/HelloActions-Qt](https://github.com/jaredtao/HelloActions-Qt) +## Congratulations +- Our code is going to the North Pole. + ![](markdown.data/arcvalut.png) +- See link for more information. https://archiveprogram.github.com/ + ## :email: Contact - Leave me a issue. [https://github.com/QtExcel/QXlsx/issues](https://github.com/QtExcel/QXlsx/issues) - If you are interested in participating in the project, please contact us by issue. diff --git a/TestExcel/image.cpp b/TestExcel/image.cpp index 8c32d5b..9a20dd5 100644 --- a/TestExcel/image.cpp +++ b/TestExcel/image.cpp @@ -4,18 +4,38 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include #include "xlsxdocument.h" int image() { - QXlsx::Document xlsx; - QImage image(40, 30, QImage::Format_RGB32); - image.fill(Qt::green); + using namespace QXlsx; + + Document xlsx; + for (int i=0; i<10; ++i) { - int index = xlsx.insertImage( 10*i, 5, image ); - qDebug() << " [image index] " << index; + QImage image(40, 30, QImage::Format_RGB32); + image.fill( uint(qrand() % 16581375) ); + + int index = xlsx.insertImage( 10*i, 5, image ); + + QImage img; + if ( xlsx.getImage( index, img ) ) + { + QString filename; + filename = QString("image %1.png").arg( index ); + img.save( filename ); + + qDebug() << " [image index] " << index; + } } xlsx.saveAs("image1.xlsx"); diff --git a/markdown.data/arcvalut.png b/markdown.data/arcvalut.png new file mode 100644 index 0000000..6b26103 Binary files /dev/null and b/markdown.data/arcvalut.png differ