Commit 65254b57 authored by ElenaSubbotina's avatar ElenaSubbotina

Merge branch 'develop' of https://github.com/ONLYOFFICE/core into develop

parents 95899e23 5c8757d3
......@@ -246,4 +246,7 @@ HEADERS += docxformatlib.h \
../Source/XlsxFormat/Worksheets/Sparkline.h \
../Source/XlsxFormat/Ole/OleObjects.h \
../Source/DocxFormat/Diagram/DiagramData.h \
../Source/DocxFormat/Diagram/DiagramDrawing.h
../Source/DocxFormat/Diagram/DiagramDrawing.h \
../Source/XlsxFormat/Pivot/PivotTable.h \
../Source/XlsxFormat/Pivot/PivotCacheDefinition.h \
../Source/XlsxFormat/Pivot/PivotCacheRecords.h
......@@ -110,9 +110,11 @@ namespace OOX
OOX::CPath oName = pFile->DefaultFileName();
if(false == pFile->m_sOutputFilename.empty())
oName.SetName(pFile->m_sOutputFilename, false);
OOX::CSystemUtility::CreateDirectories( oCurrent / oDefDir );
pFile->write( oCurrent / oDefDir / oName, oDir / oDefDir, oContent );
if(m_mNoWriteContainer.end() == m_mNoWriteContainer.find(pPair->first))
{
OOX::CSystemUtility::CreateDirectories( oCurrent / oDefDir );
pFile->write( oCurrent / oDefDir / oName, oDir / oDefDir, oContent );
}
if(true != pFile->m_bDoNotAddRels)
{
if (oDefDir.GetPath().length() > 0)//todooo перенести в CPath
......@@ -187,16 +189,18 @@ namespace OOX
mNamepair [oName.m_strFilename] = 1;
else
oName = oName + pNamePair->first;
OOX::CSystemUtility::CreateDirectories( oCurrent / oDefDir );
smart_ptr<OOX::IFileBuilder> pFileBuilder = pFile.smart_dynamic_cast<OOX::IFileBuilder>();
if ( pFileBuilder.is_init() )
if(m_mNoWriteContainer.end() == m_mNoWriteContainer.find(it->first))
{
pFileBuilder->Finalize( oCurrent / oDefDir / oName, oDir / oDefDir, oContent );
}
else
{
pFile->write( oCurrent / oDefDir / oName, oDir / oDefDir, oContent );
OOX::CSystemUtility::CreateDirectories( oCurrent / oDefDir );
smart_ptr<OOX::IFileBuilder> pFileBuilder = pFile.smart_dynamic_cast<OOX::IFileBuilder>();
if ( pFileBuilder.is_init() )
{
pFileBuilder->Finalize( oCurrent / oDefDir / oName, oDir / oDefDir, oContent );
}
else
{
pFile->write( oCurrent / oDefDir / oName, oDir / oDefDir, oContent );
}
}
oRels.Registration( it->first, pFile->type(), oDefDir / oName );
......@@ -386,6 +390,20 @@ namespace OOX
m_mContainer [rId.get()] = pFile;
}
const RId IFileContainer::AddNoWrite(const smart_ptr<OOX::File>& pFile)
{
const RId rId = GetMaxRId().next();
AddNoWrite( rId, pFile );
return rId;
}
void IFileContainer::AddNoWrite (const OOX::RId& rId, const smart_ptr<OOX::File>& pFile)
{
m_lMaxRid = (std::max)( m_lMaxRid, rId.getNumber() );
m_mContainer [rId.get()] = pFile;
m_mNoWriteContainer[rId.get()] = true;
}
smart_ptr<OOX::File> IFileContainer::Find(const FileType& oType) const
{
for (std::map<std::wstring, smart_ptr<OOX::File>>::const_iterator pPair = m_mContainer.begin(); pPair != m_mContainer.end(); ++pPair)
......
......@@ -67,6 +67,7 @@ namespace OOX
static std::map<std::wstring, size_t> m_mapEnumeratedGlobal;
protected:
std::map<std::wstring, smart_ptr<OOX::File>> m_mContainer;
std::map<std::wstring, bool> m_mNoWriteContainer;
size_t m_lMaxRid;
void Read (const OOX::CRels& oRels, const OOX::CPath& oRootPath, const CPath& oPath);
......@@ -103,6 +104,8 @@ namespace OOX
const RId Add(smart_ptr<OOX::File>& pFile);
void Add(const OOX::RId& rId, smart_ptr<OOX::File>& pFile);
const RId AddNoWrite(const smart_ptr<OOX::File>& pFile);
void AddNoWrite(const OOX::RId& rId, const smart_ptr<OOX::File>& pFile);
template<typename T>
T& Find();
......
......@@ -81,6 +81,18 @@ namespace OOX
const FileType ExternalLinks (L"externalLinks", L"externalLink.xml",
_T("application/vnd.openxmlformats-officedocument.spreadsheetml.externalLink+xml"),
_T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/externalLink"), true, true);
const FileType PivotTable (L"../pivotTables", L"pivotTable.xml",
_T("application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml"),
_T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotTable"), true, true);
const FileType PivotCacheDefinition(L"pivotCache", L"pivotCacheDefinition.xml",
_T("application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml"),
_T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition"), true);
const FileType PivotCacheRecords(L"", L"pivotCacheRecords.xml",
_T("application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheRecords+xml"),
_T("http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheRecords"), true, true);
} // namespace FileTypes
......
/*
* (c) Copyright Ascensio System SIA 2010-2017
*
* 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 Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* 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
#ifndef OOX_PIVOTCACHEDEFINITION_FILE_INCLUDE_H_
#define OOX_PIVOTCACHEDEFINITION_FILE_INCLUDE_H_
#include "../CommonInclude.h"
namespace OOX
{
namespace Spreadsheet
{
class CPivotCacheDefinition : public OOX::File, public OOX::IFileContainer
{
public:
CPivotCacheDefinition()
{
m_bSpreadsheets = true;
bIsWritten = false;
m_pData = NULL;
m_nDataLength = 0;
}
CPivotCacheDefinition(const CPath& oRootPath, const CPath& oPath)
{
m_bSpreadsheets = true;
bIsWritten = false;
m_pData = NULL;
m_nDataLength = 0;
read( oRootPath, oPath );
}
virtual ~CPivotCacheDefinition()
{
ClearItems();
}
public:
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
{
if(m_nDataLength > 0 && !bIsWritten)
{
NSFile::CFileBinary oFile;
oFile.CreateFileW(oPath.GetPath());
oFile.WriteFile(m_pData, m_nDataLength);
oFile.CloseFile();
oContent.Registration( type().OverrideType(), oDirectory, oPath.GetFilename() );
IFileContainer::Write( oPath, oDirectory, oContent );
//prevent repeated write
bIsWritten = true;
}
}
virtual const OOX::FileType type() const
{
return OOX::Spreadsheet::FileTypes::PivotCacheDefinition;
}
virtual const CPath DefaultDirectory() const
{
return type().DefaultDirectory();
}
virtual const CPath DefaultFileName() const
{
return type().DefaultFileName();
}
const CPath& GetReadPath()
{
return m_oReadPath;
}
void setData(BYTE* pData, long length, const std::wstring& srIdRecords)
{
if(srIdRecords.length() > 0)
{
const std::string srIdRecordsA( srIdRecords.begin(), srIdRecords.end() );
std::string rIdAttr = " r:id=\""+ srIdRecordsA +"\"";
m_nDataLength = length + rIdAttr.length();
m_pData = new BYTE[m_nDataLength];
long nTreshold = 220;
memcpy(m_pData, pData, nTreshold);
memcpy(m_pData + nTreshold, rIdAttr.c_str(), rIdAttr.length());
memcpy(m_pData + nTreshold + rIdAttr.length(), pData + nTreshold, length - nTreshold);
}
else
{
m_nDataLength = length;
memcpy(m_pData, pData, length);
}
}
private:
CPath m_oReadPath;
void ClearItems()
{
m_nDataLength = 0;
RELEASEARRAYOBJECTS(m_pData)
}
public:
mutable bool bIsWritten;
BYTE* m_pData;
long m_nDataLength;
};
} //Spreadsheet
} // namespace OOX
#endif // OOX_PIVOTCACHEDEFINITION_FILE_INCLUDE_H_
/*
* (c) Copyright Ascensio System SIA 2010-2017
*
* 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 Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* 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
#ifndef OOX_PIVOTCACHERECORDS_FILE_INCLUDE_H_
#define OOX_PIVOTCACHERECORDS_FILE_INCLUDE_H_
#include "../CommonInclude.h"
namespace OOX
{
namespace Spreadsheet
{
class CPivotCacheRecords : public OOX::File, public OOX::IFileContainer
{
public:
CPivotCacheRecords()
{
m_bSpreadsheets = true;
m_pData = NULL;
m_nDataLength = 0;
}
CPivotCacheRecords(const CPath& oRootPath, const CPath& oPath)
{
m_bSpreadsheets = true;
m_pData = NULL;
m_nDataLength = 0;
read( oRootPath, oPath );
}
virtual ~CPivotCacheRecords()
{
ClearItems();
}
public:
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
{
if(m_nDataLength > 0)
{
NSFile::CFileBinary oFile;
oFile.CreateFileW(oPath.GetPath());
oFile.WriteFile(m_pData, m_nDataLength);
oFile.CloseFile();
oContent.Registration(type().OverrideType(), oDirectory, oPath.GetFilename());
oContent.Registration( type().OverrideType(), oDirectory, oPath.GetFilename() );
IFileContainer::Write( oPath, oDirectory, oContent );
}
}
virtual const OOX::FileType type() const
{
return OOX::Spreadsheet::FileTypes::PivotCacheRecords;
}
virtual const CPath DefaultDirectory() const
{
return type().DefaultDirectory();
}
virtual const CPath DefaultFileName() const
{
return type().DefaultFileName();
}
const CPath& GetReadPath()
{
return m_oReadPath;
}
void setData(BYTE* pData, long length)
{
m_nDataLength = length;
m_pData = new BYTE[length];
memcpy(m_pData, pData, length);
}
private:
CPath m_oReadPath;
void ClearItems()
{
m_nDataLength = 0;
RELEASEARRAYOBJECTS(m_pData)
}
public:
BYTE* m_pData;
long m_nDataLength;
};
} //Spreadsheet
} // namespace OOX
#endif // OOX_PIVOTCACHERECORDS_FILE_INCLUDE_H_
/*
* (c) Copyright Ascensio System SIA 2010-2017
*
* 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 Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* 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
#ifndef OOX_PIVOTTABLE_FILE_INCLUDE_H_
#define OOX_PIVOTTABLE_FILE_INCLUDE_H_
#include "../CommonInclude.h"
namespace OOX
{
namespace Spreadsheet
{
class CPivotTable : public OOX::File, public OOX::IFileContainer
{
public:
CPivotTable()
{
m_bSpreadsheets = true;
m_pData = NULL;
m_nDataLength = 0;
}
CPivotTable(const CPath& oRootPath, const CPath& oPath)
{
m_bSpreadsheets = true;
m_pData = NULL;
m_nDataLength = 0;
read( oRootPath, oPath );
}
virtual ~CPivotTable()
{
ClearItems();
}
public:
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
{
if(m_nDataLength > 0)
{
NSFile::CFileBinary oFile;
oFile.CreateFileW(oPath.GetPath());
oFile.WriteFile(m_pData, m_nDataLength);
oFile.CloseFile();
oContent.Registration( type().OverrideType(), oDirectory, oPath.GetFilename() );
IFileContainer::Write( oPath, oDirectory, oContent );
}
}
virtual const OOX::FileType type() const
{
return OOX::Spreadsheet::FileTypes::PivotTable;
}
virtual const CPath DefaultDirectory() const
{
return type().DefaultDirectory();
}
virtual const CPath DefaultFileName() const
{
return type().DefaultFileName();
}
const CPath& GetReadPath()
{
return m_oReadPath;
}
void setData(BYTE* pData, long length)
{
m_nDataLength = length;
m_pData = new BYTE[length];
memcpy(m_pData, pData, length);
}
private:
CPath m_oReadPath;
void ClearItems()
{
m_nDataLength = 0;
RELEASEARRAYOBJECTS(m_pData)
}
public:
BYTE* m_pData;
long m_nDataLength;
};
} //Spreadsheet
} // namespace OOX
#endif // OOX_PIVOTTABLE_FILE_INCLUDE_H_
......@@ -137,6 +137,8 @@ namespace OOX
m_oDefinedNames->toXML(sXml);
sXml.WriteString(_T("<calcPr calcId=\"145621\"/>"));
if(m_oPivotCachesXml.IsInit())
sXml.WriteString(m_oPivotCachesXml.get());
sXml.WriteString(_T("</workbook>"));
std::wstring sPath = oPath.GetPath();
......@@ -208,7 +210,7 @@ namespace OOX
nullable<OOX::Spreadsheet::CSheets> m_oSheets;
nullable<OOX::Spreadsheet::CWorkbookPr> m_oWorkbookPr;
nullable<OOX::Spreadsheet::CExternalReferences> m_oExternalReferences;
nullable<std::wstring> m_oPivotCachesXml;
};
} //Spreadsheet
} // namespace OOX
......
......@@ -47,6 +47,9 @@
#include "CalcChain/CalcChain.h"
#include "ExternalLinks/ExternalLinks.h"
#include "ExternalLinks/ExternalLinkPath.h"
#include "Pivot/PivotTable.h"
#include "Pivot/PivotCacheDefinition.h"
#include "Pivot/PivotCacheRecords.h"
#include "../../../DesktopEditor/common/Directory.h"
......
......@@ -122,13 +122,13 @@ namespace codegen
sb.AppendFormat("function {0}(){{\r\n", oGenClass.sName);
ProcessProperty(sb, aAttributes, aMembers, bNeedTextNode, bNeedDoubleArray);
sb.AppendFormat("}}\r\n", oGenClass.sName);
sb.AppendFormat("}}\r\n");
if (aAttributes.Count > 0)
{
sb.AppendFormat("{0}.prototype.readAttributes = function(attr, uq) {{\r\n", oGenClass.sName);
ProcessAttributesFromXml(sb, oGenClass, aAttributes);
sb.AppendFormat("}};\r\n", oGenClass.sName);
sb.AppendFormat("}};\r\n");
}
if (aMembers.Count > 0)
{
......@@ -144,19 +144,19 @@ namespace codegen
sb.AppendFormat("newContext = null;\r\n");
sb.AppendFormat("}}\r\n");
sb.AppendFormat("return newContext;\r\n");
sb.AppendFormat("}};\r\n", oGenClass.sName);
sb.AppendFormat("}};\r\n");
if (bNeedTextNode)
{
sb.AppendFormat("{0}.prototype.onTextNode = function(text, uq) {{\r\n", oGenClass.sName);
ProcessOnTextNodeFromXml(sb, oGenClass, aMembers);
sb.AppendFormat("}};\r\n", oGenClass.sName);
sb.AppendFormat("}};\r\n");
}
if (bNeedDoubleArray)
{
sb.AppendFormat("{0}.prototype.onEndNode = function(prevContext, elem) {{\r\n", oGenClass.sName);
ProcessOnEndNodeFromXml(sb, oGenClass, aMembers);
sb.AppendFormat("}};\r\n", oGenClass.sName);
sb.AppendFormat("}};\r\n");
}
}
if (aAttributes.Count > 0 || aMembers.Count > 0)
......@@ -302,7 +302,9 @@ namespace codegen
if (!string.IsNullOrEmpty(sName))
{
sb.AppendFormat("if(\"{0}\" === {1}){{\r\n", sName, sCodeName);
sb.AppendFormat("newContext.readAttributes(attr, uq);\r\n", sName, sCodeName);
sb.AppendFormat("if(newContext.readAttributes){{\r\n");
sb.AppendFormat("newContext.readAttributes(attr, uq);\r\n");
sb.AppendFormat("}}\r\n");
sb.AppendFormat("}}\r\n", sName, sCodeName);
return true;
}
......@@ -328,8 +330,8 @@ namespace codegen
else
{
sb.AppendFormat("//todo check name duplication\r\n", getNameWithPrefix(oGenClass, oGenMember), sCodeName);
sb.AppendFormat("this.{0} = [];\r\n", oGenMember.sName);
}
sb.AppendFormat("this.{0} = [];\r\n", oGenMember.sName);
sb.AppendFormat("}}\r\n", getNameWithPrefix(oGenClass, oGenMember), sCodeName);
nCounter++;
}
......@@ -481,6 +483,9 @@ namespace codegen
sb.AppendFormat("else ");
sb.AppendFormat("if(\"{0}\" === elem){{\r\n", getNameWithPrefix(oGenClass, oGenMember));
sb.AppendFormat("if(this._curArray && this._curArray.length > 0){{\r\n");
sb.AppendFormat("if(!this.{0}){{\r\n", oGenMember.sName);
sb.AppendFormat("this.{0} = [];\r\n", oGenMember.sName);
sb.AppendFormat("}}\r\n");
sb.AppendFormat("this.{0}.push(this._curArray);\r\n", oGenMember.sName);
sb.AppendFormat("this._curArray = null;\r\n");
sb.AppendFormat("}}\r\n");
......@@ -586,29 +591,25 @@ namespace codegen
{
GenMemberPivot oGenMember = aMembers[i];
bool bNullCheck = true;
string sCodeElem;
string sCodeElem = "this." + oGenMember.sName;
if (oGenMember.nArrayRank > 0)
{
if (false == oGenMember.bIsArrayTypesHidden)
{
sb.AppendFormat("if(null !== {0}){{\r\n", oGenMember.sName);
sb.AppendFormat("if(null !== {0}){{\r\n", sCodeElem);
}
sb.AppendFormat("for(var i = 0; i < this.{0}.length; ++i){{\r\n", oGenMember.sName);
sb.AppendFormat("var elem = this.{0}[i];\r\n", oGenMember.sName);
sb.AppendFormat("for(var i = 0; i < {0}.length; ++i){{\r\n", sCodeElem);
sb.AppendFormat("var elem = {0}[i];\r\n", sCodeElem);
sCodeElem = "elem";
bNullCheck = false;
}
else
{
sCodeElem = "this." + oGenMember.sName;
}
if (null != oGenMember.aArrayTypes)
{
if (false == oGenMember.bIsArrayTypesHidden)
{
if (bNullCheck)
sb.AppendFormat("if(null !== {0}){{\r\n", sCodeElem);
sb.AppendFormat("writer.WriteXmlNodeEnd(\"{0}\", true);\r\n", getNameWithPrefix(oGenClass, oGenMember));
sb.AppendFormat("writer.WriteXmlNodeStart(\"{0}\", true);\r\n", getNameWithPrefix(oGenClass, oGenMember));
}
if (oGenMember.nArrayRank.HasValue)
{
......@@ -669,7 +670,7 @@ namespace codegen
sb.AppendFormat("}}\r\n");
if (false == oGenMember.bIsArrayTypesHidden)
{
sb.AppendFormat("}}\r\n", oGenMember.sName);
sb.AppendFormat("}}\r\n");
}
}
}
......@@ -756,12 +757,12 @@ namespace codegen
default:
if (bAttribute)
{
sb.AppendFormat("writer.WriteXmlAttributeString(\"{0}\", {1});\r\n", sName, sVal);
sb.AppendFormat("writer.WriteXmlAttributeStringEncode(\"{0}\", {1});\r\n", sName, sVal);
}
else
{
sb.AppendFormat("writer.WriteXmlNodeStart(\"{0}\", true);\r\n", sName);
sb.AppendFormat("writer.WriteXmlString({0});\r\n", sVal);
sb.AppendFormat("writer.WriteXmlStringEncode({0});\r\n", sVal);
sb.AppendFormat("writer.WriteXmlNodeEnd(\"{0}\");\r\n", sName);
}
break;
......
......@@ -45,10 +45,35 @@ namespace TestDocsWithChart
{
static void Main(string[] args)
{
getFilesAlternateContent();
getFilesPivot();
//getFilesAlternateContent();
//getFiles();
//convertFiles();
}
static void getFilesPivot()
{
string sDirInput = @"\\192.168.3.208\allusers\Files\XLSX";
string sDirOutput = @"D:\Files\Pivot";
String[] allfiles = System.IO.Directory.GetFiles(sDirInput, "*.*", System.IO.SearchOption.AllDirectories);
for (var i = 0; i < allfiles.Length; ++i)
{
string file = allfiles[i];
try
{
ZipArchive zip = ZipFile.OpenRead(file);
foreach (ZipArchiveEntry entry in zip.Entries)
{
if (-1 != entry.FullName.IndexOf("pivotTable", StringComparison.OrdinalIgnoreCase))
{
System.IO.File.Copy(file, Path.Combine(sDirOutput, Path.GetFileName(file)), true);
break;
}
}
}
catch { }
}
}
static void getFilesAlternateContent()
{
string sAlternateContent = ":Choice ";
......
......@@ -185,8 +185,9 @@ namespace BinXlsxRW
DefinedNames = 3,
DefinedName = 4,
ExternalReferences = 5,
ExternalReference = 6
ExternalReference = 6,
PivotCaches = 7,
PivotCache = 8
};}
namespace c_oSerWorkbookPrTypes{enum c_oSerWorkbookPrTypes
{
......@@ -232,7 +233,8 @@ namespace BinXlsxRW
SheetViews = 22,
SheetView = 23,
SheetPr = 24,
SparklineGroups = 25
SparklineGroups = 25,
PivotTable = 26
};}
namespace c_oSerWorksheetPropTypes{enum c_oSerWorksheetPropTypes
{
......@@ -809,6 +811,14 @@ namespace BinXlsxRW
AltText = 0,
AltTextSummary = 1
};}
namespace c_oSer_PivotTypes{enum c_oSerPivotTypes
{
id = 0,
cache = 1,
record = 2,
cacheId = 3,
table = 4
};}
}
#endif //
......@@ -64,6 +64,27 @@ namespace BinXlsxRW {
nIndex = _nIndex;
}
};
class PivotCachesTemp
{
public:
long nId;
BYTE* pDefinitionData;
long nDefinitionLength;
OOX::Spreadsheet::CPivotCacheRecords* pRecords;
long nCacheId;
OOX::Spreadsheet::CPivotTable* pTable;
public:
PivotCachesTemp()
{
nId = -1;
pDefinitionData = NULL;
nDefinitionLength = 0;
pRecords = NULL;
nCacheId = -1;
pTable = NULL;
}
};
class Binary_CommonReader2
{
protected:
......@@ -1477,8 +1498,9 @@ namespace BinXlsxRW {
class BinaryWorkbookTableReader : public Binary_CommonReader<BinaryWorkbookTableReader>
{
OOX::Spreadsheet::CWorkbook& m_oWorkbook;
std::map<long, NSCommon::smart_ptr<OOX::File>>& m_mapPivotCacheDefinitions;
public:
BinaryWorkbookTableReader(NSBinPptxRW::CBinaryFileReader& oBufferedStream, OOX::Spreadsheet::CWorkbook& oWorkbook):Binary_CommonReader(oBufferedStream), m_oWorkbook(oWorkbook)
BinaryWorkbookTableReader(NSBinPptxRW::CBinaryFileReader& oBufferedStream, OOX::Spreadsheet::CWorkbook& oWorkbook, std::map<long, NSCommon::smart_ptr<OOX::File>>& mapPivotCacheDefinitions):Binary_CommonReader(oBufferedStream), m_oWorkbook(oWorkbook), m_mapPivotCacheDefinitions(mapPivotCacheDefinitions)
{
}
int Read()
......@@ -1508,6 +1530,13 @@ namespace BinXlsxRW {
m_oWorkbook.m_oExternalReferences.Init();
res = Read1(length, &BinaryWorkbookTableReader::ReadExternalReferences, this, poResult);
}
else if(c_oSerWorkbookTypes::PivotCaches == type)
{
m_oWorkbook.m_oPivotCachesXml.Init();
m_oWorkbook.m_oPivotCachesXml->append(L"<pivotCaches>");
res = Read1(length, &BinaryWorkbookTableReader::ReadPivotCaches, this, poResult);
m_oWorkbook.m_oPivotCachesXml->append(L"</pivotCaches>");
}
else
res = c_oSerConstants::ReadUnknown;
return res;
......@@ -1633,7 +1662,67 @@ namespace BinXlsxRW {
{
pDefinedName->m_oComment.Init();
pDefinedName->m_oComment->append(m_oBufferedStream.GetString4(length));
}
}
else
res = c_oSerConstants::ReadUnknown;
return res;
};
int ReadPivotCaches(BYTE type, long length, void* poResult)
{
int res = c_oSerConstants::ReadOk;
if(c_oSerWorkbookTypes::PivotCache == type)
{
PivotCachesTemp oPivotCachesTemp;
res = Read1(length, &BinaryWorkbookTableReader::ReadPivotCache, this, &oPivotCachesTemp);
if(-1 != oPivotCachesTemp.nId && NULL != oPivotCachesTemp.pDefinitionData)
{
OOX::Spreadsheet::CPivotCacheDefinition* pDefinition = new OOX::Spreadsheet::CPivotCacheDefinition();
std::wstring srIdRecords;
if(NULL != oPivotCachesTemp.pRecords)
{
NSCommon::smart_ptr<OOX::File> pFileRecords(oPivotCachesTemp.pRecords);
srIdRecords = pDefinition->Add(pFileRecords).ToString();
}
pDefinition->setData(oPivotCachesTemp.pDefinitionData, oPivotCachesTemp.nDefinitionLength, srIdRecords);
NSCommon::smart_ptr<OOX::File> pFileDefinition(pDefinition);
OOX::RId rIdDefinition = m_oWorkbook.Add(pFileDefinition);
m_oWorkbook.m_oPivotCachesXml->append(L"<pivotCache cacheId=\"");
m_oWorkbook.m_oPivotCachesXml->append(std::to_wstring(oPivotCachesTemp.nId));
m_oWorkbook.m_oPivotCachesXml->append(L"\" r:id=\"");
m_oWorkbook.m_oPivotCachesXml->append(rIdDefinition.ToString());
m_oWorkbook.m_oPivotCachesXml->append(L"\"/>");
m_mapPivotCacheDefinitions[oPivotCachesTemp.nId] = pFileDefinition;
}
else
{
RELEASEOBJECT(oPivotCachesTemp.pRecords);
}
}
else
res = c_oSerConstants::ReadUnknown;
return res;
};
int ReadPivotCache(BYTE type, long length, void* poResult)
{
PivotCachesTemp* pPivotCachesTemp = static_cast<PivotCachesTemp*>(poResult);
int res = c_oSerConstants::ReadOk;
if(c_oSer_PivotTypes::id == type)
{
pPivotCachesTemp->nId = m_oBufferedStream.GetLong();
}
else if(c_oSer_PivotTypes::cache == type)
{
pPivotCachesTemp->pDefinitionData = m_oBufferedStream.GetPointer(length);
pPivotCachesTemp->nDefinitionLength = length;
}
else if(c_oSer_PivotTypes::record == type)
{
pPivotCachesTemp->pRecords = new OOX::Spreadsheet::CPivotCacheRecords();
pPivotCachesTemp->pRecords->setData(m_oBufferedStream.GetPointer(length), length);
}
else
res = c_oSerConstants::ReadUnknown;
return res;
};
};
......@@ -1876,14 +1965,15 @@ namespace BinXlsxRW {
NSBinPptxRW::CDrawingConverter* m_pOfficeDrawingConverter;
std::map<std::wstring, OOX::Spreadsheet::CWorksheet*>& m_mapWorksheets;
std::map<long, NSCommon::smart_ptr<OOX::File>>& m_mapPivotCacheDefinitions;
public:
BinaryWorksheetsTableReader(NSBinPptxRW::CBinaryFileReader& oBufferedStream, OOX::Spreadsheet::CWorkbook& oWorkbook,
OOX::Spreadsheet::CSharedStrings* pSharedStrings, std::map<std::wstring, OOX::Spreadsheet::CWorksheet*>& mapWorksheets,
std::map<long, ImageObject*>& mapMedia, const std::wstring& sDestinationDir, const std::wstring& sMediaDir, SaveParams& oSaveParams,
NSBinPptxRW::CDrawingConverter* pOfficeDrawingConverter)
NSBinPptxRW::CDrawingConverter* pOfficeDrawingConverter, std::map<long, NSCommon::smart_ptr<OOX::File>>& mapPivotCacheDefinitions)
: Binary_CommonReader(oBufferedStream), m_oWorkbook(oWorkbook), m_oBcr2(oBufferedStream), m_sMediaDir(sMediaDir), m_oSaveParams(oSaveParams),
m_mapMedia(mapMedia), m_sDestinationDir(sDestinationDir), m_mapWorksheets(mapWorksheets), m_pSharedStrings(pSharedStrings)
m_mapMedia(mapMedia), m_sDestinationDir(sDestinationDir), m_mapWorksheets(mapWorksheets), m_pSharedStrings(pSharedStrings),m_mapPivotCacheDefinitions(mapPivotCacheDefinitions)
{
m_pCurSheet = NULL;
m_pCurWorksheet = NULL;
......@@ -2110,10 +2200,45 @@ namespace BinXlsxRW {
m_pCurWorksheet->m_oExtLst.Init();
m_pCurWorksheet->m_oExtLst->m_arrExt.push_back(pOfficeArtExtension);
}
else if(c_oSerWorksheetsTypes::PivotTable == type)
{
PivotCachesTemp oPivotCachesTemp;
res = Read1(length, &BinaryWorksheetsTableReader::ReadPivotTable, this, &oPivotCachesTemp);
std::map<long, NSCommon::smart_ptr<OOX::File>>::const_iterator pair = m_mapPivotCacheDefinitions.find(oPivotCachesTemp.nCacheId);
if(m_mapPivotCacheDefinitions.end() != pair && NULL != oPivotCachesTemp.pTable)
{
NSCommon::smart_ptr<OOX::File> pFileTable(oPivotCachesTemp.pTable);
oPivotCachesTemp.pTable->AddNoWrite(pair->second);
m_pCurWorksheet->Add(pFileTable);
}
else
{
RELEASEOBJECT(oPivotCachesTemp.pTable);
}
}
else
res = c_oSerConstants::ReadUnknown;
return res;
}
int ReadPivotTable(BYTE type, long length, void* poResult)
{
PivotCachesTemp* pPivotCachesTemp = static_cast<PivotCachesTemp*>(poResult);
int res = c_oSerConstants::ReadOk;
if(c_oSer_PivotTypes::cacheId == type)
{
pPivotCachesTemp->nCacheId =m_oBufferedStream.GetLong();
}
else if(c_oSer_PivotTypes::table == type)
{
OOX::Spreadsheet::CPivotTable* pPivotTable = new OOX::Spreadsheet::CPivotTable();
pPivotTable->setData(m_oBufferedStream.GetPointer(length), length);
pPivotCachesTemp->pTable = pPivotTable;
}
else
res = c_oSerConstants::ReadUnknown;
return res;
}
int ReadWorksheetProp(BYTE type, long length, void* poResult)
{
int res = c_oSerConstants::ReadOk;
......@@ -3841,6 +3966,7 @@ namespace BinXlsxRW {
std::vector<long> aOffBits;
long nOtherOffBits = -1;
long nSharedStringsOffBits = -1;
long nWorkbookOffBits = -1;
BYTE mtLen = oBufferedStream.GetUChar();
for(int i = 0; i < mtLen; ++i)
......@@ -3855,6 +3981,8 @@ namespace BinXlsxRW {
nOtherOffBits = mtiOffBits;
else if(c_oSerTableTypes::SharedStrings == mtiType)
nSharedStringsOffBits = mtiOffBits;
else if(c_oSerTableTypes::Workbook == mtiType)
nWorkbookOffBits = mtiOffBits;
else
{
aTypes.push_back(mtiType);
......@@ -3883,8 +4011,16 @@ namespace BinXlsxRW {
if(c_oSerConstants::ReadOk != res)
return res;
}
OOX::Spreadsheet::CWorkbook* pWorkbook = oXlsx.CreateWorkbook();
std::map<long, NSCommon::smart_ptr<OOX::File>> m_mapPivotCacheDefinitions;
if(-1 != nWorkbookOffBits)
{
oBufferedStream.Seek(nWorkbookOffBits);
res = BinaryWorkbookTableReader(oBufferedStream, *pWorkbook, m_mapPivotCacheDefinitions).Read();
if(c_oSerConstants::ReadOk != res)
return res;
}
for(size_t i = 0, length = aTypes.size(); i < length; ++i)
{
BYTE mtiType = aTypes[i];
......@@ -3899,14 +4035,9 @@ namespace BinXlsxRW {
res = BinaryStyleTableReader(oBufferedStream, *pStyles).Read();
}
break;
case c_oSerTableTypes::Workbook:
{
res = BinaryWorkbookTableReader(oBufferedStream, *pWorkbook).Read();
}
break;
case c_oSerTableTypes::Worksheets:
{
res = BinaryWorksheetsTableReader(oBufferedStream, *pWorkbook, pSharedStrings, oXlsx.GetWorksheets(), mapMedia, sOutDir, sMediaDir, oSaveParams, pOfficeDrawingConverter).Read();
res = BinaryWorksheetsTableReader(oBufferedStream, *pWorkbook, pSharedStrings, oXlsx.GetWorksheets(), mapMedia, sOutDir, sMediaDir, oSaveParams, pOfficeDrawingConverter, m_mapPivotCacheDefinitions).Read();
}
break;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment