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

56 lines
1.1 KiB
C++
Raw Normal View History

2017-09-16 16:34:45 +09:00
// image.cpp
2019-01-02 20:56:00 +09:00
#include <QtGlobal>
#include <QtCore>
#include <QDebug>
2017-09-16 12:21:23 +09:00
#include <QtGui>
2020-07-18 21:01:58 +09:00
#include <QVector>
#include <QVariant>
#include <QDebug>
#include <QDir>
#include <QColor>
#include <QImage>
#include <QRgb>
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>
#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;
2017-09-16 12:21:23 +09:00
for (int i=0; i<10; ++i)
2020-07-15 20:37:30 +09:00
{
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 ) );
#else
image.fill( uint(qrand() % 16581375) );
#endif
2020-07-18 21:01:58 +09:00
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;
}
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;
}