File indexing completed on 2025-02-16 10:54:11
0001 /* 0002 * This file is part of Office 2007 Filters for Calligra 0003 * 0004 * SPDX-FileCopyrightText: 2010 Nokia Corporation and /or its subsidiary(-ies). 0005 * 0006 * Contact: Suresh Chande suresh.chande@nokia.com 0007 * 0008 * SPDX-License-Identifier: LGPL-2.1-only 0009 * 0010 */ 0011 0012 #include "XlsxUtils.h" 0013 #include "XlsxXmlTableReader.h" 0014 0015 #define MSOOXML_CURRENT_CLASS XlsxXmlTableReader 0016 #define BIND_READ_CLASS MSOOXML_CURRENT_CLASS 0017 0018 #include <MsooXmlReader_p.h> 0019 #include <MsooXmlUtils.h> 0020 #include <MsooXmlSchemas.h> 0021 0022 XlsxXmlTableReaderContext::XlsxXmlTableReaderContext() 0023 : headerStyleIndex(-1), 0024 dataStyleIndex(-1), 0025 totalsRowIndex(-1), 0026 headerRowCount(1), 0027 totalsRowCount(1) 0028 { 0029 } 0030 0031 XlsxXmlTableReader::XlsxXmlTableReader(KoOdfWriters *writers) 0032 : MSOOXML::MsooXmlCommonReader(writers), m_context(0) 0033 { 0034 } 0035 0036 XlsxXmlTableReader::~XlsxXmlTableReader() 0037 { 0038 } 0039 0040 KoFilter::ConversionStatus XlsxXmlTableReader::read(MSOOXML::MsooXmlReaderContext* context) 0041 { 0042 m_context = dynamic_cast<XlsxXmlTableReaderContext*>(context); 0043 Q_ASSERT(m_context); 0044 0045 readNext(); 0046 if (!isStartDocument()) { 0047 return KoFilter::WrongFormat; 0048 } 0049 0050 readNext(); 0051 qCDebug(lcXlsxImport) << *this << namespaceUri(); 0052 0053 if (!expectEl("table")) { 0054 return KoFilter::WrongFormat; 0055 } 0056 if (!expectNS(MSOOXML::Schemas::spreadsheetml)) { 0057 return KoFilter::WrongFormat; 0058 } 0059 0060 QXmlStreamNamespaceDeclarations namespaces(namespaceDeclarations()); 0061 for (int i = 0; i < namespaces.count(); i++) { 0062 qCDebug(lcXlsxImport) << "NS prefix:" << namespaces[i].prefix() << "uri:" << namespaces[i].namespaceUri(); 0063 } 0064 //! @todo find out whether the namespace returned by namespaceUri() 0065 //! is exactly the same ref as the element of namespaceDeclarations() 0066 if (!namespaces.contains(QXmlStreamNamespaceDeclaration(QString(), MSOOXML::Schemas::spreadsheetml))) { 0067 raiseError(i18n("Namespace \"%1\" not found", QLatin1String(MSOOXML::Schemas::spreadsheetml))); 0068 return KoFilter::WrongFormat; 0069 } 0070 //! @todo expect other namespaces too... 0071 0072 TRY_READ(table) 0073 0074 qCDebug(lcXlsxImport) << "===========finished============"; 0075 return KoFilter::OK; 0076 } 0077 0078 #undef CURRENT_EL 0079 #define CURRENT_EL table 0080 /* 0081 Parent elements: 0082 - [done] root element 0083 0084 Child elements: 0085 - autoFilter (AutoFilter Settings) §18.3.1.2 0086 - extLst (Future Feature Data Storage Area) §18.2.10 0087 - sortState (Sort State) §18.3.1.92 0088 - tableColumns (Table Columns) §18.5.1.4 0089 - tableStyleInfo (Table Style) §18.5.1.5 0090 0091 */ 0092 KoFilter::ConversionStatus XlsxXmlTableReader::read_table() 0093 { 0094 READ_PROLOGUE 0095 0096 const QXmlStreamAttributes attrs(attributes()); 0097 TRY_READ_ATTR_WITHOUT_NS(ref) 0098 TRY_READ_ATTR_WITHOUT_NS(headerRowDxfId) 0099 TRY_READ_ATTR_WITHOUT_NS(dataDxfId) 0100 TRY_READ_ATTR_WITHOUT_NS(totalsRowDxfId) 0101 TRY_READ_ATTR_WITHOUT_NS(totalsRowCount) 0102 TRY_READ_ATTR_WITHOUT_NS(headerRowCount) 0103 0104 m_context->referenceArea = ref; 0105 m_context->headerStyleIndex = headerRowDxfId.toInt(); 0106 m_context->dataStyleIndex = dataDxfId.toInt(); 0107 m_context->totalsRowIndex = totalsRowDxfId.toInt(); 0108 0109 if (!totalsRowCount.isEmpty()) { 0110 m_context->totalsRowCount = totalsRowCount.toInt(); 0111 } 0112 if (!headerRowCount.isEmpty()) { 0113 m_context->headerRowCount = headerRowCount.toInt(); 0114 } 0115 0116 // TODO: Read all, it should be possible to reference the table with formulas from 0117 // worksheets maybe through the context 0118 0119 while (!atEnd()) { 0120 readNext(); 0121 BREAK_IF_END_OF(CURRENT_EL) 0122 if (isStartElement()) { 0123 } 0124 } 0125 READ_EPILOGUE 0126 }