From 2652fb4e65d187720f139e61c308435e3980c26a Mon Sep 17 00:00:00 2001 From: Oleg Korshul Date: Fri, 14 Mar 2025 11:19:14 +0300 Subject: [PATCH 1/7] Fix bug 73507 --- DesktopEditor/fontengine/TextShaper.cpp | 2 +- DesktopEditor/fontengine/TextShaper_p.h | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/DesktopEditor/fontengine/TextShaper.cpp b/DesktopEditor/fontengine/TextShaper.cpp index 6efcb547ed..0b2025e5f8 100644 --- a/DesktopEditor/fontengine/TextShaper.cpp +++ b/DesktopEditor/fontengine/TextShaper.cpp @@ -451,7 +451,7 @@ namespace NSShaper CheckUnicodeFaceName(face, family_name, family_name_len); unsigned int nLen1 = (unsigned int)family_name_len; - unsigned int nLen2 = (unsigned int)strlen(face->style_name); + unsigned int nLen2 = (unsigned int)((face->style_name != NULL) ? strlen(face->style_name) : 0); unsigned int nLen = 28 + nLen1 + 1 + nLen2 + 1 + 1 + (int)face->num_fixed_sizes; diff --git a/DesktopEditor/fontengine/TextShaper_p.h b/DesktopEditor/fontengine/TextShaper_p.h index 27ec01cdf9..3c8f0933f1 100644 --- a/DesktopEditor/fontengine/TextShaper_p.h +++ b/DesktopEditor/fontengine/TextShaper_p.h @@ -94,11 +94,14 @@ void CheckUnicodeFaceName(FT_Face pFace, int*& UName, unsigned int& ULen) bool isBadASCII = false; unsigned int face_name_len = 0; - while ('\0' != face_name[face_name_len]) + if (NULL != face_name) { - if ('?' == face_name[face_name_len]) - isBadASCII = true; - ++face_name_len; + while ('\0' != face_name[face_name_len]) + { + if ('?' == face_name[face_name_len]) + isBadASCII = true; + ++face_name_len; + } } if (face_name_len > 6 && From 1346f56d673572e2db8ca9d926dc1f26f3a3149b Mon Sep 17 00:00:00 2001 From: Green Date: Fri, 14 Mar 2025 17:00:37 +0300 Subject: [PATCH 2/7] Fix bug #73487 --- HwpFile/HwpDoc/Common/XMLNode.h | 1 + HwpFile/HwpDoc/Common/XMLReader.cpp | 47 +++++++++++++------ .../HWPElements/HWPRecordBorderFill.cpp | 9 +--- .../HwpDoc/HWPElements/HWPRecordBullet.cpp | 12 ++++- 4 files changed, 46 insertions(+), 23 deletions(-) diff --git a/HwpFile/HwpDoc/Common/XMLNode.h b/HwpFile/HwpDoc/Common/XMLNode.h index 4070946113..518ea10488 100644 --- a/HwpFile/HwpDoc/Common/XMLNode.h +++ b/HwpFile/HwpDoc/Common/XMLNode.h @@ -19,6 +19,7 @@ public: }; int ConvertWidthToHWP(const std::wstring& wsValue); +int ConvertHexToInt(const std::string& wsValue, const int& _default = 0x00000000); } #endif // XMLNODEH_H diff --git a/HwpFile/HwpDoc/Common/XMLReader.cpp b/HwpFile/HwpDoc/Common/XMLReader.cpp index 8b022f95b5..82d133855b 100644 --- a/HwpFile/HwpDoc/Common/XMLReader.cpp +++ b/HwpFile/HwpDoc/Common/XMLReader.cpp @@ -17,20 +17,7 @@ bool CXMLNode::GetAttributeBool(const std::wstring& wsName) int CXMLNode::GetAttributeColor(const std::wstring& wsName, const int& _default) { - std::wstring sColor = XmlUtils::CXmlNode::GetAttribute(wsName); - - if (L"none" != sColor) - { - if (L'#' == sColor.front()) - sColor.erase(0, 1); - - if (sColor.length() < 6) - return _default; - - return std::stoi(sColor.substr(0, 6), nullptr, 16); - } - - return _default; + return ConvertHexToInt(XmlUtils::CXmlNode::GetAttributeA(wsName), _default); } CXMLNode CXMLNode::GetChild(const std::wstring& wsName) @@ -98,4 +85,36 @@ int ConvertWidthToHWP(const std::wstring& wsValue) return 0; } + +int ConvertHexToInt(const std::string& wsValue, const int& _default) +{ + if (wsValue.empty() || "none" == wsValue) + return _default; + + std::string::const_iterator itStart = wsValue.cbegin(); + + if ('#' == *itStart) + ++itStart; + + if (wsValue.cend() - itStart < 6) + return _default; + + itStart = wsValue.cend() - 6; + + int nResult = 0; + + while (itStart != wsValue.cend()) + { + if ('0' <= *itStart && *itStart <= '9') + nResult = (nResult << 4) | (*itStart++ - '0'); + else if ('A' <= *itStart && *itStart <= 'F') + nResult = (nResult << 4) | (*itStart++ - 'A' + 10); + else if ('a' <= *itStart && *itStart <= 'f') + nResult = (nResult << 4) | (*itStart++ - 'a' + 10); + else + return _default; + } + + return nResult; +} } diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordBorderFill.cpp b/HwpFile/HwpDoc/HWPElements/HWPRecordBorderFill.cpp index 2569ee8618..503586237b 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordBorderFill.cpp +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordBorderFill.cpp @@ -62,12 +62,7 @@ EColorFillPattern GetColorFillPattern(int nPattern) void TBorder::ReadFromNode(CXMLNode& oNode) { m_eStyle = GetLineStyle2(oNode.GetAttribute(L"type")); - - HWP_STRING sColor = std::regex_replace(oNode.GetAttribute(L"color"), std::wregex(L"^#([0-9A-Fa-f]+)$"), L"$1"); - - if (L"none" != sColor) - m_nColor = std::stoi(sColor, 0, 16); - + m_nColor = oNode.GetAttributeColor(L"color"); m_chWidth = (HWP_BYTE)ConvertWidthToHWP(oNode.GetAttribute(L"width")); } @@ -199,7 +194,7 @@ void CFill::ReadGradation(CXMLNode& oNode) m_arColors.resize(arChilds.size()); for (unsigned int unIndex = 0; unIndex < arChilds.size(); ++unIndex) - m_arColors[unIndex] = std::stoi(std::regex_replace(arChilds[unIndex].GetText(), std::wregex(L"\\D"), L""), 0, 16); + m_arColors[unIndex] = ConvertHexToInt(arChilds[unIndex].GetTextA()); } void CFill::ReadImgBrush(CXMLNode& oNode) diff --git a/HwpFile/HwpDoc/HWPElements/HWPRecordBullet.cpp b/HwpFile/HwpDoc/HWPElements/HWPRecordBullet.cpp index 877ebae315..91ee5db3a3 100644 --- a/HwpFile/HwpDoc/HWPElements/HWPRecordBullet.cpp +++ b/HwpFile/HwpDoc/HWPElements/HWPRecordBullet.cpp @@ -48,8 +48,16 @@ CHWPRecordBullet::CHWPRecordBullet(CHWPDocInfo& oDocInfo, int nTagNum, int nLeve CHWPRecordBullet::CHWPRecordBullet(CHWPDocInfo& oDocInfo, CXMLNode& oNode, int nVersion) : CHWPRecord(EHWPTag::HWPTAG_BULLET, 0, 0), m_pParent(&oDocInfo) { - m_chBulletChar = oNode.GetAttribute(L"char").at(0); - m_chCheckBulletChar = oNode.GetAttribute(L"checkedChar").at(0); + std::wstring wsAttributeValue = oNode.GetAttribute(L"char"); + + if (!wsAttributeValue.empty()) + m_chBulletChar = wsAttributeValue.at(0); + + wsAttributeValue = oNode.GetAttribute(L"checkedChar"); + + if (!wsAttributeValue.empty()) + m_chCheckBulletChar = wsAttributeValue.at(0); + m_nBulletImage = oNode.GetAttributeInt(L"useImage"); for (CXMLNode& oChild : oNode.GetChilds()) From 6fe0f2828e9b796b90d0b850dad624f9845ba697 Mon Sep 17 00:00:00 2001 From: Viktor Andreev Date: Fri, 14 Mar 2025 21:53:47 +0600 Subject: [PATCH 3/7] Fix bug #73467 --- OOXML/Common/SimpleTypes_Spreadsheet.cpp | 2 +- OOXML/XlsxFormat/Worksheets/SheetData.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/OOXML/Common/SimpleTypes_Spreadsheet.cpp b/OOXML/Common/SimpleTypes_Spreadsheet.cpp index 24d91f3e28..fb2b990041 100644 --- a/OOXML/Common/SimpleTypes_Spreadsheet.cpp +++ b/OOXML/Common/SimpleTypes_Spreadsheet.cpp @@ -589,7 +589,7 @@ namespace SimpleTypes this->m_eValue = underlineDouble; else if(L"doubleAccounting" == sValue) this->m_eValue = underlineDoubleAccounting; - else if(L"none" == sValue) + else if(L"none" == sValue || L"0" == sValue) this->m_eValue = underlineNone; else if(L"single" == sValue) this->m_eValue = underlineSingle; diff --git a/OOXML/XlsxFormat/Worksheets/SheetData.cpp b/OOXML/XlsxFormat/Worksheets/SheetData.cpp index 9a710afbef..f898cee414 100644 --- a/OOXML/XlsxFormat/Worksheets/SheetData.cpp +++ b/OOXML/XlsxFormat/Worksheets/SheetData.cpp @@ -1158,7 +1158,7 @@ namespace OOX ColumnRef = static_cast(BinFmla.rgcb.getPtgs().back().get())->col; if(!SharedFormulasRef::sharedRefsLocations) SharedFormulasRef::sharedRefsLocations = std::unique_ptr>(new std::map<_UINT32, XLS::CellRef>); - m_oSi = (unsigned int)SharedFormulasRef::sharedRefsLocations->size() - 1; + m_oSi = (unsigned int)SharedFormulasRef::sharedRefsLocations->size(); SharedFormulasRef::sharedRefsLocations->emplace(m_oSi->GetValue(), XLS::CellRef(rowRef, ColumnRef, true, true)); } @@ -4369,7 +4369,7 @@ namespace OOX } bool CRow::compressCell(CCell* pCell) { - if(!pCell->m_oValue.IsInit() && !m_arrItems.empty()) + if(!pCell->m_oValue.IsInit() && !pCell->m_oFormula.IsInit() && !m_arrItems.empty()) { auto prevCell = m_arrItems.back(); if(!prevCell->m_oRepeated.IsInit()) From 4f4f61bb1918e0a0a6d79827227ae5129443564f Mon Sep 17 00:00:00 2001 From: Green Date: Sat, 15 Mar 2025 01:04:27 +0300 Subject: [PATCH 4/7] Fix bug #73483 --- Common/OfficeFileFormatChecker2.cpp | 248 +++++++++++++++++++++++----- 1 file changed, 206 insertions(+), 42 deletions(-) diff --git a/Common/OfficeFileFormatChecker2.cpp b/Common/OfficeFileFormatChecker2.cpp index e1ea7b2d88..695efb0628 100644 --- a/Common/OfficeFileFormatChecker2.cpp +++ b/Common/OfficeFileFormatChecker2.cpp @@ -1159,58 +1159,222 @@ bool COfficeFileFormatChecker::isOnlyOfficeFormatFile(const std::wstring &fileNa } return false; } -bool COfficeFileFormatChecker::isMacFormatFile(const std::wstring& fileName) + +struct TIWAField +{ + size_t m_unStart; + size_t m_unEnd; + unsigned m_uIndex; + unsigned m_unWireType; + uint64_t m_oValue; +}; + +bool ReadUVar(BYTE* pBuffer, size_t unEndPos, size_t& unPos, uint64_t& unValue) +{ + std::vector arBytes; + arBytes.reserve(8); + + unValue = 0; + + bool bNext = true; + while (unPos < unEndPos && bNext) + { + const unsigned char c = pBuffer[unPos++]; + arBytes.push_back((unsigned char)(c & ~0x80)); + bNext = c & 0x80; + } + + if (bNext && unPos == unEndPos) + return false; + + for (std::vector::const_reverse_iterator it = arBytes.rbegin(); it != arBytes.rend(); ++it) + { + if (std::numeric_limits::max() >> 7 < unValue || + std::numeric_limits::max() - (unValue << 7) < *it) // overflow + return false; + + unValue = (unValue << 7) + *it; + } + + return true; +} + +bool ReadIWAField(BYTE* pBuffer, size_t unEndPos, size_t& unPos, TIWAField& oIWAField) +{ + if (NULL == pBuffer || unPos + 2 > unEndPos) + return false; + + unsigned uSpec; + + uSpec = (unsigned)pBuffer[unPos++]; + oIWAField.m_unWireType = uSpec & 0x7; + + oIWAField.m_unStart = unPos; + + switch (oIWAField.m_unWireType) + { + case 0: + { + if (!ReadUVar(pBuffer, unEndPos, unPos, oIWAField.m_oValue)) + return false; + + break; + } + case 1: + { + unPos += 4; + break; + } + case 2: + { + uint64_t unLen; + if (!ReadUVar(pBuffer, unEndPos, unPos, unLen) || unPos + unLen > unEndPos) + return false; + + oIWAField.m_unStart = unPos; + unPos += unLen; + break; + } + case 5: + { + unPos += 2; + break; + } + default: + return false; + } + + oIWAField.m_unEnd = unPos; + oIWAField.m_uIndex = uSpec >> 3; + + return true; +} + +bool DetectIWorkFormat(const std::wstring& fileName, int &nType) { COfficeUtils OfficeUtils(NULL); - ULONG nBufferSize = 0; + ULONG unSize = 0; BYTE* pBuffer = NULL; - HRESULT hresult = OfficeUtils.LoadFileFromArchive(fileName, L"Index/Document.iwa", &pBuffer, nBufferSize); - if (hresult == S_OK && pBuffer != NULL) + HRESULT hresult = OfficeUtils.LoadFileFromArchive(fileName, L"Index/Document.iwa", &pBuffer, unSize); + + if (hresult != S_OK || NULL == pBuffer) + return false; + + #define CLEAR_BUFFER_AND_RETURN(return_value)\ + do{\ + delete[] pBuffer;\ + return return_value;\ + }while(false) + + if (unSize < 13) + CLEAR_BUFFER_AND_RETURN(false); + + size_t uPos = 6; + + for (; uPos < 12; ++uPos) { - nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_PAGES; - - delete[] pBuffer; - pBuffer = NULL; - - hresult = OfficeUtils.LoadFileFromArchive(fileName, L"Index/Slide.iwa", &pBuffer, nBufferSize); - if (hresult == S_OK && pBuffer != NULL) + if (0x08 == pBuffer[uPos] && 0x01 == pBuffer[uPos + 1]) { - delete[] pBuffer; - pBuffer = NULL; - - nFileType = AVS_OFFICESTUDIO_FILE_PRESENTATION_KEY; - return true; + --uPos; + break; } - hresult = OfficeUtils.LoadFileFromArchive(fileName, L"Index/Tables/DataList.iwa", &pBuffer, nBufferSize); - if (hresult == S_OK && pBuffer != NULL) - { - delete[] pBuffer; - pBuffer = NULL; - - nFileType = AVS_OFFICESTUDIO_FILE_SPREADSHEET_NUMBERS; - return true; - } - std::wstring::size_type nExtPos = fileName.rfind(L'.'); - std::wstring sExt = L"unknown"; - - if (nExtPos != std::wstring::npos) - sExt = fileName.substr(nExtPos); - - std::transform(sExt.begin(), sExt.end(), sExt.begin(), tolower); - - if (0 == sExt.compare(L".pages")) - nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_PAGES; - else if (0 == sExt.compare(L".numbers")) - nFileType = AVS_OFFICESTUDIO_FILE_SPREADSHEET_NUMBERS; - else if (0 == sExt.compare(L".key")) - nFileType = AVS_OFFICESTUDIO_FILE_PRESENTATION_KEY; - - return true; } - return false; + + if (12 == uPos) + CLEAR_BUFFER_AND_RETURN(false); + + uint64_t unHeaderLen; + if (!ReadUVar(pBuffer, unSize, uPos, unHeaderLen)) + CLEAR_BUFFER_AND_RETURN(false); + + const size_t uStartPos = uPos; + + if (unHeaderLen < 8 || unSize < unHeaderLen + uStartPos) + CLEAR_BUFFER_AND_RETURN(false); + + uPos += 2; + + TIWAField oMessageField; + + if (!ReadIWAField(pBuffer, uStartPos + unHeaderLen, uPos, oMessageField) || 2 != oMessageField.m_unWireType || + 2 != oMessageField.m_uIndex) + CLEAR_BUFFER_AND_RETURN(false); + + size_t uSubPos = oMessageField.m_unStart; + TIWAField oField; + + if (!ReadIWAField(pBuffer, oMessageField.m_unEnd, uSubPos, oField) || 0 != oField.m_unWireType || + 1 != oField.m_uIndex) + CLEAR_BUFFER_AND_RETURN(false); + + switch (oField.m_oValue) + { + case 1: + { + uint32_t unDataLen = 0; + + TIWAField oTempField; + if (ReadIWAField(pBuffer, oMessageField.m_unEnd, uSubPos, oTempField) && + ReadIWAField(pBuffer, oMessageField.m_unEnd, uSubPos, oTempField) && 0 == oTempField.m_unWireType && + 3 == oTempField.m_uIndex) + unDataLen += oTempField.m_oValue; + + size_t unTempPos = uStartPos + unHeaderLen; + + // keynote: presentation ref in 2 + // number: sheet ref in 1 + if (ReadIWAField(pBuffer, uStartPos + unDataLen, unTempPos, oTempField) && + (2 != oTempField.m_unWireType || 1 != oTempField.m_uIndex || oTempField.m_unEnd - oTempField.m_unStart < 2)) + { + nType = AVS_OFFICESTUDIO_FILE_PRESENTATION_KEY; + CLEAR_BUFFER_AND_RETURN(true); + } + else if (ReadIWAField(pBuffer, uStartPos + unDataLen, unTempPos, oTempField) && + (2 != oTempField.m_unWireType || 2 != oTempField.m_uIndex || oTempField.m_unEnd - oTempField.m_unStart < 2)) + { + nType = AVS_OFFICESTUDIO_FILE_SPREADSHEET_NUMBERS; + CLEAR_BUFFER_AND_RETURN(true); + } + + break; + } + case 10000: + { + nType = AVS_OFFICESTUDIO_FILE_DOCUMENT_PAGES; + CLEAR_BUFFER_AND_RETURN(true); + } + } + + CLEAR_BUFFER_AND_RETURN(false); } + +bool COfficeFileFormatChecker::isMacFormatFile(const std::wstring& fileName) +{ + if (DetectIWorkFormat(fileName, nFileType)) + return true; + + std::wstring::size_type nExtPos = fileName.rfind(L'.'); + std::wstring sExt = L"unknown"; + + if (nExtPos != std::wstring::npos) + sExt = fileName.substr(nExtPos); + + std::transform(sExt.begin(), sExt.end(), sExt.begin(), tolower); + + if (0 == sExt.compare(L".pages")) + nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_PAGES; + else if (0 == sExt.compare(L".numbers")) + nFileType = AVS_OFFICESTUDIO_FILE_SPREADSHEET_NUMBERS; + else if (0 == sExt.compare(L".key")) + nFileType = AVS_OFFICESTUDIO_FILE_PRESENTATION_KEY; + else + return false; + + return true; +} + bool COfficeFileFormatChecker::isOpenOfficeFormatFile(const std::wstring &fileName, std::wstring &documentID) { documentID.clear(); From 2ab94263f2e2f91f448cfea05cf3e2af0450d33d Mon Sep 17 00:00:00 2001 From: Mikhail Lobotskiy Date: Mon, 17 Mar 2025 15:29:49 +0400 Subject: [PATCH 5/7] Remove `lib` directory --- .../doctrenderer/docbuilder.python/src/docbuilder.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DesktopEditor/doctrenderer/docbuilder.python/src/docbuilder.py b/DesktopEditor/doctrenderer/docbuilder.python/src/docbuilder.py index a09d1f4afd..bf8f6186a0 100644 --- a/DesktopEditor/doctrenderer/docbuilder.python/src/docbuilder.py +++ b/DesktopEditor/doctrenderer/docbuilder.python/src/docbuilder.py @@ -609,14 +609,14 @@ class FileTypes: PNG = _IMAGE_MASK + 0x0005 BMP = _IMAGE_MASK + 0x0008 -builder_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'lib') +builder_path = os.path.dirname(os.path.realpath(__file__)) _loadLibrary(builder_path) CDocBuilder.Initialize(builder_path) def registerLibrary(license_path): - docbuilder_bin = os.path.dirname(os.path.realpath(__file__)) + "/lib/docbuilder" + docbuilder_bin = os.path.join(builder_path, "docbuilder") if ("windows" == platform.system().lower()): docbuilder_bin += ".exe" - return subprocess.call([docbuilder_bin, "-register", license_path], stderr=subprocess.STDOUT, shell=True) + return subprocess.call([docbuilder_bin, "-register", license_path], stderr=subprocess.STDOUT, shell=True) atexit.register(CDocBuilder.Dispose) From 72ee82211d317069bf2dfdb3226d2c2ad8aa128d Mon Sep 17 00:00:00 2001 From: Mikhail Lobotskiy Date: Mon, 17 Mar 2025 15:36:03 +0400 Subject: [PATCH 6/7] Add note --- DesktopEditor/doctrenderer/docbuilder.python/src/docbuilder.py | 1 + 1 file changed, 1 insertion(+) diff --git a/DesktopEditor/doctrenderer/docbuilder.python/src/docbuilder.py b/DesktopEditor/doctrenderer/docbuilder.python/src/docbuilder.py index bf8f6186a0..b097c55a2e 100644 --- a/DesktopEditor/doctrenderer/docbuilder.python/src/docbuilder.py +++ b/DesktopEditor/doctrenderer/docbuilder.python/src/docbuilder.py @@ -609,6 +609,7 @@ class FileTypes: PNG = _IMAGE_MASK + 0x0005 BMP = _IMAGE_MASK + 0x0008 +# NOTE: do not change builder_path manually! builder_path = os.path.dirname(os.path.realpath(__file__)) _loadLibrary(builder_path) CDocBuilder.Initialize(builder_path) From 6a4ba5ec8d69e6ed31fc2bbd93d333c83fecb770 Mon Sep 17 00:00:00 2001 From: ElenaSubbotina Date: Wed, 19 Mar 2025 10:39:55 +0300 Subject: [PATCH 7/7] fix bug #73554 --- .../Sheets/Common/BinReaderWriterDefines.h | 12 +- OOXML/Binary/Sheets/Reader/BinaryWriter.cpp | 60 +- OOXML/Binary/Sheets/Reader/BinaryWriter.h | 2 + OOXML/Binary/Sheets/Writer/BinaryReader.cpp | 52 ++ OOXML/Binary/Sheets/Writer/BinaryReader.h | 1 + OOXML/Common/SimpleTypes_Spreadsheet.cpp | 20 + OOXML/Common/SimpleTypes_Spreadsheet.h | 7 + OOXML/DocxFormat/CustomXml.h | 2 - OOXML/DocxFormat/WritingElement.h | 12 +- .../Linux/DocxFormatLib/DocxFormatLib.pro | 6 +- .../Linux/DocxFormatLib/xlsx_format_logic.cpp | 1 + .../DocxFormatLib/DocxFormatLib.vcxproj | 2 + .../DocxFormatLib.vcxproj.filters | 6 + OOXML/XlsxFormat/FileFactory_Spreadsheet.cpp | 13 +- OOXML/XlsxFormat/FileTypes_Spreadsheet.cpp | 11 +- OOXML/XlsxFormat/FileTypes_Spreadsheet.h | 4 + OOXML/XlsxFormat/Table/Table.h | 210 +++++-- OOXML/XlsxFormat/Table/Tables.cpp | 505 +++++++++++++++- OOXML/XlsxFormat/Workbook/CustomsXml.cpp | 561 ++++++++++++++++++ OOXML/XlsxFormat/Workbook/CustomsXml.h | 179 ++++++ 20 files changed, 1610 insertions(+), 56 deletions(-) create mode 100644 OOXML/XlsxFormat/Workbook/CustomsXml.cpp create mode 100644 OOXML/XlsxFormat/Workbook/CustomsXml.h diff --git a/OOXML/Binary/Sheets/Common/BinReaderWriterDefines.h b/OOXML/Binary/Sheets/Common/BinReaderWriterDefines.h index 1b01b39012..20ec0466f5 100644 --- a/OOXML/Binary/Sheets/Common/BinReaderWriterDefines.h +++ b/OOXML/Binary/Sheets/Common/BinReaderWriterDefines.h @@ -238,7 +238,8 @@ namespace BinXlsxRW ExternalLinksAutoRefresh = 26, TimelineCaches = 27, TimelineCache = 28, - Metadata = 29 + Metadata = 29, + XmlMap = 30 };} namespace c_oSerWorkbookProtection {enum c_oSerWorkbookProtection{ AlgorithmName = 0, @@ -456,7 +457,7 @@ namespace BinXlsxRW TimelinesList = 48, Timelines = 49, Timeline = 50, - + TableSingleCells = 51 };} namespace c_oSerWorksheetProtection {enum c_oSerWorksheetPropTypes { @@ -1113,7 +1114,12 @@ namespace BinXlsxRW QueryTableFieldId = 11, TotalsRowCellStyle = 12, TotalsRowDxfId = 13, - UniqueName = 14 + UniqueName = 14, + XmlColumnPr = 15, + MapId = 16, + Xpath = 17, + Denormalized = 18, + XmlDataType = 19 };} namespace c_oSer_SortState{enum c_oSer_SortState { diff --git a/OOXML/Binary/Sheets/Reader/BinaryWriter.cpp b/OOXML/Binary/Sheets/Reader/BinaryWriter.cpp index 6b6534fb16..a6af8c4770 100644 --- a/OOXML/Binary/Sheets/Reader/BinaryWriter.cpp +++ b/OOXML/Binary/Sheets/Reader/BinaryWriter.cpp @@ -71,6 +71,8 @@ #include "../../../XlsxFormat/Styles/TableStyles.h" #include "../../../XlsxFormat/Timelines/Timeline.h" #include "../../../XlsxFormat/Workbook/Metadata.h" +#include "../../../XlsxFormat/Table/Table.h" +#include "../../../XlsxFormat/Workbook/CustomsXml.h" #include "../../../../DesktopEditor/common/Directory.h" #include "../../../../Common/OfficeFileFormatChecker.h" @@ -990,6 +992,12 @@ void BinaryTableWriter::WriteTableColumn(const OOX::Spreadsheet::CTableColumn& o m_oBcw.m_oStream.WriteBYTE(c_oSer_TableColumns::UniqueName); m_oBcw.m_oStream.WriteStringW(*oTableColumn.m_oUniqueName); } + if (oTableColumn.m_oXmlColumnPr.IsInit()) + { + nCurPos = m_oBcw.WriteItemStart(c_oSer_TableColumns::XmlColumnPr); + WriteTableXmlColumnPr(oTableColumn.m_oXmlColumnPr.get()); + m_oBcw.WriteItemEnd(nCurPos); + } } void BinaryTableWriter::WriteTableColumns(const OOX::Spreadsheet::CTableColumns& oTableColumns) { @@ -1001,15 +1009,43 @@ void BinaryTableWriter::WriteTableColumns(const OOX::Spreadsheet::CTableColumns& m_oBcw.WriteItemEnd(nCurPos); } } +void BinaryTableWriter::WriteTableXmlColumnPr(const OOX::Spreadsheet::CXmlColumnPr & oXmlColumnPr) +{ + if (oXmlColumnPr.mapId.IsInit()) + { + m_oBcw.m_oStream.WriteBYTE(c_oSer_TableColumns::MapId); + m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Long); + m_oBcw.m_oStream.WriteLONG(*oXmlColumnPr.mapId); + } + if (oXmlColumnPr.xpath.IsInit()) + { + m_oBcw.m_oStream.WriteBYTE(c_oSer_TableColumns::Xpath); + m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Variable); + m_oBcw.m_oStream.WriteStringW(*oXmlColumnPr.xpath); + } + if (oXmlColumnPr.denormalized.IsInit()) + { + m_oBcw.m_oStream.WriteBYTE(c_oSer_TableColumns::Denormalized); + m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Byte); + m_oBcw.m_oStream.WriteBOOL(*oXmlColumnPr.denormalized); + } + if (oXmlColumnPr.xmlDataType.IsInit()) + { + m_oBcw.m_oStream.WriteBYTE(c_oSer_TableColumns::XmlDataType); + m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Byte); + m_oBcw.m_oStream.WriteBYTE(oXmlColumnPr.xmlDataType->GetValue()); + } +} + void BinaryTableWriter::WriteTableStyleInfo(const OOX::Spreadsheet::CTableStyleInfo& oTableStyleInfo) { - if(oTableStyleInfo.m_oName.IsInit()) + if (oTableStyleInfo.m_oName.IsInit()) { m_oBcw.m_oStream.WriteBYTE(c_oSer_TableStyleInfo::Name); m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Variable); m_oBcw.m_oStream.WriteStringW(oTableStyleInfo.m_oName.get2()); } - if(oTableStyleInfo.m_oShowColumnStripes.IsInit()) + if (oTableStyleInfo.m_oShowColumnStripes.IsInit()) { m_oBcw.m_oStream.WriteBYTE(c_oSer_TableStyleInfo::ShowColumnStripes); m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Byte); @@ -2290,6 +2326,16 @@ void BinaryWorkbookTableWriter::WriteWorkbook(OOX::Spreadsheet::CWorkbook& workb WriteMetadata(pMetadataFile->m_oMetadata.GetPointer()); m_oBcw.WriteItemWithLengthEnd(nCurPos); } + pFile = workbook.Find(OOX::Spreadsheet::FileTypes::XmlMaps); + OOX::Spreadsheet::CXmlMapsFile* pXmlMapFile = dynamic_cast(pFile.GetPointer()); + if (pXmlMapFile) + { + nCurPos = m_oBcw.WriteItemStart(c_oSerWorkbookTypes::XmlMap); + m_oBcw.m_oStream.StartRecord(0); + pXmlMapFile->toPPTY(&m_oBcw.m_oStream); + m_oBcw.m_oStream.EndRecord(); + m_oBcw.WriteItemWithLengthEnd(nCurPos); + } } void BinaryWorkbookTableWriter::WriteFileSharing(const OOX::Spreadsheet::CFileSharing& fileSharing) { @@ -4787,6 +4833,16 @@ void BinaryWorksheetTableWriter::WriteWorksheet(OOX::Spreadsheet::CSheet* pSheet m_oBcw.WriteItemWithLengthEnd(tablePos); m_oBcw.WriteItemWithLengthEnd(nCurPos); } + pFile = oWorksheet.Find(OOX::Spreadsheet::FileTypes::TableSingleCells); + OOX::Spreadsheet::CTableSingleCellsFile* pTableSingleCells = dynamic_cast(pFile.GetPointer()); + if (pTableSingleCells) + { + nCurPos = m_oBcw.WriteItemStart(c_oSerWorksheetsTypes::TableSingleCells); + m_oBcw.m_oStream.StartRecord(0); + pTableSingleCells->toPPTY(&m_oBcw.m_oStream); + m_oBcw.m_oStream.EndRecord(); + m_oBcw.WriteItemWithLengthEnd(nCurPos); + } } void BinaryWorksheetTableWriter::WriteWorksheetProp(OOX::Spreadsheet::CSheet& oSheet) { diff --git a/OOXML/Binary/Sheets/Reader/BinaryWriter.h b/OOXML/Binary/Sheets/Reader/BinaryWriter.h index 558520db18..26b7f9d1e2 100644 --- a/OOXML/Binary/Sheets/Reader/BinaryWriter.h +++ b/OOXML/Binary/Sheets/Reader/BinaryWriter.h @@ -84,6 +84,7 @@ namespace OOX class CTimelineStyle; class CTimelineStyles; class CTimelineStyleElement; + class CXmlColumnPr; class CMetadata; class CFutureMetadata; @@ -138,6 +139,7 @@ namespace BinXlsxRW void WriteQueryTableField(const OOX::Spreadsheet::CQueryTableField& oQueryTableField); void WriteQueryTableDeletedFields(const OOX::Spreadsheet::CQueryTableDeletedFields& oQueryTableDeletedFields); void WriteQueryTableDeletedField(const OOX::Spreadsheet::CQueryTableDeletedField& oQueryTableDeletedField); + void WriteTableXmlColumnPr(const OOX::Spreadsheet::CXmlColumnPr & oXmlColumnPr); }; class BinaryStyleTableWriter { diff --git a/OOXML/Binary/Sheets/Writer/BinaryReader.cpp b/OOXML/Binary/Sheets/Writer/BinaryReader.cpp index f2b4fa8c9c..8373a7aa67 100644 --- a/OOXML/Binary/Sheets/Writer/BinaryReader.cpp +++ b/OOXML/Binary/Sheets/Writer/BinaryReader.cpp @@ -72,6 +72,7 @@ #include "../../../XlsxFormat/Controls/Controls.h" #include "../../../XlsxFormat/Timelines/Timeline.h" #include "../../../XlsxFormat/Workbook/Metadata.h" +#include "../../../XlsxFormat/Workbook/CustomsXml.h" #include "../../../DocxFormat/Media/VbaProject.h" #include "../../../DocxFormat/Media/JsaProject.h" @@ -996,6 +997,32 @@ int BinaryTableReader::ReadTableColumns(BYTE type, long length, void* poResult) res = c_oSerConstants::ReadUnknown; return res; } +int BinaryTableReader::ReadTableXmlColumnPr(BYTE type, long length, void* poResult) +{ + int res = c_oSerConstants::ReadOk; + OOX::Spreadsheet::CXmlColumnPr* pXmlColumnPr = static_cast(poResult); + + if (c_oSer_TableColumns::MapId == type) + { + pXmlColumnPr->mapId = m_oBufferedStream.GetLong(); + } + else if (c_oSer_TableColumns::Xpath == type) + { + pXmlColumnPr->xpath = m_oBufferedStream.GetString4(length); + } + else if (c_oSer_TableColumns::Denormalized == type) + { + pXmlColumnPr->denormalized = m_oBufferedStream.GetBool(); + } + else if (c_oSer_TableColumns::XmlDataType == type) + { + pXmlColumnPr->xmlDataType.Init(); + pXmlColumnPr->xmlDataType->SetValueFromByte(m_oBufferedStream.GetUChar()); + } + else + res = c_oSerConstants::ReadUnknown; + return res; +} int BinaryTableReader::ReadTableColumn(BYTE type, long length, void* poResult) { int res = c_oSerConstants::ReadOk; @@ -1063,6 +1090,11 @@ int BinaryTableReader::ReadTableColumn(BYTE type, long length, void* poResult) { pTableColumn->m_oUniqueName = m_oBufferedStream.GetString4(length); } + else if (c_oSer_TableColumns::XmlColumnPr == type) + { + pTableColumn->m_oXmlColumnPr.Init(); + READ2_DEF_SPREADSHEET(length, res, this->ReadTableXmlColumnPr, pTableColumn->m_oXmlColumnPr.GetPointer()); + } else res = c_oSerConstants::ReadUnknown; return res; @@ -2332,6 +2364,16 @@ int BinaryWorkbookTableReader::ReadWorkbookTableContent(BYTE type, long length, smart_ptr oFile = oMetadataFile.smart_dynamic_cast(); m_oWorkbook.Add(oFile); } + else if (c_oSerWorkbookTypes::XmlMap == type) + { + m_oBufferedStream.Skip(1); //skip type + + smart_ptr oXmlMapFile(new OOX::Spreadsheet::CXmlMapsFile(NULL)); + oXmlMapFile->fromPPTY(&m_oBufferedStream); + + smart_ptr oFile = oXmlMapFile.smart_dynamic_cast(); + m_oWorkbook.Add(oFile); + } else res = c_oSerConstants::ReadUnknown; return res; @@ -4629,6 +4671,16 @@ int BinaryWorksheetsTableReader::ReadWorksheet(boost::unordered_map oFile = pNamedSheetViewFile.smart_dynamic_cast(); m_pCurWorksheet->Add(oFile); SEEK_TO_POS_END2(); +//------------------------------------------------------------------------------------------------------------- + SEEK_TO_POS_START(c_oSerWorksheetsTypes::TableSingleCells); + + m_oBufferedStream.Skip(1); //skip type + + smart_ptr pTableSingleCellsFile(new OOX::Spreadsheet::CTableSingleCellsFile(NULL)); + pTableSingleCellsFile->fromPPTY(&m_oBufferedStream); + smart_ptr oFile = pTableSingleCellsFile.smart_dynamic_cast(); + m_pCurWorksheet->Add(oFile); + SEEK_TO_POS_END2(); //------------------------------------------------------------------------------------------------------------- m_oBufferedStream.Seek(nOldPos); m_pCurWorksheet->toXMLEnd(oStreamWriter); diff --git a/OOXML/Binary/Sheets/Writer/BinaryReader.h b/OOXML/Binary/Sheets/Writer/BinaryReader.h index d1551af149..6a6c8ee8f5 100644 --- a/OOXML/Binary/Sheets/Writer/BinaryReader.h +++ b/OOXML/Binary/Sheets/Writer/BinaryReader.h @@ -137,6 +137,7 @@ namespace BinXlsxRW int ReadTableColumns(BYTE type, long length, void* poResult); int ReadTableColumn(BYTE type, long length, void* poResult); int ReadTableStyleInfo(BYTE type, long length, void* poResult); + int ReadTableXmlColumnPr(BYTE type, long length, void* poResult); int ReadQueryTableContent(BYTE type, long length, void* poResult); int ReadQueryTableRefresh(BYTE type, long length, void* poResult); int ReadQueryTableFields(BYTE type, long length, void* poResult); diff --git a/OOXML/Common/SimpleTypes_Spreadsheet.cpp b/OOXML/Common/SimpleTypes_Spreadsheet.cpp index fb2b990041..17a58c1293 100644 --- a/OOXML/Common/SimpleTypes_Spreadsheet.cpp +++ b/OOXML/Common/SimpleTypes_Spreadsheet.cpp @@ -3415,5 +3415,25 @@ namespace SimpleTypes } return L"edit"; } + EXmlDataType CXmlDataType::FromString(const std::wstring& sValue) + { + if (L"date" == sValue) + this->m_eValue = typeDate; + else if (L"float" == sValue) + this->m_eValue = typeFloat; + else + this->m_eValue = typeString; + return this->m_eValue; + } + std::wstring CXmlDataType::ToString() const + { + switch (this->m_eValue) + { + case typeString: return L"string"; break; + case typeDate: return L"date"; break; + case typeFloat: return L"float"; break; + } + return L"edit"; + } }// Spreadsheet } // SimpleTypes diff --git a/OOXML/Common/SimpleTypes_Spreadsheet.h b/OOXML/Common/SimpleTypes_Spreadsheet.h index 70de28e593..77a18ce49b 100644 --- a/OOXML/Common/SimpleTypes_Spreadsheet.h +++ b/OOXML/Common/SimpleTypes_Spreadsheet.h @@ -1449,5 +1449,12 @@ namespace SimpleTypes }; DEFINE_SIMPLE_TYPE(CUserProtectedRangeType, EUserProtectedRangeType, typeView) + enum EXmlDataType + { + typeString = 0, + typeDate = 1, + typeFloat = 2 //... + }; + DEFINE_SIMPLE_TYPE(CXmlDataType, EXmlDataType, typeString) }// Spreadsheet } // SimpleTypes diff --git a/OOXML/DocxFormat/CustomXml.h b/OOXML/DocxFormat/CustomXml.h index 09819fdb28..a482db61ac 100644 --- a/OOXML/DocxFormat/CustomXml.h +++ b/OOXML/DocxFormat/CustomXml.h @@ -102,10 +102,8 @@ namespace OOX virtual const CPath DefaultDirectory() const; virtual const CPath DefaultFileName() const; - // Attributes SimpleTypes::CGuid m_oItemID; - // Childs nullable m_oShemaRefs; //------------- for write from binary std::wstring m_oCustomXmlContent; diff --git a/OOXML/DocxFormat/WritingElement.h b/OOXML/DocxFormat/WritingElement.h index 90aede38a6..2a2bc4c581 100644 --- a/OOXML/DocxFormat/WritingElement.h +++ b/OOXML/DocxFormat/WritingElement.h @@ -1342,6 +1342,7 @@ namespace OOX et_x_TableColumns, et_x_TableColumn, et_x_TableStyleInfo, + et_x_xmlColumnPr, et_x_AltTextTable, et_x_SortState, et_x_SortCondition, @@ -1544,7 +1545,16 @@ namespace OOX et_x_MdxKPI, et_x_DynamicArrayProperties, - et_x_RichValueBlock + et_x_RichValueBlock, + + et_x_MapInfo, + et_x_Schema, + et_x_Map, + et_x_DataBinding, + et_x_SingleXmlCells, + et_x_SingleXmlCell, + et_x_xmlCellPr, + et_x_xmlPr }; class File; diff --git a/OOXML/Projects/Linux/DocxFormatLib/DocxFormatLib.pro b/OOXML/Projects/Linux/DocxFormatLib/DocxFormatLib.pro index ed6fb5632f..8efa4c13a6 100644 --- a/OOXML/Projects/Linux/DocxFormatLib/DocxFormatLib.pro +++ b/OOXML/Projects/Linux/DocxFormatLib/DocxFormatLib.pro @@ -177,7 +177,8 @@ SOURCES += \ ../../../XlsxFormat/Workbook/ExternalReferences.cpp \ ../../../XlsxFormat/Workbook/Sheets.cpp \ ../../../XlsxFormat/Workbook/WorkbookPr.cpp \ - ../../../XlsxFormat/Comments/XlsxComments.cpp \ + ../../../XlsxFormat/Workbook/CustomsXml.cpp \ + ../../../XlsxFormat/Comments/XlsxComments.cpp \ ../../../XlsxFormat/Comments/ThreadedComments.cpp \ ../../../XlsxFormat/Drawing/CellAnchor.cpp \ ../../../XlsxFormat/Drawing/XlsxDrawing.cpp \ @@ -334,7 +335,8 @@ HEADERS += \ ../../../XlsxFormat/Workbook/Workbook.h \ ../../../XlsxFormat/Workbook/WorkbookPr.h \ ../../../XlsxFormat/Workbook/ExternalReferences.h \ - ../../../XlsxFormat/Worksheets/Cols.h \ + ../../../XlsxFormat/Workbook/CustomsXml.h \ + ../../../XlsxFormat/Worksheets/Cols.h \ ../../../XlsxFormat/Worksheets/ConditionalFormatting.h \ ../../../XlsxFormat/Worksheets/DataValidation.h \ ../../../XlsxFormat/Worksheets/Hyperlinks.h \ diff --git a/OOXML/Projects/Linux/DocxFormatLib/xlsx_format_logic.cpp b/OOXML/Projects/Linux/DocxFormatLib/xlsx_format_logic.cpp index aa764e8635..b8b2abbe0f 100644 --- a/OOXML/Projects/Linux/DocxFormatLib/xlsx_format_logic.cpp +++ b/OOXML/Projects/Linux/DocxFormatLib/xlsx_format_logic.cpp @@ -82,6 +82,7 @@ #include "../../../XlsxFormat/Workbook/ExternalReferences.cpp" #include "../../../XlsxFormat/Workbook/Sheets.cpp" #include "../../../XlsxFormat/Workbook/WorkbookPr.cpp" +#include "../../../XlsxFormat/Workbook/CustomsXml.cpp" #include "../../../XlsxFormat/Comments/XlsxComments.cpp" #include "../../../XlsxFormat/Comments/ThreadedComments.cpp" #include "../../../XlsxFormat/Drawing/CellAnchor.cpp" diff --git a/OOXML/Projects/Windows/DocxFormatLib/DocxFormatLib.vcxproj b/OOXML/Projects/Windows/DocxFormatLib/DocxFormatLib.vcxproj index 4dc49f0162..9ef90557c9 100644 --- a/OOXML/Projects/Windows/DocxFormatLib/DocxFormatLib.vcxproj +++ b/OOXML/Projects/Windows/DocxFormatLib/DocxFormatLib.vcxproj @@ -384,6 +384,7 @@ + @@ -545,6 +546,7 @@ + diff --git a/OOXML/Projects/Windows/DocxFormatLib/DocxFormatLib.vcxproj.filters b/OOXML/Projects/Windows/DocxFormatLib/DocxFormatLib.vcxproj.filters index 8b9170151f..2f28340aef 100644 --- a/OOXML/Projects/Windows/DocxFormatLib/DocxFormatLib.vcxproj.filters +++ b/OOXML/Projects/Windows/DocxFormatLib/DocxFormatLib.vcxproj.filters @@ -553,6 +553,9 @@ XlsxFormat\Pivots + + XlsxFormat\Workbook + @@ -975,5 +978,8 @@ XlsxFormat\Pivots + + XlsxFormat\Workbook + \ No newline at end of file diff --git a/OOXML/XlsxFormat/FileFactory_Spreadsheet.cpp b/OOXML/XlsxFormat/FileFactory_Spreadsheet.cpp index 8b692b6291..135fea08a1 100644 --- a/OOXML/XlsxFormat/FileFactory_Spreadsheet.cpp +++ b/OOXML/XlsxFormat/FileFactory_Spreadsheet.cpp @@ -46,6 +46,7 @@ #include "Worksheets/Worksheet.h" #include "CalcChain/CalcChain.h" #include "WorkbookComments.h" +#include "Workbook/CustomsXml.h" #include "Comments/ThreadedComments.h" #include "Comments/Comments.h" #include "Controls/Controls.h" @@ -114,6 +115,8 @@ namespace OOX return smart_ptr(new CWorksheet( pMain, oRootPath, oFileName, oRelation.rId().ToString(), true )); else if ( oRelation.Type() == FileTypes::Table ) return smart_ptr(new CTableFile( pMain, oRootPath, oFileName )); + else if (oRelation.Type() == FileTypes::TableSingleCells) + return smart_ptr(new CTableSingleCellsFile(pMain, oRootPath, oFileName)); else if ( oRelation.Type() == FileTypes::QueryTable ) return smart_ptr(new CQueryTableFile( pMain, oRootPath, oFileName )); else if ( oRelation.Type() == FileTypes::PivotTable ) @@ -140,7 +143,9 @@ namespace OOX return smart_ptr(new CExternalLink( pMain, oRootPath, oFileName, oRelation.rId().ToString() )); else if ( oRelation.Type() == FileTypes::Connections ) return smart_ptr(new CConnectionsFile( pMain, oRootPath, oFileName )); - + else if (oRelation.Type() == FileTypes::XmlMaps) + return smart_ptr(new CXmlMapsFile(pMain, oRootPath, oFileName)); + else if ( oRelation.Type() == OOX::FileTypes::Chart ) return smart_ptr(new CChartFile( pMain, oRootPath, oFileName )); else if ( oRelation.Type() == OOX::FileTypes::ChartEx ) @@ -251,6 +256,8 @@ namespace OOX return smart_ptr(new CWorksheet( pMain, oRootPath, oFileName, pRelation->rId().ToString(), true )); else if ( pRelation->Type() == FileTypes::Table ) return smart_ptr(new CTableFile( pMain, oRootPath, oFileName )); + else if (pRelation->Type() == FileTypes::TableSingleCells) + return smart_ptr(new CTableSingleCellsFile(pMain, oRootPath, oFileName)); else if ( pRelation->Type() == FileTypes::QueryTable ) return smart_ptr(new CQueryTableFile( pMain, oRootPath, oFileName )); else if ( pRelation->Type() == FileTypes::PivotTable ) @@ -331,8 +338,10 @@ namespace OOX return smart_ptr(new CRdRichValueFile(pMain, oRootPath, oFileName)); else if (pRelation->Type() == FileTypes::RdRichValueTypes) return smart_ptr(new CRdRichValueTypesFile(pMain, oRootPath, oFileName)); + else if (pRelation->Type() == FileTypes::XmlMaps) + return smart_ptr(new CXmlMapsFile(pMain, oRootPath, oFileName)); return smart_ptr( new UnknowTypeFile(pMain) ); } - } + } } // namespace OOX diff --git a/OOXML/XlsxFormat/FileTypes_Spreadsheet.cpp b/OOXML/XlsxFormat/FileTypes_Spreadsheet.cpp index e5c88368de..4bdcf456da 100644 --- a/OOXML/XlsxFormat/FileTypes_Spreadsheet.cpp +++ b/OOXML/XlsxFormat/FileTypes_Spreadsheet.cpp @@ -86,6 +86,11 @@ namespace OOX L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/table", L"tables/table", true, true); + const FileType TableSingleCells (L"../tables", L"tableSingleCells.xml", + L"application/vnd.openxmlformats-officedocument.spreadsheetml.tableSingleCells+xml", + L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/tableSingleCells", + L"tables/tableSingleCells", true, true); + const FileType QueryTable (L"../queryTables", L"queryTable.xml", L"application/vnd.openxmlformats-officedocument.spreadsheetml.queryTable+xml", L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/queryTable", @@ -172,10 +177,14 @@ namespace OOX L"application/vnd.ms-excel.rdrichvaluestructure+xml", L"http://schemas.microsoft.com/office/2017/06/relationships/rdRichValueStructure"); - const FileType RdRichValueTypes (L"richData", L"rdRichValueTypes..xml", + const FileType RdRichValueTypes (L"richData", L"rdRichValueTypes.xml", L"application/vnd.ms-excel.rdrichvaluetypes+xml", L"http://schemas.microsoft.com/office/2017/06/relationships/rdRichValueTypes"); + const FileType XmlMaps (L"", L"xmlMaps.xml", + L"application/xml", + L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/xmlMaps"); + const FileType SpreadsheetFlat (L"", L"", L"", L""); } // namespace FileTypes diff --git a/OOXML/XlsxFormat/FileTypes_Spreadsheet.h b/OOXML/XlsxFormat/FileTypes_Spreadsheet.h index 0204c80566..3f71d38ed8 100644 --- a/OOXML/XlsxFormat/FileTypes_Spreadsheet.h +++ b/OOXML/XlsxFormat/FileTypes_Spreadsheet.h @@ -60,6 +60,8 @@ namespace OOX extern const FileType Table; + extern const FileType TableSingleCells; + extern const FileType QueryTable; extern const FileType Connections; @@ -100,6 +102,8 @@ namespace OOX extern const FileType RdRichValueStructure; extern const FileType RdRichValueTypes; + + extern const FileType XmlMaps; } // namespace FileTypes } } // namespace OOX diff --git a/OOXML/XlsxFormat/Table/Table.h b/OOXML/XlsxFormat/Table/Table.h index 58bfc18f29..a64d5b461a 100644 --- a/OOXML/XlsxFormat/Table/Table.h +++ b/OOXML/XlsxFormat/Table/Table.h @@ -41,6 +41,7 @@ namespace SimpleTypes { class CTableType; class CTotalsRowFunction; + class CXmlDataType; } } @@ -124,26 +125,46 @@ namespace OOX public: nullable m_oName; - nullable m_oShowColumnStripes; - nullable m_oShowFirstColumn; - nullable m_oShowLastColumn; - nullable m_oShowRowStripes; + nullable m_oShowColumnStripes; + nullable m_oShowFirstColumn; + nullable m_oShowLastColumn; + nullable m_oShowRowStripes; }; + class CXmlColumnPr : public WritingElement + { + public: + WritingElement_AdditionMethods(CXmlColumnPr) + CXmlColumnPr() {} + virtual ~CXmlColumnPr() {} + virtual void fromXML(XmlUtils::CXmlNode& node) {} + virtual std::wstring toXML() const { return L""; } + virtual void toXML(NSStringUtils::CStringBuilder& writer) const; + + virtual void fromXML(XmlUtils::CXmlLiteReader& oReader); + virtual void toXmlWriter(NSBinPptxRW::CXmlWriter* pWriter) const; + + void ReadAttributes(XmlUtils::CXmlLiteReader& oReader); + + virtual void toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const; + virtual void fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader); + virtual EElementType getType() const; + + nullable_uint mapId; + nullable_string xpath; + nullable_bool denormalized; + nullable xmlDataType; + + //ext + }; class CTableColumn : public WritingElement { public: WritingElement_AdditionMethods(CTableColumn) WritingElement_XlsbConstructors(CTableColumn) - CTableColumn() - { - } - virtual ~CTableColumn() - { - } - virtual void fromXML(XmlUtils::CXmlNode& node) - { - } + CTableColumn() {} + virtual ~CTableColumn() {} + virtual void fromXML(XmlUtils::CXmlNode& node) {} virtual std::wstring toXML() const { return _T(""); @@ -162,24 +183,24 @@ namespace OOX void ReadAttributes(XLS::BaseObjectPtr& obj); public: - nullable_string m_oDataCellStyle; - nullable m_oDataDxfId; - nullable_string m_oHeaderRowCellStyle; - nullable m_oHeaderRowDxfId; - nullable m_oId; - nullable_string m_oName; - nullable m_oQueryTableFieldId; - nullable_string m_oTotalsRowCellStyle; - nullable m_oTotalsRowDxfId; - nullable m_oTotalsRowFunction; - nullable_string m_oTotalsRowLabel; - nullable_string m_oUniqueName; - nullable_string m_oUid; + nullable_string m_oDataCellStyle; + nullable m_oDataDxfId; + nullable_string m_oHeaderRowCellStyle; + nullable m_oHeaderRowDxfId; + nullable m_oId; + nullable_string m_oName; + nullable m_oQueryTableFieldId; + nullable_string m_oTotalsRowCellStyle; + nullable m_oTotalsRowDxfId; + nullable m_oTotalsRowFunction; + nullable_string m_oTotalsRowLabel; + nullable_string m_oUniqueName; + nullable_string m_oUid; - nullable_string m_oTotalsRowFormula; - nullable_string m_oCalculatedColumnFormula; - //xmlColumnPr; - //ext + nullable_string m_oTotalsRowFormula; + nullable_string m_oCalculatedColumnFormula; + nullable m_oXmlColumnPr; + //ext }; class CTableColumns : public WritingElementWithChilds @@ -397,16 +418,129 @@ namespace OOX { return m_oReadPath; } - - nullable m_oTable; - + nullable m_oTable; private: - CPath m_oReadPath; - - void ReadAttributes(XmlUtils::CXmlLiteReader& oReader) - { - } + CPath m_oReadPath; }; +//--------------------------------------------------------------------------------------------------------------------------------- + class CXmlPr : public WritingElement + { + public: + WritingElement_AdditionMethods(CXmlPr) + CXmlPr() {} + virtual ~CXmlPr() {} + virtual void fromXML(XmlUtils::CXmlNode& node) {} + virtual std::wstring toXML() const { return L""; } + virtual void toXML(NSStringUtils::CStringBuilder& writer) const {} + + virtual void fromXML(XmlUtils::CXmlLiteReader& oReader); + virtual void toXmlWriter(NSBinPptxRW::CXmlWriter* pWriter) const; + + void ReadAttributes(XmlUtils::CXmlLiteReader& oReader); + + virtual void toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const; + virtual void fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader); + virtual EElementType getType() const; + + nullable_uint mapId; + nullable_string xpath; + nullable xmlDataType; + + //ext + }; + class CXmlCellPr : public WritingElement + { + public: + WritingElement_AdditionMethods(CXmlCellPr) + CXmlCellPr() {} + virtual ~CXmlCellPr() {} + + virtual void fromXML(XmlUtils::CXmlNode& node) {} + virtual std::wstring toXML() const { return L""; } + virtual void toXML(NSStringUtils::CStringBuilder& writer) const {} + + virtual void fromXML(XmlUtils::CXmlLiteReader& oReader); + virtual void toXmlWriter(NSBinPptxRW::CXmlWriter* pWriter) const; + + void ReadAttributes(XmlUtils::CXmlLiteReader& oReader); + + virtual void toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const; + virtual void fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader); + virtual EElementType getType() const; + + nullable_uint id; + nullable_string uniqueName; + + nullable xmlPr; + //ext + }; + class CSingleXmlCell : public WritingElement + { + public: + WritingElement_AdditionMethods(CSingleXmlCell) + CSingleXmlCell() {} + virtual ~CSingleXmlCell() {} + + virtual void fromXML(XmlUtils::CXmlNode& node) {} + virtual std::wstring toXML() const { return L""; } + virtual void toXML(NSStringUtils::CStringBuilder& writer) const {} + + virtual void fromXML(XmlUtils::CXmlLiteReader& oReader); + virtual void toXmlWriter(NSBinPptxRW::CXmlWriter* pWriter) const; + + void ReadAttributes(XmlUtils::CXmlLiteReader& oReader); + + virtual void toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const; + virtual void fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader); + virtual EElementType getType() const; + + nullable_uint connectionId; + nullable_uint id; + nullable_string r; //ref + + nullable xmlCellPr; + //ext + }; + class CSingleXmlCells : public WritingElementWithChilds + { + public: + WritingElement_AdditionMethods(CSingleXmlCells) + CSingleXmlCells() {} + virtual ~CSingleXmlCells() {} + + virtual void toXML(NSStringUtils::CStringBuilder& writer) const {} + virtual std::wstring toXML() const { return L""; } + virtual void fromXML(XmlUtils::CXmlNode& node) {} + virtual void fromXML(XmlUtils::CXmlLiteReader& oReader); + virtual void toXmlWriter(NSBinPptxRW::CXmlWriter* pWriter) const; + + virtual EElementType getType() const; + + virtual void fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader); + virtual void toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const; + }; + class CTableSingleCellsFile : public OOX::File + { + public: + CTableSingleCellsFile(OOX::Document* pMain); + CTableSingleCellsFile(OOX::Document* pMain, const CPath& uri); + CTableSingleCellsFile(OOX::Document* pMain, const CPath& oRootPath, const CPath& oPath); + virtual ~CTableSingleCellsFile(); + + virtual void read(const CPath& oFilePath); + virtual void read(const CPath& oRootPath, const CPath& oFilePath); + virtual void write(const CPath& oFilePath, const CPath& oDirectory, CContentTypes& oContent) const; + + virtual const OOX::FileType type() const; + + virtual const CPath DefaultDirectory() const; + virtual const CPath DefaultFileName() const; + + virtual void fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader); + virtual void toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const; + + nullable singleXmlCells; + }; } //Spreadsheet } // namespace OOX diff --git a/OOXML/XlsxFormat/Table/Tables.cpp b/OOXML/XlsxFormat/Table/Tables.cpp index f6f3afab2d..ea97a2801e 100644 --- a/OOXML/XlsxFormat/Table/Tables.cpp +++ b/OOXML/XlsxFormat/Table/Tables.cpp @@ -203,7 +203,91 @@ namespace Spreadsheet WritingElement_ReadAttributes_End( oReader ) } + //----------------------------------------------------------------------------------------------------------------------------- + EElementType CXmlColumnPr::getType() const + { + return et_x_xmlColumnPr; + } + void CXmlColumnPr::ReadAttributes(XmlUtils::CXmlLiteReader& oReader) + { + WritingElement_ReadAttributes_StartChar_No_NS(oReader) + WritingElement_ReadAttributes_Read_ifChar(oReader, "mapId", mapId) + WritingElement_ReadAttributes_Read_else_ifChar(oReader, "xpath", xpath) + WritingElement_ReadAttributes_Read_else_ifChar(oReader, "xmlDataType", xmlDataType) + WritingElement_ReadAttributes_Read_else_ifChar(oReader, "denormalized", denormalized) + WritingElement_ReadAttributes_EndChar_No_NS(oReader) + } + void CXmlColumnPr::fromXML(XmlUtils::CXmlLiteReader& oReader) + { + ReadAttributes(oReader); + if (oReader.IsEmptyNode()) + return; + } + void CXmlColumnPr::toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const + { + pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeStart); + pWriter->WriteUInt2(0, mapId); + pWriter->WriteString2(1, xpath); + if (xmlDataType.IsInit()) + pWriter->WriteByte1(2, xmlDataType->GetValue()); + pWriter->WriteBool2(1, denormalized); + pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeEnd); + } + void CXmlColumnPr::fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader) + { + LONG _end_rec = pReader->GetPos() + pReader->GetRecordSize() + 4; + pReader->Skip(1); // start attributes + while (true) + { + BYTE _at = pReader->GetUChar_TypeNode(); + if (_at == NSBinPptxRW::g_nodeAttributeEnd) + break; + switch (_at) + { + case 0: + { + mapId = pReader->GetULong(); + }break; + case 1: + { + xpath = pReader->GetString2(); + }break; + case 2: + { + xmlDataType.Init(); + xmlDataType->SetValueFromByte(pReader->GetUChar()); + }break; + case 3: + { + denormalized = pReader->GetBool(); + }break; + } + } + pReader->Seek(_end_rec); + } + void CXmlColumnPr::toXmlWriter(NSBinPptxRW::CXmlWriter* pWriter) const + { + pWriter->StartNode(L"xmlColumnPr"); + pWriter->StartAttributes(); + pWriter->WriteAttribute2(L"mapId", mapId); + pWriter->WriteAttribute2(L"xpath", xpath); + if (xmlDataType.IsInit()) pWriter->WriteAttribute(L"xmlDataType", xmlDataType->ToString()); + pWriter->WriteAttribute(L"denormalized", denormalized); + pWriter->EndAttributes(); + + pWriter->WriteNodeEnd(L"xmlColumnPr"); + } + void CXmlColumnPr::toXML(NSStringUtils::CStringBuilder& writer) const + { + writer.WriteString(L"ToString()); + WritingStringNullableAttrBool2(L"denormalized", denormalized); + writer.WriteString(L"/>"); + } + void CTableColumn::toXML(NSStringUtils::CStringBuilder& writer) const { std::wstring sRoot; @@ -221,15 +305,20 @@ namespace Spreadsheet WritingStringNullableAttrInt(L"headerRowDxfId", m_oHeaderRowDxfId, m_oHeaderRowDxfId->GetValue()); WritingStringNullableAttrString(L"totalsRowCellStyle", m_oTotalsRowCellStyle, *m_oTotalsRowCellStyle); WritingStringNullableAttrInt(L"totalsRowDxfId", m_oTotalsRowDxfId, m_oTotalsRowDxfId->GetValue()); - if(m_oTotalsRowFormula.IsInit() || m_oCalculatedColumnFormula.IsInit()) + + if (m_oTotalsRowFormula.IsInit() || m_oCalculatedColumnFormula.IsInit() || m_oXmlColumnPr.IsInit()) { writer.WriteString(L">"); - if(m_oCalculatedColumnFormula.IsInit()) + if (m_oXmlColumnPr.IsInit()) + { + m_oXmlColumnPr->toXML(writer); + } + if (m_oCalculatedColumnFormula.IsInit()) { WritingStringValEncodeXmlString(L"calculatedColumnFormula", m_oCalculatedColumnFormula.get()); } - if(m_oTotalsRowFormula.IsInit()) + if (m_oTotalsRowFormula.IsInit()) { WritingStringValEncodeXmlString(L"totalsRowFormula", m_oTotalsRowFormula.get()); } @@ -253,10 +342,12 @@ namespace Spreadsheet { std::wstring sName = XmlUtils::GetNameNoNS(oReader.GetName()); - if ( (L"totalsRowFormula") == sName ) + if (L"totalsRowFormula" == sName) m_oTotalsRowFormula = oReader.GetText3(); - else if ( (L"calculatedColumnFormula") == sName ) + else if (L"calculatedColumnFormula" == sName) m_oCalculatedColumnFormula = oReader.GetText3(); + else if (L"xmlColumnPr" == sName) + m_oXmlColumnPr = oReader; } } void CTableColumn::fromBin(XLS::BaseObjectPtr& obj) @@ -1896,6 +1987,410 @@ xmlns:xr16=\"http://schemas.microsoft.com/office/spreadsheetml/2017/revision16\" } return OOX::Spreadsheet::FileTypes::QueryTable; } +//----------------------------------------------------------------------------------------------------------------------------- + EElementType CXmlPr::getType() const + { + return et_x_xmlPr; + } + void CXmlPr::ReadAttributes(XmlUtils::CXmlLiteReader& oReader) + { + WritingElement_ReadAttributes_StartChar_No_NS(oReader) + WritingElement_ReadAttributes_Read_ifChar(oReader, "mapId", mapId) + WritingElement_ReadAttributes_Read_else_ifChar(oReader, "xpath", xpath) + WritingElement_ReadAttributes_Read_else_ifChar(oReader, "xmlDataType", xmlDataType) + WritingElement_ReadAttributes_EndChar_No_NS(oReader) + } + void CXmlPr::fromXML(XmlUtils::CXmlLiteReader& oReader) + { + ReadAttributes(oReader); + if (oReader.IsEmptyNode()) + return; + } + void CXmlPr::toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const + { + pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeStart); + pWriter->WriteUInt2(0, mapId); + pWriter->WriteString2(1, xpath); + if (xmlDataType.IsInit()) + pWriter->WriteByte1(2, xmlDataType->GetValue()); + pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeEnd); + } + void CXmlPr::fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader) + { + LONG _end_rec = pReader->GetPos() + pReader->GetRecordSize() + 4; + pReader->Skip(1); // start attributes + while (true) + { + BYTE _at = pReader->GetUChar_TypeNode(); + if (_at == NSBinPptxRW::g_nodeAttributeEnd) + break; + switch (_at) + { + case 0: + { + mapId = pReader->GetULong(); + }break; + case 1: + { + xpath = pReader->GetString2(); + }break; + case 2: + { + xmlDataType.Init(); + xmlDataType->SetValueFromByte(pReader->GetUChar()); + }break; + } + } + pReader->Seek(_end_rec); + } + void CXmlPr::toXmlWriter(NSBinPptxRW::CXmlWriter* pWriter) const + { + pWriter->StartNode(L"xmlPr"); + pWriter->StartAttributes(); + pWriter->WriteAttribute2(L"mapId", mapId); + pWriter->WriteAttribute2(L"xpath", xpath); + if (xmlDataType.IsInit()) pWriter->WriteAttribute(L"xmlDataType", xmlDataType->ToString()); + pWriter->EndAttributes(); + + pWriter->WriteNodeEnd(L"xmlPr"); + } +//----------------------------------------------------------------------------------------------------------------------------- + EElementType CXmlCellPr::getType() const + { + return et_x_xmlCellPr; + } + void CXmlCellPr::ReadAttributes(XmlUtils::CXmlLiteReader& oReader) + { + WritingElement_ReadAttributes_StartChar_No_NS(oReader) + WritingElement_ReadAttributes_Read_ifChar(oReader, "uniqueName", uniqueName) + WritingElement_ReadAttributes_Read_else_ifChar(oReader, "id", id) + WritingElement_ReadAttributes_EndChar_No_NS(oReader) + } + void CXmlCellPr::fromXML(XmlUtils::CXmlLiteReader& oReader) + { + ReadAttributes(oReader); + + if (oReader.IsEmptyNode()) + return; + + int nParentDepth = oReader.GetDepth(); + while (oReader.ReadNextSiblingNode(nParentDepth)) + { + std::wstring sName = oReader.GetNameNoNS(); + + if (L"xmlPr" == sName) + { + xmlPr = oReader; + } + } + } + void CXmlCellPr::toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const + { + pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeStart); + pWriter->WriteString2(0, uniqueName); + pWriter->WriteUInt2(1, id); + pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeEnd); + + pWriter->WriteRecord2(0, xmlPr); + } + void CXmlCellPr::fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader) + { + LONG _end_rec = pReader->GetPos() + pReader->GetRecordSize() + 4; + pReader->Skip(1); // start attributes + while (true) + { + BYTE _at = pReader->GetUChar_TypeNode(); + if (_at == NSBinPptxRW::g_nodeAttributeEnd) + break; + switch (_at) + { + case 0: + { + uniqueName = pReader->GetString2(); + }break; + case 1: + { + id = pReader->GetULong(); + }break; + } + } + while (pReader->GetPos() < _end_rec) + { + BYTE _rec = pReader->GetUChar(); + switch (_rec) + { + case 0: + { + xmlPr.Init(); + xmlPr->fromPPTY(pReader); + }break; + default: + { + pReader->SkipRecord(); + }break; + } + } + pReader->Seek(_end_rec); + } + void CXmlCellPr::toXmlWriter(NSBinPptxRW::CXmlWriter* pWriter) const + { + pWriter->StartNode(L"xmlCellPr"); + pWriter->StartAttributes(); + pWriter->WriteAttribute2(L"id", id); + pWriter->WriteAttribute2(L"uniqueName", uniqueName); + pWriter->EndAttributes(); + + if (xmlPr.IsInit()) + xmlPr->toXmlWriter(pWriter); + + pWriter->WriteNodeEnd(L"xmlCellPr"); + } +//----------------------------------------------------------------------------------------------------------------------------- + EElementType CSingleXmlCell::getType() const + { + return et_x_SingleXmlCell; + } + void CSingleXmlCell::ReadAttributes(XmlUtils::CXmlLiteReader& oReader) + { + WritingElement_ReadAttributes_StartChar_No_NS(oReader) + WritingElement_ReadAttributes_Read_ifChar(oReader, "connectionId", connectionId) + WritingElement_ReadAttributes_Read_else_ifChar(oReader, "id", id) + WritingElement_ReadAttributes_Read_else_ifChar(oReader, "r", r) + WritingElement_ReadAttributes_EndChar_No_NS(oReader) + } + void CSingleXmlCell::fromXML(XmlUtils::CXmlLiteReader& oReader) + { + ReadAttributes(oReader); + + if (oReader.IsEmptyNode()) + return; + + int nParentDepth = oReader.GetDepth(); + while (oReader.ReadNextSiblingNode(nParentDepth)) + { + std::wstring sName = oReader.GetNameNoNS(); + + if (L"xmlCellPr" == sName) + { + xmlCellPr = oReader; + } + } + } + void CSingleXmlCell::toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const + { + pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeStart); + pWriter->WriteUInt2(0, connectionId); + pWriter->WriteUInt2(1, id); + pWriter->WriteString2(2, r); + pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeEnd); + + pWriter->WriteRecord2(0, xmlCellPr); + } + void CSingleXmlCell::fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader) + { + LONG _end_rec = pReader->GetPos() + pReader->GetRecordSize() + 4; + pReader->Skip(1); // start attributes + while (true) + { + BYTE _at = pReader->GetUChar_TypeNode(); + if (_at == NSBinPptxRW::g_nodeAttributeEnd) + break; + switch (_at) + { + case 0: + { + connectionId = pReader->GetULong(); + }break; + case 1: + { + id = pReader->GetULong(); + }break; + case 2: + { + r = pReader->GetString2(); + }break; + } + } + while (pReader->GetPos() < _end_rec) + { + BYTE _rec = pReader->GetUChar(); + switch (_rec) + { + case 0: + { + xmlCellPr.Init(); + xmlCellPr->fromPPTY(pReader); + }break; + default: + { + pReader->SkipRecord(); + }break; + } + } + pReader->Seek(_end_rec); + } + void CSingleXmlCell::toXmlWriter(NSBinPptxRW::CXmlWriter* pWriter) const + { + pWriter->StartNode(L"singleXmlCell"); + pWriter->StartAttributes(); + pWriter->WriteAttribute2(L"id", id); + pWriter->WriteAttribute2(L"r", r); + pWriter->WriteAttribute2(L"connectionId", connectionId); + pWriter->EndAttributes(); + + if (xmlCellPr.IsInit()) + xmlCellPr->toXmlWriter(pWriter); + + pWriter->WriteNodeEnd(L"singleXmlCell"); + } +//----------------------------------------------------------------------------------------------------------------------------- + void CSingleXmlCells::fromXML(XmlUtils::CXmlLiteReader& oReader) + { + if (oReader.IsEmptyNode()) + return; + + int nParentDepth = oReader.GetDepth(); + while (oReader.ReadNextSiblingNode(nParentDepth)) + { + std::wstring sName = oReader.GetNameNoNS(); + + if (L"singleXmlCell" == sName) + { + CSingleXmlCell* pItem = new CSingleXmlCell(); + *pItem = oReader; + + if (pItem) + m_arrItems.push_back(pItem); + } + } + } + EElementType CSingleXmlCells::getType() const + { + return et_x_SingleXmlCells; + } + void CSingleXmlCells::fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader) + { + LONG end = pReader->GetPos() + pReader->GetRecordSize() + 4; + while (pReader->GetPos() < end) + { + BYTE _rec = pReader->GetUChar(); + switch (_rec) + { + case 0: + { + m_arrItems.push_back(new CSingleXmlCell()); + m_arrItems.back()->fromPPTY(pReader); + }break; + default: + { + pReader->SkipRecord(); + }break; + } + } + pReader->Seek(end); + } + void CSingleXmlCells::toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const + { + for (size_t i = 0; i < m_arrItems.size(); ++i) + pWriter->WriteRecord2(0, dynamic_cast(m_arrItems[i])); + } + void CSingleXmlCells::toXmlWriter(NSBinPptxRW::CXmlWriter* pWriter) const + { + pWriter->StartNode(L"singleXmlCells"); + pWriter->StartAttributes(); + pWriter->WriteAttribute2(L"xmlns", L"http://schemas.openxmlformats.org/spreadsheetml/2006/main"); + pWriter->EndAttributes(); + + for (size_t i = 0; i < m_arrItems.size(); ++i) + m_arrItems[i]->toXmlWriter(pWriter); + + pWriter->WriteNodeEnd(L"singleXmlCells"); + } +//----------------------------------------------------------------------------------------------------------------------------- + CTableSingleCellsFile::CTableSingleCellsFile(OOX::Document* pMain) : OOX::File(pMain) + { + } + CTableSingleCellsFile::CTableSingleCellsFile(OOX::Document* pMain, const CPath& uri) : OOX::File(pMain) + { + read(uri.GetDirectory(), uri); + } + CTableSingleCellsFile::CTableSingleCellsFile(OOX::Document* pMain, const CPath& oRootPath, const CPath& oPath) : OOX::File(pMain) + { + read(oRootPath, oPath); + } + CTableSingleCellsFile::~CTableSingleCellsFile() + { + } + void CTableSingleCellsFile::read(const CPath& oFilePath) + { + CPath oRootPath; + read(oRootPath, oFilePath); + } + void CTableSingleCellsFile::read(const CPath& oRootPath, const CPath& oFilePath) + { + XmlUtils::CXmlLiteReader oReader; + + if (!oReader.FromFile(oFilePath.GetPath())) + return; + + if (!oReader.ReadNextNode()) + return; + + singleXmlCells = oReader; + } + void CTableSingleCellsFile::write(const CPath& oFilePath, const CPath& oDirectory, CContentTypes& oContent) const + { + NSBinPptxRW::CXmlWriter oXmlWriter; + oXmlWriter.WriteString((L"")); + + oXmlWriter.m_lDocType = XMLWRITER_DOC_TYPE_XLSX; + + if (singleXmlCells.IsInit()) + singleXmlCells->toXmlWriter(&oXmlWriter); + + NSFile::CFileBinary::SaveToFile(oFilePath.GetPath(), oXmlWriter.GetXmlString()); + + oContent.Registration(type().OverrideType(), oDirectory, oFilePath.GetFilename()); + } + const OOX::FileType CTableSingleCellsFile::type() const + { + return FileTypes::TableSingleCells; + } + const OOX::CPath CTableSingleCellsFile::DefaultDirectory() const + { + return type().DefaultDirectory(); + } + const OOX::CPath CTableSingleCellsFile::DefaultFileName() const + { + return type().DefaultFileName(); + } + void CTableSingleCellsFile::fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader) + { + LONG end = pReader->GetPos() + pReader->GetRecordSize() + 4; + + while (pReader->GetPos() < end) + { + BYTE _rec = pReader->GetUChar(); + + switch (_rec) + { + case 0: + { + singleXmlCells.Init(); + singleXmlCells->fromPPTY(pReader); + }break; + default: + { + pReader->SkipRecord(); + }break; + } + } + pReader->Seek(end); + } + void CTableSingleCellsFile::toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const + { + pWriter->WriteRecord2(0, singleXmlCells); + } } //Spreadsheet } // namespace OOX diff --git a/OOXML/XlsxFormat/Workbook/CustomsXml.cpp b/OOXML/XlsxFormat/Workbook/CustomsXml.cpp new file mode 100644 index 0000000000..1c35da1572 --- /dev/null +++ b/OOXML/XlsxFormat/Workbook/CustomsXml.cpp @@ -0,0 +1,561 @@ +/* + * (c) Copyright Ascensio System SIA 2010-2023 + * + * This program is a free software product. You can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License (AGPL) + * version 3 as published by the Free Software Foundation. In accordance with + * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect + * that Ascensio System SIA expressly excludes the warranty of non-infringement + * of any third-party rights. + * + * This program is distributed WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For + * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html + * + * You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish + * street, Riga, Latvia, EU, LV-1050. + * + * The interactive user interfaces in modified source and object code versions + * of the Program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU AGPL version 3. + * + * Pursuant to Section 7(b) of the License you must retain the original Product + * logo when distributing the program. Pursuant to Section 7(e) we decline to + * grant you any rights under trademark law for use of our trademarks. + * + * All the Product's GUI elements, including illustrations and icon sets, as + * well as technical writing content are licensed under the terms of the + * Creative Commons Attribution-ShareAlike 4.0 International. See the License + * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + * + */ +#include "CustomsXML.h" + +#include "../FileTypes_Spreadsheet.h" + +#include "../../../DesktopEditor/common/SystemUtils.h" +#include "../../Binary/Presentation/BinaryFileReaderWriter.h" +#include "../../Binary/Presentation/XmlWriter.h" + +namespace OOX +{ +namespace Spreadsheet +{ + CXmlMapsFile::CXmlMapsFile(OOX::Document* pMain) : OOX::File(pMain) + { + } + CXmlMapsFile::CXmlMapsFile(OOX::Document* pMain, const CPath& uri) : OOX::File(pMain) + { + read(uri.GetDirectory(), uri); + } + CXmlMapsFile::CXmlMapsFile(OOX::Document* pMain, const CPath& oRootPath, const CPath& oPath) : OOX::File(pMain) + { + read(oRootPath, oPath); + } + CXmlMapsFile::~CXmlMapsFile() + { + } + void CXmlMapsFile::read(const CPath& oFilePath) + { + CPath oRootPath; + read(oRootPath, oFilePath); + } + void CXmlMapsFile::read(const CPath& oRootPath, const CPath& oFilePath) + { + XmlUtils::CXmlLiteReader oReader; + + if (!oReader.FromFile(oFilePath.GetPath())) + return; + + if (!oReader.ReadNextNode()) + return; + + m_MapInfo = oReader; + } + void CXmlMapsFile::write(const CPath& oFilePath, const CPath& oDirectory, CContentTypes& oContent) const + { + NSBinPptxRW::CXmlWriter oXmlWriter; + oXmlWriter.WriteString((L"")); + + oXmlWriter.m_lDocType = XMLWRITER_DOC_TYPE_XLSX; + + if (m_MapInfo.IsInit()) + m_MapInfo->toXmlWriter(&oXmlWriter); + + NSFile::CFileBinary::SaveToFile(oFilePath.GetPath(), oXmlWriter.GetXmlString()); + + oContent.Registration(type().OverrideType(), oDirectory, oFilePath.GetFilename()); + } + const OOX::FileType CXmlMapsFile::type() const + { + return FileTypes::XmlMaps; + } + const OOX::CPath CXmlMapsFile::DefaultDirectory() const + { + return type().DefaultDirectory(); + } + const OOX::CPath CXmlMapsFile::DefaultFileName() const + { + return type().DefaultFileName(); + } + void CXmlMapsFile::fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader) + { + LONG end = pReader->GetPos() + pReader->GetRecordSize() + 4; + + while (pReader->GetPos() < end) + { + BYTE _rec = pReader->GetUChar(); + + switch (_rec) + { + case 0: + { + m_MapInfo.Init(); + m_MapInfo->fromPPTY(pReader); + }break; + default: + { + pReader->SkipRecord(); + }break; + } + } + pReader->Seek(end); + } + void CXmlMapsFile::toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) + { + smart_ptr rels_old = pWriter->GetRels(); + pWriter->SetRels(dynamic_cast((CMapInfo*)this)); + + pWriter->WriteRecord2(0, m_MapInfo); + + pWriter->SetRels(rels_old); + } +//-------------------------------------------------------------------------------------------------------------- + EElementType CMapInfo::getType() const + { + return et_x_MapInfo; + } + void CMapInfo::ReadAttributes(XmlUtils::CXmlLiteReader& oReader) + { + WritingElement_ReadAttributes_StartChar_No_NS(oReader) + WritingElement_ReadAttributes_Read_ifChar(oReader, "SelectionNamespaces", SelectionNamespaces) + WritingElement_ReadAttributes_EndChar_No_NS(oReader) + } + void CMapInfo::fromXML(XmlUtils::CXmlLiteReader& oReader) + { + ReadAttributes(oReader); + if (oReader.IsEmptyNode()) + return; + + int nParentDepth = oReader.GetDepth(); + while (oReader.ReadNextSiblingNode(nParentDepth)) + { + std::wstring sName = oReader.GetNameNoNS(); + + OOX::Spreadsheet::WritingElement* pItem = NULL; + if (L"Schema" == sName) + { + pItem = new OOX::Spreadsheet::CSchema(); + } + else if (L"Map" == sName) + { + pItem = new OOX::Spreadsheet::CMap(); + } + if (pItem) + { + pItem->fromXML(oReader); + m_arrItems.push_back(pItem); + } + } + } + void CMapInfo::toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const + { + pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeStart); + pWriter->WriteString2(0, SelectionNamespaces); + pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeEnd); + + for (size_t i = 0; i < m_arrItems.size(); ++i) + { + int type = 0xff; //todooo predefine type for ??? + switch (m_arrItems[i]->getType()) + { + case et_x_Schema: type = 0; break; + case et_x_Map: type = 1; break; + } + if (type != 0xff) + pWriter->WriteRecord2(type, dynamic_cast(m_arrItems[i])); + } + } + void CMapInfo::fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader) + { + LONG _end_rec = pReader->GetPos() + pReader->GetRecordSize() + 4; + pReader->Skip(1); // start attributes + while (true) + { + BYTE _at = pReader->GetUChar_TypeNode(); + if (_at == NSBinPptxRW::g_nodeAttributeEnd) + break; + switch (_at) + { + case 0: + { + SelectionNamespaces = pReader->GetString2(); + }break; + } + } + while (pReader->GetPos() < _end_rec) + { + BYTE _rec = pReader->GetUChar(); + switch (_rec) + { + case 0: + { + m_arrItems.push_back(new CSchema()); + m_arrItems.back()->fromPPTY(pReader); + }break; + case 1: + { + m_arrItems.push_back(new CMap()); + m_arrItems.back()->fromPPTY(pReader); + }break; + default: + { + pReader->SkipRecord(); + }break; + } + } + pReader->Seek(_end_rec); + } + void CMapInfo::toXmlWriter(NSBinPptxRW::CXmlWriter * pWriter) const + { + pWriter->StartNode(L"MapInfo"); + pWriter->StartAttributes(); + pWriter->WriteAttribute2(L"xmlns", L"http://schemas.openxmlformats.org/spreadsheetml/2006/main"); + pWriter->WriteAttribute2(L"SelectionNamespaces", SelectionNamespaces); + pWriter->EndAttributes(); + + for (size_t i = 0; i < m_arrItems.size(); ++i) + m_arrItems[i]->toXmlWriter(pWriter); + + pWriter->WriteNodeEnd(L"MapInfo"); + } + EElementType CMap::getType() const + { + return et_x_Map; + } + void CMap::ReadAttributes(XmlUtils::CXmlLiteReader& oReader) + { + WritingElement_ReadAttributes_StartChar_No_NS(oReader) + WritingElement_ReadAttributes_Read_ifChar(oReader, "ID", ID) + WritingElement_ReadAttributes_Read_else_ifChar(oReader, "Name", Name) + WritingElement_ReadAttributes_Read_else_ifChar(oReader, "RootElement", RootElement) + WritingElement_ReadAttributes_Read_else_ifChar(oReader, "SchemaID", SchemaID) + WritingElement_ReadAttributes_Read_else_ifChar(oReader, "ShowImportExportValidationErrors", ShowImportExportValidationErrors) + WritingElement_ReadAttributes_Read_else_ifChar(oReader, "AutoFit", AutoFit) + WritingElement_ReadAttributes_Read_else_ifChar(oReader, "Append", Append) + WritingElement_ReadAttributes_Read_else_ifChar(oReader, "PreserveSortAFLayout", PreserveSortAFLayout) + WritingElement_ReadAttributes_Read_else_ifChar(oReader, "PreserveFormat", PreserveFormat) + WritingElement_ReadAttributes_EndChar_No_NS(oReader) + } + void CMap::fromXML(XmlUtils::CXmlLiteReader& oReader) + { + ReadAttributes(oReader); + if (oReader.IsEmptyNode()) + return; + + int nParentDepth = oReader.GetDepth(); + while (oReader.ReadNextSiblingNode(nParentDepth)) + { + std::wstring sName = oReader.GetName(); + + if (L"DataBinding" == sName) + { + DataBinding = oReader; + } + } + } + void CMap::toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const + { + pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeStart); + pWriter->WriteUInt2(0, ID); + pWriter->WriteString2(1, Name); + pWriter->WriteString2(2, RootElement); + pWriter->WriteString2(3, SchemaID); + pWriter->WriteBool2(4, ShowImportExportValidationErrors); + pWriter->WriteBool2(5, AutoFit); + pWriter->WriteBool2(6, Append); + pWriter->WriteBool2(7, PreserveSortAFLayout); + pWriter->WriteBool2(8, PreserveFormat); + pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeEnd); + + pWriter->WriteRecord2(0, DataBinding); + } + void CMap::fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader) + { + LONG _end_rec = pReader->GetPos() + pReader->GetRecordSize() + 4; + pReader->Skip(1); // start attributes + while (true) + { + BYTE _at = pReader->GetUChar_TypeNode(); + if (_at == NSBinPptxRW::g_nodeAttributeEnd) + break; + switch (_at) + { + case 0: + { + ID = pReader->GetULong(); + }break; + case 1: + { + Name = pReader->GetString2(); + }break; + case 2: + { + RootElement = pReader->GetString2(); + }break; + case 3: + { + SchemaID = pReader->GetString2(); + }break; + case 4: + { + ShowImportExportValidationErrors = pReader->GetBool(); + }break; + case 5: + { + AutoFit = pReader->GetBool(); + }break; + case 6: + { + Append = pReader->GetBool(); + }break; + case 7: + { + PreserveSortAFLayout = pReader->GetBool(); + }break; + case 8: + { + PreserveFormat = pReader->GetBool(); + }break; + } + } + while (pReader->GetPos() < _end_rec) + { + BYTE _rec = pReader->GetUChar(); + switch (_rec) + { + case 0: + { + DataBinding.Init(); + DataBinding->fromPPTY(pReader); + }break; + default: + { + pReader->SkipRecord(); + }break; + } + } + pReader->Seek(_end_rec); + } + void CMap::toXmlWriter(NSBinPptxRW::CXmlWriter * pWriter) const + { + pWriter->StartNode(L"Map"); + pWriter->StartAttributes(); + pWriter->WriteAttribute2(L"ID", ID); + pWriter->WriteAttribute2(L"RootElement", RootElement); + pWriter->WriteAttribute2(L"Name", Name); + pWriter->WriteAttribute2(L"SchemaID", SchemaID); + pWriter->WriteAttribute(L"ShowImportExportValidationErrors", ShowImportExportValidationErrors); + pWriter->WriteAttribute(L"AutoFit", AutoFit); + pWriter->WriteAttribute(L"Append", Append); + pWriter->WriteAttribute(L"PreserveSortAFLayout", PreserveSortAFLayout); + pWriter->WriteAttribute(L"PreserveFormat", PreserveFormat); + pWriter->EndAttributes(); + + if (DataBinding.IsInit()) + DataBinding->toXmlWriter(pWriter); + + pWriter->WriteNodeEnd(L"Map"); + } + EElementType CDataBinding::getType() const + { + return et_x_Map; + } + void CDataBinding::ReadAttributes(XmlUtils::CXmlLiteReader& oReader) + { + WritingElement_ReadAttributes_StartChar_No_NS(oReader) + WritingElement_ReadAttributes_Read_ifChar(oReader, "ConnectionID", ConnectionID) + WritingElement_ReadAttributes_Read_else_ifChar(oReader, "DataBindingName", DataBindingName) + WritingElement_ReadAttributes_Read_else_ifChar(oReader, "FileBindingName", FileBindingName) + WritingElement_ReadAttributes_Read_else_ifChar(oReader, "SchemaID", SchemaID) + WritingElement_ReadAttributes_Read_else_ifChar(oReader, "FileBinding", FileBinding) + WritingElement_ReadAttributes_Read_else_ifChar(oReader, "DataBindingLoadMode", DataBindingLoadMode) + WritingElement_ReadAttributes_EndChar_No_NS(oReader) + } + void CDataBinding::fromXML(XmlUtils::CXmlLiteReader& oReader) + { + ReadAttributes(oReader); + if (oReader.IsEmptyNode()) + return; + + content = oReader.GetInnerXml(); + } + void CDataBinding::toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) + { + pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeStart); + pWriter->WriteUInt2(0, ConnectionID); + pWriter->WriteString2(1, DataBindingName); + pWriter->WriteString2(2, FileBindingName); + pWriter->WriteString2(3, SchemaID); + pWriter->WriteBool2(4, FileBinding); + pWriter->WriteUInt2(5, DataBindingLoadMode); + pWriter->WriteString2(6, content); + pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeEnd); + } + void CDataBinding::fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader) + { + LONG _end_rec = pReader->GetPos() + pReader->GetRecordSize() + 4; + pReader->Skip(1); // start attributes + while (true) + { + BYTE _at = pReader->GetUChar_TypeNode(); + if (_at == NSBinPptxRW::g_nodeAttributeEnd) + break; + switch (_at) + { + case 0: + { + ConnectionID = pReader->GetULong(); + }break; + case 1: + { + DataBindingName = pReader->GetString2(); + }break; + case 2: + { + FileBindingName = pReader->GetString2(); + }break; + case 3: + { + SchemaID = pReader->GetString2(); + }break; + case 4: + { + FileBinding = pReader->GetBool(); + }break; + case 5: + { + DataBindingLoadMode = pReader->GetULong(); + }break; + case 6: + { + content = pReader->GetString2(); + }break; + } + } + pReader->Seek(_end_rec); + } + void CDataBinding::toXmlWriter(NSBinPptxRW::CXmlWriter* pWriter) const + { + pWriter->StartNode(L"DataBinding"); + pWriter->StartAttributes(); + pWriter->WriteAttribute2(L"ConnectionID", ConnectionID); + pWriter->WriteAttribute2(L"DataBindingName", DataBindingName); + pWriter->WriteAttribute2(L"FileBindingName", FileBindingName); + pWriter->WriteAttribute2(L"SchemaID", SchemaID); + pWriter->WriteAttribute(L"FileBinding", FileBinding); + pWriter->WriteAttribute2(L"DataBindingLoadMode", DataBindingLoadMode); + pWriter->EndAttributes(); + + if (content.is_init()) + { + pWriter->WriteString(*content); + } + pWriter->WriteNodeEnd(L"DataBinding"); + } + EElementType CSchema::getType() const + { + return et_x_Schema; + } + void CSchema::ReadAttributes(XmlUtils::CXmlLiteReader& oReader) + { + WritingElement_ReadAttributes_StartChar_No_NS(oReader) + WritingElement_ReadAttributes_Read_ifChar(oReader, "ID", ID) + WritingElement_ReadAttributes_Read_else_ifChar(oReader, "SchemaRef", SchemaRef) + WritingElement_ReadAttributes_Read_else_ifChar(oReader, "Namespace", Namespace) + WritingElement_ReadAttributes_Read_else_ifChar(oReader, "SchemaLanguage", SchemaLanguage) + WritingElement_ReadAttributes_EndChar_No_NS(oReader) + } + void CSchema::fromXML(XmlUtils::CXmlLiteReader& oReader) + { + ReadAttributes(oReader); + if (oReader.IsEmptyNode()) + return; + + content = oReader.GetInnerXml(); + } + void CSchema::toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const + { + pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeStart); + pWriter->WriteString2(0, ID); + pWriter->WriteString2(1, SchemaRef); + pWriter->WriteString2(2, Namespace); + pWriter->WriteString2(3, SchemaLanguage); + pWriter->WriteString2(4, content); + pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeEnd); + } + void CSchema::fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader) + { + LONG _end_rec = pReader->GetPos() + pReader->GetRecordSize() + 4; + pReader->Skip(1); // start attributes + while (true) + { + BYTE _at = pReader->GetUChar_TypeNode(); + if (_at == NSBinPptxRW::g_nodeAttributeEnd) + break; + switch (_at) + { + case 0: + { + ID = pReader->GetString2(); + }break; + case 1: + { + SchemaRef = pReader->GetString2(); + }break; + case 2: + { + Namespace = pReader->GetString2(); + }break; + case 3: + { + SchemaLanguage = pReader->GetString2(); + }break; + case 4: + { + content = pReader->GetString2(); + }break; + } + } + pReader->Seek(_end_rec); + } + void CSchema::toXmlWriter(NSBinPptxRW::CXmlWriter* pWriter) const + { + pWriter->StartNode(L"Schema"); + pWriter->StartAttributes(); + pWriter->WriteAttribute2(L"ID", ID); + pWriter->WriteAttribute2(L"SchemaRef", SchemaRef); + pWriter->WriteAttribute2(L"Namespace", Namespace); + pWriter->WriteAttribute2(L"SchemaLanguage", SchemaLanguage); + pWriter->EndAttributes(); + + if (content.is_init()) + { + pWriter->WriteString(*content); + } + + pWriter->WriteNodeEnd(L"Schema"); + } +} +} // namespace OOX + diff --git a/OOXML/XlsxFormat/Workbook/CustomsXml.h b/OOXML/XlsxFormat/Workbook/CustomsXml.h new file mode 100644 index 0000000000..b077a1014d --- /dev/null +++ b/OOXML/XlsxFormat/Workbook/CustomsXml.h @@ -0,0 +1,179 @@ +/* + * (c) Copyright Ascensio System SIA 2010-2023 + * + * This program is a free software product. You can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License (AGPL) + * version 3 as published by the Free Software Foundation. In accordance with + * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect + * that Ascensio System SIA expressly excludes the warranty of non-infringement + * of any third-party rights. + * + * This program is distributed WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For + * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html + * + * You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish + * street, Riga, Latvia, EU, LV-1050. + * + * The interactive user interfaces in modified source and object code versions + * of the Program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU AGPL version 3. + * + * Pursuant to Section 7(b) of the License you must retain the original Product + * logo when distributing the program. Pursuant to Section 7(e) we decline to + * grant you any rights under trademark law for use of our trademarks. + * + * All the Product's GUI elements, including illustrations and icon sets, as + * well as technical writing content are licensed under the terms of the + * Creative Commons Attribution-ShareAlike 4.0 International. See the License + * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + * + */ +#pragma once + +#include "../Table/Autofilter.h" +#include "../../DocxFormat/IFileContainer.h" +#include "../../Common/SimpleTypes_Spreadsheet.h" + +namespace OOX +{ + namespace Spreadsheet + { + class CMapInfo : public OOX::Spreadsheet::WritingElementWithChilds<> + { + public: + WritingElement_AdditionMethods(CMapInfo) + CMapInfo() {} + virtual ~CMapInfo() {} + + virtual void fromXML(XmlUtils::CXmlNode& node) {} + virtual std::wstring toXML() const { return L""; } + virtual void toXML(NSStringUtils::CStringBuilder& writer) const {} + + virtual void fromXML(XmlUtils::CXmlLiteReader& oReader); + virtual void toXmlWriter(NSBinPptxRW::CXmlWriter* pWriter) const; + + virtual void toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const; + virtual void fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader); + + virtual EElementType getType() const; + + nullable_string SelectionNamespaces; + private: + void ReadAttributes(XmlUtils::CXmlLiteReader& oReader); + }; +//------------------------------------------------------------------------------------------------------------------------ + class CXmlMapsFile : public OOX::File + { + public: + CXmlMapsFile(OOX::Document* pMain); + CXmlMapsFile(OOX::Document* pMain, const CPath& uri); + CXmlMapsFile(OOX::Document* pMain, const CPath& oRootPath, const CPath& oPath); + virtual ~CXmlMapsFile(); + + virtual void read(const CPath& oPath); + virtual void read(const CPath& oRootPath, const CPath& oPath); + + virtual void write(const CPath& oPath, const CPath& oDirectory, CContentTypes& oContent) const; + virtual const OOX::FileType type() const; + + virtual const CPath DefaultDirectory() const; + virtual const CPath DefaultFileName() const; + + virtual void toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter); + virtual void fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader); + + const CPath& GetReadPath(); + + nullable m_MapInfo; + private: + CPath m_oReadPath; + }; + class CDataBinding : public OOX::Spreadsheet::WritingElement + { + public: + WritingElement_AdditionMethods(CDataBinding) + CDataBinding() {} + virtual ~CDataBinding() {} + + virtual void fromXML(XmlUtils::CXmlNode& node) {} + virtual std::wstring toXML() const { return L""; } + virtual void toXML(NSStringUtils::CStringBuilder& writer) const {} + + virtual void fromXML(XmlUtils::CXmlLiteReader& oReader); + virtual void toXmlWriter(NSBinPptxRW::CXmlWriter* pWriter) const; + + void ReadAttributes(XmlUtils::CXmlLiteReader& oReader); + + virtual void toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter); + virtual void fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader); + virtual EElementType getType() const; + + nullable_uint ConnectionID; + nullable_string DataBindingName; + nullable_string FileBindingName; + nullable_string SchemaID; + nullable_bool FileBinding; + nullable_uint DataBindingLoadMode; + nullable_string content; + }; + class CMap : public OOX::Spreadsheet::WritingElement + { + public: + WritingElement_AdditionMethods(CMap) + CMap() {} + virtual ~CMap() {} + + virtual void fromXML(XmlUtils::CXmlNode& node) {} + virtual std::wstring toXML() const { return L""; } + virtual void toXML(NSStringUtils::CStringBuilder& writer) const {} + + virtual void fromXML(XmlUtils::CXmlLiteReader& oReader); + virtual void toXmlWriter(NSBinPptxRW::CXmlWriter* pWriter) const; + + void ReadAttributes(XmlUtils::CXmlLiteReader& oReader); + + virtual void toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const; + virtual void fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader); + virtual EElementType getType() const; + + nullable_uint ID; + nullable_string Name; + nullable_string RootElement; + nullable_string SchemaID; + nullable_bool ShowImportExportValidationErrors; + nullable_bool AutoFit; + nullable_bool Append; + nullable_bool PreserveSortAFLayout; + nullable_bool PreserveFormat; + + nullable DataBinding; + }; + class CSchema : public OOX::Spreadsheet::WritingElement + { + public: + WritingElement_AdditionMethods(CSchema) + CSchema() {} + virtual ~CSchema() {} + + virtual void fromXML(XmlUtils::CXmlNode& node) {} + virtual std::wstring toXML() const { return L""; } + virtual void toXML(NSStringUtils::CStringBuilder& writer) const {} + + virtual void fromXML(XmlUtils::CXmlLiteReader& oReader); + virtual void toXmlWriter(NSBinPptxRW::CXmlWriter* pWriter) const; + + void ReadAttributes(XmlUtils::CXmlLiteReader& oReader); + + virtual void toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const; + virtual void fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader); + virtual EElementType getType() const; + + nullable_string ID; + nullable_string SchemaRef; + nullable_string Namespace; + nullable_string SchemaLanguage; + nullable_string content; + }; + } //Spreadsheet +} // namespace OOX