File indexing completed on 2025-01-19 13:27:36
0001 /* 0002 * This file is part of Office 2007 Filters for Calligra 0003 * 0004 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 0005 * 0006 * Contact: Suresh Chande suresh.chande@nokia.com 0007 * 0008 * This library is free software; you can redistribute it and/or 0009 * modify it under the terms of the GNU Lesser General Public License 0010 * version 2.1 as published by the Free Software Foundation. 0011 * 0012 * This library is distributed in the hope that it will be useful, but 0013 * WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 * Lesser General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU Lesser General Public 0018 * License along with this library; if not, write to the Free Software 0019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 0020 * 02110-1301 USA 0021 * 0022 */ 0023 0024 #include "XlsxUtils.h" 0025 #include "XlsxXmlTableReader.h" 0026 0027 #define MSOOXML_CURRENT_CLASS XlsxXmlTableReader 0028 #define BIND_READ_CLASS MSOOXML_CURRENT_CLASS 0029 0030 #include <MsooXmlReader_p.h> 0031 #include <MsooXmlUtils.h> 0032 #include <MsooXmlSchemas.h> 0033 0034 XlsxXmlTableReaderContext::XlsxXmlTableReaderContext() 0035 : headerStyleIndex(-1), 0036 dataStyleIndex(-1), 0037 totalsRowIndex(-1), 0038 headerRowCount(1), 0039 totalsRowCount(1) 0040 { 0041 } 0042 0043 XlsxXmlTableReader::XlsxXmlTableReader(KoOdfWriters *writers) 0044 : MSOOXML::MsooXmlCommonReader(writers), m_context(0) 0045 { 0046 } 0047 0048 XlsxXmlTableReader::~XlsxXmlTableReader() 0049 { 0050 } 0051 0052 KoFilter::ConversionStatus XlsxXmlTableReader::read(MSOOXML::MsooXmlReaderContext* context) 0053 { 0054 m_context = dynamic_cast<XlsxXmlTableReaderContext*>(context); 0055 Q_ASSERT(m_context); 0056 0057 readNext(); 0058 if (!isStartDocument()) { 0059 return KoFilter::WrongFormat; 0060 } 0061 0062 readNext(); 0063 qCDebug(lcXlsxImport) << *this << namespaceUri(); 0064 0065 if (!expectEl("table")) { 0066 return KoFilter::WrongFormat; 0067 } 0068 if (!expectNS(MSOOXML::Schemas::spreadsheetml)) { 0069 return KoFilter::WrongFormat; 0070 } 0071 0072 QXmlStreamNamespaceDeclarations namespaces(namespaceDeclarations()); 0073 for (int i = 0; i < namespaces.count(); i++) { 0074 qCDebug(lcXlsxImport) << "NS prefix:" << namespaces[i].prefix() << "uri:" << namespaces[i].namespaceUri(); 0075 } 0076 //! @todo find out whether the namespace returned by namespaceUri() 0077 //! is exactly the same ref as the element of namespaceDeclarations() 0078 if (!namespaces.contains(QXmlStreamNamespaceDeclaration(QString(), MSOOXML::Schemas::spreadsheetml))) { 0079 raiseError(i18n("Namespace \"%1\" not found", QLatin1String(MSOOXML::Schemas::spreadsheetml))); 0080 return KoFilter::WrongFormat; 0081 } 0082 //! @todo expect other namespaces too... 0083 0084 TRY_READ(table) 0085 0086 qCDebug(lcXlsxImport) << "===========finished============"; 0087 return KoFilter::OK; 0088 } 0089 0090 #undef CURRENT_EL 0091 #define CURRENT_EL table 0092 /* 0093 Parent elements: 0094 - [done] root element 0095 0096 Child elements: 0097 - autoFilter (AutoFilter Settings) §18.3.1.2 0098 - extLst (Future Feature Data Storage Area) §18.2.10 0099 - sortState (Sort State) §18.3.1.92 0100 - tableColumns (Table Columns) §18.5.1.4 0101 - tableStyleInfo (Table Style) §18.5.1.5 0102 0103 */ 0104 KoFilter::ConversionStatus XlsxXmlTableReader::read_table() 0105 { 0106 READ_PROLOGUE 0107 0108 const QXmlStreamAttributes attrs(attributes()); 0109 TRY_READ_ATTR_WITHOUT_NS(ref) 0110 TRY_READ_ATTR_WITHOUT_NS(headerRowDxfId) 0111 TRY_READ_ATTR_WITHOUT_NS(dataDxfId) 0112 TRY_READ_ATTR_WITHOUT_NS(totalsRowDxfId) 0113 TRY_READ_ATTR_WITHOUT_NS(totalsRowCount) 0114 TRY_READ_ATTR_WITHOUT_NS(headerRowCount) 0115 0116 m_context->referenceArea = ref; 0117 m_context->headerStyleIndex = headerRowDxfId.toInt(); 0118 m_context->dataStyleIndex = dataDxfId.toInt(); 0119 m_context->totalsRowIndex = totalsRowDxfId.toInt(); 0120 0121 if (!totalsRowCount.isEmpty()) { 0122 m_context->totalsRowCount = totalsRowCount.toInt(); 0123 } 0124 if (!headerRowCount.isEmpty()) { 0125 m_context->headerRowCount = headerRowCount.toInt(); 0126 } 0127 0128 // TODO: Read all, it should be possible to reference the table with formulas from 0129 // worksheets maybe through the context 0130 0131 while (!atEnd()) { 0132 readNext(); 0133 BREAK_IF_END_OF(CURRENT_EL) 0134 if (isStartElement()) { 0135 } 0136 } 0137 READ_EPILOGUE 0138 }