Qt从Excel读取图片

时间:2019-02-26 03:13:00

标签: excel qt

每个人。现在,我需要使用Qt读取excel文件,并且单元格中有一些图片。我按照以下步骤编写了这些代码。

QAxObject *pExcel = new QAxObject("Excel.Application");    
if (pExcel == NULL || pExcel->isNull())
{
    return;
}
pExcel->dynamicCall("SetVisible(bool)", false);
QAxObject *pWorkbooks = pExcel->querySubObject("WorkBooks");
if (pWorkbooks == NULL || pWorkbooks->isNull())
{
    delete pExcel;
    pExcel = nullptr;
    return;
}
QAxObject *pWorkbook = pWorkbooks->querySubObject("Open(QString&)", qstrExcelPath);
if (pWorkbook == NULL || pWorkbook->isNull())
{
    delete pExcel;
    pExcel = nullptr;
    return;
}
QAxObject *pWorksheets = pWorkbook->querySubObject("WorkSheets");
if (pWorksheets == NULL || pWorksheets->isNull())
{
    delete pExcel;
    pExcel = nullptr;
    return;
}
QAxObject *pWorksheet = pWorksheets->querySubObject("Item(int)", 1);
if (pWorksheet == NULL || pWorksheet->isNull())
{
    delete pExcel;
    pExcel = nullptr;
    return;
}

QAxObject *pUsedRange = pWorksheet->querySubObject("UsedRange");
if (NULL == pUsedRange || pUsedRange->isNull())
{
    delete pExcel;
    pExcel = nullptr;
    return;
}

QVariant varExcelInfo = pUsedRange->dynamicCall("Value");

varExcelInfo可以正确读取字符串,但不能读取图片。如何从Excel文件读取图片?谢谢。

1 个答案:

答案 0 :(得分:0)

图片存储在Shape属性的Worksheet.Shapes对象中。

我看不到直接读取图像文件的方法,但是您可以使用Shape.CopyPicture方法通过剪贴板将其复制到剪贴板上;然后使用Qt QClipboard::image函数将图像复制到QImage中。