| 170 | } |
| 171 | |
| 172 | bool DocumentPrivate::loadPackage(QIODevice *device) |
| 173 | { |
| 174 | Q_Q(Document); |
| 175 | ZipReader zipReader(device); |
| 176 | QStringList filePaths = zipReader.filePaths(); |
| 177 | |
| 178 | //Load the Content_Types file |
| 179 | if (!filePaths.contains(QLatin1String("[Content_Types].xml"))) |
| 180 | return false; |
| 181 | contentTypes = std::make_shared<ContentTypes>(ContentTypes::F_LoadFromExists); |
| 182 | contentTypes->loadFromXmlData(zipReader.fileData(QStringLiteral("[Content_Types].xml"))); |
| 183 | |
| 184 | //Load root rels file |
| 185 | if (!filePaths.contains(QLatin1String("_rels/.rels"))) |
| 186 | return false; |
| 187 | Relationships rootRels; |
| 188 | rootRels.loadFromXmlData(zipReader.fileData(QStringLiteral("_rels/.rels"))); |
| 189 | |
| 190 | //load core property |
| 191 | QList<XlsxRelationship> rels_core = rootRels.packageRelationships(QStringLiteral("/metadata/core-properties")); |
| 192 | if (!rels_core.isEmpty()) { |
| 193 | //Get the core property file name if it exists. |
| 194 | //In normal case, this should be "docProps/core.xml" |
| 195 | QString docPropsCore_Name = rels_core[0].target; |
| 196 | |
| 197 | DocPropsCore props(DocPropsCore::F_LoadFromExists); |
| 198 | props.loadFromXmlData(zipReader.fileData(docPropsCore_Name)); |
| 199 | const auto propNames = props.propertyNames(); |
| 200 | for (const QString &name : propNames) |
| 201 | q->setDocumentProperty(name, props.property(name)); |
| 202 | } |
| 203 | |
| 204 | //load app property |
| 205 | QList<XlsxRelationship> rels_app = rootRels.documentRelationships(QStringLiteral("/extended-properties")); |
| 206 | if (!rels_app.isEmpty()) { |
| 207 | //Get the app property file name if it exists. |
| 208 | //In normal case, this should be "docProps/app.xml" |
| 209 | QString docPropsApp_Name = rels_app[0].target; |
| 210 | |
| 211 | DocPropsApp props(DocPropsApp::F_LoadFromExists); |
| 212 | props.loadFromXmlData(zipReader.fileData(docPropsApp_Name)); |
| 213 | const auto propNames = props.propertyNames(); |
| 214 | for (const QString &name : propNames) |
| 215 | q->setDocumentProperty(name, props.property(name)); |
| 216 | } |
| 217 | |
| 218 | //load workbook now, Get the workbook file path from the root rels file |
| 219 | //In normal case, this should be "xl/workbook.xml" |
| 220 | workbook = QSharedPointer<Workbook>(new Workbook(Workbook::F_LoadFromExists)); |
| 221 | QList<XlsxRelationship> rels_xl = rootRels.documentRelationships(QStringLiteral("/officeDocument")); |
| 222 | if (rels_xl.isEmpty()) |
| 223 | return false; |
| 224 | const QString xlworkbook_Path = rels_xl[0].target; |
| 225 | const auto parts = splitPath(xlworkbook_Path); |
| 226 | const QString xlworkbook_Dir = parts.first(); |
| 227 | const QString relFilePath = getRelFilePath(xlworkbook_Path); |
| 228 | |
| 229 | workbook->relationships()->loadFromXmlData( zipReader.fileData(relFilePath) ); |
no test coverage detected