From 3192b808a283f8eb18c97b9a087bf085054e9bb0 Mon Sep 17 00:00:00 2001 From: hxbb00 Date: Mon, 29 Jul 2024 12:01:43 +0800 Subject: [PATCH] fix: workbook.xml.rels with absolute path https://github.com/QtExcel/QXlsx/issues/310 --- QXlsx/source/xlsxworkbook.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/QXlsx/source/xlsxworkbook.cpp b/QXlsx/source/xlsxworkbook.cpp index 1a2fdca..b183b37 100644 --- a/QXlsx/source/xlsxworkbook.cpp +++ b/QXlsx/source/xlsxworkbook.cpp @@ -607,15 +607,21 @@ bool Workbook::loadFromXmlFile(QIODevice *device) AbstractSheet *sheet = addSheet(name, sheetId, type); sheet->setSheetState(state); - QString strFilePath = filePath(); + if (relationship.target.startsWith("/")) { + QString fullPath = QDir::cleanPath(relationship.target.mid(1)); - // const QString fullPath = QDir::cleanPath(splitPath(strFilePath).constFirst() + - // QLatin1String("/") + relationship.target); - const auto parts = splitPath(strFilePath); - QString fullPath = - QDir::cleanPath(parts.first() + QLatin1String("/") + relationship.target); - - sheet->setFilePath(fullPath); + sheet->setFilePath(fullPath); + }else{ + QString strFilePath = filePath(); + + // const QString fullPath = QDir::cleanPath(splitPath(strFilePath).constFirst() + + // QLatin1String("/") + relationship.target); + const auto parts = splitPath(strFilePath); + QString fullPath = + QDir::cleanPath(parts.first() + QLatin1String("/") + relationship.target); + + sheet->setFilePath(fullPath); + } } else if (reader.name() == QLatin1String("workbookPr")) { QXmlStreamAttributes attrs = reader.attributes(); if (attrs.hasAttribute(QLatin1String("date1904")))