1
0
mirror of https://github.com/QtExcel/QXlsx.git synced 2025-01-30 05:02:52 +08:00
QXlsx/TestExcel/image.cpp

53 lines
1.1 KiB
C++
Raw Normal View History

2017-09-16 16:34:45 +09:00
// image.cpp
#include <QColor>
2019-01-02 20:56:00 +09:00
#include <QDebug>
2020-07-18 21:01:58 +09:00
#include <QDir>
#include <QImage>
#include <QRgb>
#include <QVariant>
#include <QVector>
#include <QtCore>
#include <QtGlobal>
#include <QtGui>
2019-01-02 20:56:00 +09:00
2020-11-23 23:34:21 +09:00
#if QT_VERSION >= 0x060000 // Qt 6.0 or over
# include <QRandomGenerator>
2020-11-23 23:34:21 +09:00
#endif
2017-09-16 12:21:23 +09:00
#include "xlsxdocument.h"
2017-09-16 16:34:45 +09:00
int image()
2017-09-16 12:21:23 +09:00
{
2020-07-18 21:01:58 +09:00
using namespace QXlsx;
Document xlsx;
for (int i = 0; i < 10; ++i) {
2020-07-18 21:01:58 +09:00
QImage image(40, 30, QImage::Format_RGB32);
2020-11-23 23:34:21 +09:00
#if QT_VERSION >= 0x060000 // Qt 6.0 or over
QRandomGenerator rgen;
image.fill(uint(rgen.generate() % 16581375));
2020-11-23 23:34:21 +09:00
#else
image.fill(uint(qrand() % 16581375));
2020-11-23 23:34:21 +09:00
#endif
int index = xlsx.insertImage(10 * i, 5, image);
2020-07-18 21:01:58 +09:00
QImage img;
if (xlsx.getImage(index, img)) {
QString filename;
filename = QString("image %1.png").arg(index);
img.save(filename);
2020-07-18 21:01:58 +09:00
qDebug() << " [image index] " << index;
}
2020-07-15 20:37:30 +09:00
}
2017-09-23 11:12:59 +09:00
xlsx.saveAs("image1.xlsx");
2017-09-16 12:21:23 +09:00
2017-09-23 11:12:59 +09:00
QXlsx::Document xlsx2("image1.xlsx");
xlsx2.saveAs("image2.xlsx");
2017-09-16 12:21:23 +09:00
return 0;
}