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

testing image index

This commit is contained in:
Look Skyworker 2020-07-15 20:37:30 +09:00
parent dfeb703de2
commit a0e1f2d7aa
8 changed files with 37 additions and 12 deletions

View File

@ -41,7 +41,7 @@ public:
QVariant read(const CellReference &cell) const;
QVariant read(int row, int col) const;
bool insertImage(int row, int col, const QImage &image);
int insertImage(int row, int col, const QImage &image);
Chart *insertChart(int row, int col, const QSize &size);

View File

@ -85,6 +85,10 @@ protected:
QSharedPointer<Chart> m_chartFile;
int m_id;
public:
int getm_id();
protected:
// liufeij {{
void setObjectShape(const QImage &img); // liufeij

View File

@ -97,7 +97,7 @@ public:
Cell *cellAt(const CellReference &row_column) const;
Cell *cellAt(int row, int column) const;
bool insertImage(int row, int column, const QImage &image);
int insertImage(int row, int column, const QImage &image);
Chart *insertChart(int row, int column, const QSize &size);
bool mergeCells(const CellRange &range, const Format &format=Format());

View File

@ -641,11 +641,12 @@ QVariant Document::read(int row, int col) const
* Insert an \a image to current active worksheet at the position \a row, \a column
* Returns ture if success.
*/
bool Document::insertImage(int row, int column, const QImage &image)
int Document::insertImage(int row, int column, const QImage &image)
{
if (Worksheet *sheet = currentWorksheet())
return sheet->insertImage(row, column, image);
return false;
return 0;
}
/*!

View File

@ -821,6 +821,11 @@ void DrawingAnchor::saveXmlObjectPicture(QXmlStreamWriter &writer) const
writer.writeEndElement(); //xdr:pic
}
int DrawingAnchor::getm_id()
{
return (this->m_id);
}
void DrawingAnchor::saveXmlObjectShape(QXmlStreamWriter &writer) const
{
//{{ liufeijin

View File

@ -703,14 +703,19 @@ QList<QSharedPointer<MediaFile> > Workbook::mediaFiles() const
void Workbook::addMediaFile(QSharedPointer<MediaFile> media, bool force)
{
Q_D(Workbook);
if (!force) {
for (int i=0; i<d->mediaFiles.size(); ++i) {
if (d->mediaFiles[i]->hashKey() == media->hashKey()) {
if (!force)
{
for (int i=0; i<d->mediaFiles.size(); ++i)
{
if (d->mediaFiles[i]->hashKey() == media->hashKey())
{
media->setIndex(i);
return;
}
}
}
media->setIndex(d->mediaFiles.size());
d->mediaFiles.append(media);
}

View File

@ -1085,17 +1085,21 @@ bool Worksheet::addConditionalFormatting(const ConditionalFormatting &cf)
* Insert an \a image at the position \a row, \a column
* Returns true on success.
*/
bool Worksheet::insertImage(int row, int column, const QImage &image)
int Worksheet::insertImage(int row, int column, const QImage &image)
{
Q_D(Worksheet);
int imageIndex = 0;
if (image.isNull())
return false;
return imageIndex;
if (!d->drawing)
{
d->drawing = QSharedPointer<Drawing>(new Drawing(this, F_NewFromScratch));
}
DrawingOneCellAnchor *anchor = new DrawingOneCellAnchor(d->drawing.data(), DrawingAnchor::Picture);
DrawingOneCellAnchor* anchor = new DrawingOneCellAnchor(d->drawing.data(), DrawingAnchor::Picture);
/*
The size are expressed as English Metric Units (EMUs).
@ -1107,7 +1111,10 @@ bool Worksheet::insertImage(int row, int column, const QImage &image)
anchor->ext = QSize( int(image.width() * scaleX), int(image.height() * scaleY) );
anchor->setObjectPicture(image);
return true;
imageIndex = anchor->getm_id();
return imageIndex;
}
/*!

View File

@ -13,7 +13,10 @@ int image()
QImage image(40, 30, QImage::Format_RGB32);
image.fill(Qt::green);
for (int i=0; i<10; ++i)
xlsx.insertImage(10*i, 5, image);
{
int index = xlsx.insertImage( 10*i, 5, image );
qDebug() << " [image index] " << index;
}
xlsx.saveAs("image1.xlsx");
QXlsx::Document xlsx2("image1.xlsx");