wps里面有一个接口是AddPicture他可以向文档插入图片你用qt写一个函数打开文件夹选择图片插入文档
下面是一个可以打开文件夹选择图片并插入到文档的示例函数:
void insertPictureToDoc(QAxObject* doc)
{
QString filePath = QFileDialog::getOpenFileName(nullptr, "Select Image", "", "Images (*.png *.xpm *.jpg *.bmp)");
if (!filePath.isEmpty()) {
QAxObject* selection = doc->querySubObject("Selection");
QAxObject* shapes = selection->querySubObject("InlineShapes");
QAxObject* shape = shapes->querySubObject("AddPicture(const QString&)", filePath);
// set picture width and height
shape->setProperty("Width", 200);
shape->setProperty("Height", 200);
// move cursor to the end of the picture
QAxObject* range = shape->querySubObject("Range");
QAxObject* endPos = range->querySubObject("End");
selection->setProperty("Start", endPos->property("Start"));
selection->setProperty("End", endPos->property("End"));
}
}
这个函数会打开文件选择对话框,让用户选择一个图片文件。如果用户选择了文件,那么就会创建一个新的图片对象,并将它插入到文档中。在这个示例中,我们设置了图片的宽度和高度,并将光标移动到图片的末尾,以便用户可以继续编辑文档
原文地址: https://www.cveoy.top/t/topic/huhj 著作权归作者所有。请勿转载和采集!