Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion OOXML/Binary/Sheets/Common/BinReaderWriterDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ namespace BinXlsxRW
QuotePrefix = 11,
XfId = 12,
Aligment = 13,
Protection = 14
Protection = 14,
CellControl = 15
};}
namespace c_oSerProtectionTypes {enum c_oSerProtectionTypes
{
Expand Down
35 changes: 35 additions & 0 deletions OOXML/Binary/Sheets/Reader/BinaryWriterS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include "../../../XlsxFormat/Styles/TableStyles.h"
#include "../../../XlsxFormat/Timelines/Timeline.h"
#include "../../../XlsxFormat/Workbook/Metadata.h"
#include "../../../XlsxFormat/Workbook/FeaturePropertyBag.h"
#include "../../../XlsxFormat/Table/Table.h"
#include "../../../XlsxFormat/Workbook/CustomsXml.h"
#include "../../../XlsxFormat/RichData/RdRichData.h"
Expand Down Expand Up @@ -1446,6 +1447,13 @@ void BinaryStyleTableWriter::WriteXfs(const OOX::Spreadsheet::CXfs& xfs)
m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Byte);
m_oBcw.m_oStream.WriteBOOL(xfs.m_oPivotButton->ToBool());
}
//CellControl (checkbox)
if (false != xfs.m_oCellControl.IsInit())
{
m_oBcw.m_oStream.WriteBYTE(c_oSerXfsTypes::CellControl);
m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Byte);
m_oBcw.m_oStream.WriteBOOL(*xfs.m_oCellControl);
}
//XfId
if (false != xfs.m_oXfId.IsInit())
{
Expand Down Expand Up @@ -9336,6 +9344,33 @@ void BinaryFileWriter::WriteContent(OOX::Document *pDocument, NSFontCutter::CEmb
//Styles
if(pStyles)
{
if (pWorkbook)
{
//resolve xf checkbox controls via the workbook featurePropertyBag part
smart_ptr<OOX::File> pFile = pWorkbook->Find(OOX::Spreadsheet::FileTypes::FeaturePropertyBag);
OOX::Spreadsheet::CFeaturePropertyBagFile* pBagFile = dynamic_cast<OOX::Spreadsheet::CFeaturePropertyBagFile*>(pFile.GetPointer());
if (pBagFile)
{
if (pStyles->m_oCellXfs.IsInit())
{
for (size_t i = 0; i < pStyles->m_oCellXfs->m_arrItems.size(); ++i)
{
OOX::Spreadsheet::CXfs* pXfs = pStyles->m_oCellXfs->m_arrItems[i];
if ((pXfs) && (pXfs->m_oXfComplementIndex.IsInit()))
pXfs->m_oCellControl = pBagFile->IsCheckboxComplement(*pXfs->m_oXfComplementIndex);
}
}
if (pStyles->m_oCellStyleXfs.IsInit())
{
for (size_t i = 0; i < pStyles->m_oCellStyleXfs->m_arrItems.size(); ++i)
{
OOX::Spreadsheet::CXfs* pXfs = pStyles->m_oCellStyleXfs->m_arrItems[i];
if ((pXfs) && (pXfs->m_oXfComplementIndex.IsInit()))
pXfs->m_oCellControl = pBagFile->IsCheckboxComplement(*pXfs->m_oXfComplementIndex);
}
}
}
}
nCurPos = WriteTableStart(c_oSerTableTypes::Styles);
BinaryStyleTableWriter oBinaryStyleTableWriter(m_oBcw->m_oStream, pEmbeddedFontsManager);
oBinaryStyleTableWriter.Write(*pStyles, pXlsx ? pXlsx->GetTheme() : NULL, m_oFontProcessor);
Expand Down
37 changes: 37 additions & 0 deletions OOXML/Binary/Sheets/Writer/BinaryReaderS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include "../../../XlsxFormat/Controls/Controls.h"
#include "../../../XlsxFormat/Timelines/Timeline.h"
#include "../../../XlsxFormat/Workbook/Metadata.h"
#include "../../../XlsxFormat/Workbook/FeaturePropertyBag.h"
#include "../../../XlsxFormat/Workbook/CustomsXml.h"
#include "../../../XlsxFormat/RichData/RdRichData.h"

Expand Down Expand Up @@ -1972,6 +1973,10 @@ int BinaryStyleTableReader::ReadXfs(BYTE type, long length, void* poResult)
pXfs->m_oXfId.Init();
pXfs->m_oXfId->SetValue(m_oBufferedStream.GetLong());
}
else if (c_oSerXfsTypes::CellControl == type)
{
pXfs->m_oCellControl = m_oBufferedStream.GetBool();
}
else
res = c_oSerConstants::ReadUnknown;
return res;
Expand Down Expand Up @@ -9932,6 +9937,38 @@ int BinaryFileReader::ReadMainTable(OOX::Spreadsheet::CXlsx& oXlsx, NSBinPptxRW:
if (c_oSerConstants::ReadOk != res)
return res;
}
OOX::Spreadsheet::CXlsb* pXlsb = dynamic_cast<OOX::Spreadsheet::CXlsb*>(&oXlsx);
if (oXlsx.m_pStyles && oXlsx.m_pWorkbook && (!pXlsb || !pXlsb->m_bWriteToXlsb))
{
//checkbox xfs reference the canonical featurePropertyBag part - create it on demand
bool bHasCellControl = false;
if (oXlsx.m_pStyles->m_oCellXfs.IsInit())
{
for (size_t i = 0; !bHasCellControl && i < oXlsx.m_pStyles->m_oCellXfs->m_arrItems.size(); ++i)
{
OOX::Spreadsheet::CXfs* pXfs = oXlsx.m_pStyles->m_oCellXfs->m_arrItems[i];
if ((pXfs) && (pXfs->m_oCellControl.IsInit()) && (*pXfs->m_oCellControl))
bHasCellControl = true;
}
}
if (oXlsx.m_pStyles->m_oCellStyleXfs.IsInit())
{
for (size_t i = 0; !bHasCellControl && i < oXlsx.m_pStyles->m_oCellStyleXfs->m_arrItems.size(); ++i)
{
OOX::Spreadsheet::CXfs* pXfs = oXlsx.m_pStyles->m_oCellStyleXfs->m_arrItems[i];
if ((pXfs) && (pXfs->m_oCellControl.IsInit()) && (*pXfs->m_oCellControl))
bHasCellControl = true;
}
}
if (bHasCellControl)
{
smart_ptr<OOX::Spreadsheet::CFeaturePropertyBagFile> oBagFile(new OOX::Spreadsheet::CFeaturePropertyBagFile(NULL));
oBagFile->OOX::File::m_pMainDocument = oXlsx.m_pWorkbook->OOX::File::m_pMainDocument;

smart_ptr<OOX::File> oFile = oBagFile.smart_dynamic_cast<OOX::File>();
oXlsx.m_pWorkbook->Add(oFile);
}
}
for (boost::unordered_map<long, ImageObject*>::const_iterator pPair = mapMedia.begin(); pPair != mapMedia.end(); ++pPair)
{
delete pPair->second;
Expand Down
2 changes: 2 additions & 0 deletions OOXML/Projects/Linux/DocxFormatLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ add_library(DocxFormatLib STATIC
${OOXML_ROOT_DIR}/XlsxFormat/Workbook/CustomsXml.cpp
${OOXML_ROOT_DIR}/XlsxFormat/Workbook/DefinedNames.cpp
${OOXML_ROOT_DIR}/XlsxFormat/Workbook/ExternalReferences.cpp
${OOXML_ROOT_DIR}/XlsxFormat/Workbook/FeaturePropertyBag.cpp
${OOXML_ROOT_DIR}/XlsxFormat/Workbook/Metadata.cpp
${OOXML_ROOT_DIR}/XlsxFormat/Workbook/Sheets.cpp
${OOXML_ROOT_DIR}/XlsxFormat/Workbook/Workbook.cpp
Expand Down Expand Up @@ -359,6 +360,7 @@ add_library(DocxFormatLib STATIC
${OOXML_ROOT_DIR}/XlsxFormat/Workbook/CustomsXml.h
${OOXML_ROOT_DIR}/XlsxFormat/Workbook/DefinedNames.h
${OOXML_ROOT_DIR}/XlsxFormat/Workbook/ExternalReferences.h
${OOXML_ROOT_DIR}/XlsxFormat/Workbook/FeaturePropertyBag.h
${OOXML_ROOT_DIR}/XlsxFormat/Workbook/Metadata.h
${OOXML_ROOT_DIR}/XlsxFormat/Workbook/Sheets.h
${OOXML_ROOT_DIR}/XlsxFormat/Workbook/Workbook.h
Expand Down
2 changes: 2 additions & 0 deletions OOXML/Projects/Linux/DocxFormatLib/DocxFormatLib.pro
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ SOURCES += \
../../../XlsxFormat/Drawing/Pos.cpp \
../../../XlsxFormat/ExternalLinks/ExternalLinkPath.cpp \
../../../XlsxFormat/ExternalLinks/ExternalLinks.cpp \
../../../XlsxFormat/Workbook/FeaturePropertyBag.cpp \
../../../XlsxFormat/Workbook/Metadata.cpp \
../../../XlsxFormat/RichData/RdRichData.cpp \
../../../XlsxFormat/Ole/OleObjects.cpp \
Expand Down Expand Up @@ -393,6 +394,7 @@ HEADERS += \
../../../XlsxFormat/Slicer/SlicerCacheExt.h \
../../../XlsxFormat/Slicer/Slicer.h \
../../../XlsxFormat/NamedSheetViews/NamedSheetViews.h \
../../../XlsxFormat/Workbook/FeaturePropertyBag.h \
../../../XlsxFormat/Workbook/Metadata.h \
../../../XlsxFormat/RichData/RdRichValue.h \
../../../VsdxFormat/Vsdx.h \
Expand Down
2 changes: 2 additions & 0 deletions OOXML/Projects/Windows/DocxFormatLib/DocxFormatLib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@
<ClInclude Include="..\..\..\XlsxFormat\Workbook\CustomsXml.h" />
<ClInclude Include="..\..\..\XlsxFormat\Workbook\DefinedNames.h" />
<ClInclude Include="..\..\..\XlsxFormat\Workbook\ExternalReferences.h" />
<ClInclude Include="..\..\..\XlsxFormat\Workbook\FeaturePropertyBag.h" />
<ClInclude Include="..\..\..\XlsxFormat\Workbook\Metadata.h" />
<ClInclude Include="..\..\..\XlsxFormat\Workbook\Sheets.h" />
<ClInclude Include="..\..\..\XlsxFormat\Workbook\Workbook.h" />
Expand Down Expand Up @@ -567,6 +568,7 @@
<ClCompile Include="..\..\..\XlsxFormat\Workbook\CustomsXml.cpp" />
<ClCompile Include="..\..\..\XlsxFormat\Workbook\DefinedNames.cpp" />
<ClCompile Include="..\..\..\XlsxFormat\Workbook\ExternalReferences.cpp" />
<ClCompile Include="..\..\..\XlsxFormat\Workbook\FeaturePropertyBag.cpp" />
<ClCompile Include="..\..\..\XlsxFormat\Workbook\Metadata.cpp" />
<ClCompile Include="..\..\..\XlsxFormat\Workbook\Sheets.cpp" />
<ClCompile Include="..\..\..\XlsxFormat\Workbook\Workbook.cpp" />
Expand Down
5 changes: 5 additions & 0 deletions OOXML/XlsxFormat/FileFactory_Spreadsheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "Timelines/Timeline.h"
#include "RichData/RdRichData.h"
#include "Workbook/Metadata.h"
#include "Workbook/FeaturePropertyBag.h"

#include "Table/Table.h"
#include "Table/QueryTable.h"
Expand Down Expand Up @@ -183,6 +184,8 @@ namespace OOX
return smart_ptr<OOX::File>(new CTimelineCacheFile(pMain, oRootPath, oFileName));
else if (oRelation.Type() == FileTypes::Metadata)
return smart_ptr<OOX::File>(new CMetadataFile(pMain, oRootPath, oFileName));
else if (oRelation.Type() == FileTypes::FeaturePropertyBag)
return smart_ptr<OOX::File>(new CFeaturePropertyBagFile(pMain, oRootPath, oFileName));
else if (oRelation.Type() == FileTypes::RdRichValueStructure)
return smart_ptr<OOX::File>(new CRdRichValueStructureFile(pMain, oRootPath, oFileName));
else if (oRelation.Type() == FileTypes::RdRichValue)
Expand Down Expand Up @@ -325,6 +328,8 @@ namespace OOX
return smart_ptr<OOX::File>(new CTimelineCacheFile(pMain, oRootPath, oFileName));
else if (pRelation->Type() == FileTypes::Metadata)
return smart_ptr<OOX::File>(new CMetadataFile(pMain, oRootPath, oFileName));
else if (pRelation->Type() == FileTypes::FeaturePropertyBag)
return smart_ptr<OOX::File>(new CFeaturePropertyBagFile(pMain, oRootPath, oFileName));
else if (pRelation->Type() == FileTypes::RdRichValueStructure)
return smart_ptr<OOX::File>(new CRdRichValueStructureFile(pMain, oRootPath, oFileName));
else if (pRelation->Type() == FileTypes::RdRichValue)
Expand Down
4 changes: 4 additions & 0 deletions OOXML/XlsxFormat/FileTypes_Spreadsheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ namespace OOX
L"application/vnd.openxmlformats-officedocument.spreadsheetml.sheetMetadata+xml",
L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/sheetMetadata");

const FileType FeaturePropertyBag(L"featurePropertyBag", L"featurePropertyBag.xml",
L"application/vnd.ms-excel.featurepropertybag+xml",
L"http://schemas.microsoft.com/office/2022/11/relationships/FeaturePropertyBag");


const FileType RdRichValue (L"richData", L"rdrichvalue.xml",
L"application/vnd.ms-excel.rdrichvalue+xml",
Expand Down
2 changes: 2 additions & 0 deletions OOXML/XlsxFormat/FileTypes_Spreadsheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ namespace OOX

extern const FileType Metadata;

extern const FileType FeaturePropertyBag;

extern const FileType RdRichValue;

extern const FileType RdRichValueStructure;
Expand Down
46 changes: 45 additions & 1 deletion OOXML/XlsxFormat/Styles/Xfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,20 @@ namespace OOX
WritingStringNullableAttrBool(L"applyProtection", m_oApplyProtection);
WritingStringNullableAttrBool(L"quotePrefix", m_oQuotePrefix);
WritingStringNullableAttrBool(L"pivotButton", m_oPivotButton);
if (m_oAligment.IsInit() || m_oProtection.IsInit())
bool bCellControl = m_oCellControl.IsInit() ? *m_oCellControl : m_oXfComplementIndex.IsInit();
if (m_oAligment.IsInit() || m_oProtection.IsInit() || bCellControl)
{
writer.WriteString(_T(">"));

if (m_oAligment.IsInit())m_oAligment->toXML(writer);
if (m_oProtection.IsInit())m_oProtection->toXML(writer);
if (bCellControl)
{
// references the canonical checkbox chain in featurePropertyBag.xml
writer.WriteString(L"<extLst><ext uri=\"{C7286773-470A-42A8-94C5-96B5CB345126}\" \
xmlns:xfpb=\"http://schemas.microsoft.com/office/spreadsheetml/2022/featurepropertybag\">\
<xfpb:xfComplement i=\"0\"/></ext></extLst>");
}

writer.WriteString(_T("</xf>"));
}
Expand All @@ -378,6 +386,42 @@ namespace OOX
m_oAligment = oReader;
else if( _T("protection") == sName )
m_oProtection = oReader;
else if( _T("extLst") == sName )
ReadExtLst(oReader);
}
}
void CXfs::ReadExtLst(XmlUtils::CXmlLiteReader& oReader)
{
if (oReader.IsEmptyNode())
return;

int nExtLstDepth = oReader.GetDepth();
while (oReader.ReadNextSiblingNode(nExtLstDepth))
{
if (L"ext" != XmlUtils::GetNameNoNS(oReader.GetName()) || oReader.IsEmptyNode())
continue;

int nExtDepth = oReader.GetDepth();
while (oReader.ReadNextSiblingNode(nExtDepth))
{
if (L"xfComplement" == XmlUtils::GetNameNoNS(oReader.GetName()))
{
if (oReader.MoveToFirstAttribute())
{
std::wstring wsName = oReader.GetName();
while (!wsName.empty())
{
if (L"i" == wsName)
m_oXfComplementIndex = XmlUtils::GetInteger(oReader.GetText());

if (!oReader.MoveToNextAttribute())
break;
wsName = oReader.GetName();
}
oReader.MoveToElement();
}
}
}
}
}
EElementType CXfs::getType () const
Expand Down
7 changes: 5 additions & 2 deletions OOXML/XlsxFormat/Styles/Xfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ namespace OOX
nullable<SimpleTypes::COnOff> m_oLocked;
};

//нереализован:
//<extLst>
class CXfs : public WritingElement
{
public:
Expand All @@ -137,6 +135,7 @@ namespace OOX
private:
void ReadAttributes(XmlUtils::CXmlLiteReader& oReader);
void ReadAttributes(XLS::BaseObjectPtr& obj);
void ReadExtLst(XmlUtils::CXmlLiteReader& oReader);

public:
nullable<SimpleTypes::COnOff> m_oApplyAlignment;
Expand All @@ -157,6 +156,10 @@ namespace OOX
nullable<CAligment> m_oAligment;
nullable<CProtection> m_oProtection;

// cell checkbox (resolved from the featurePropertyBag xfComplement extension)
nullable_bool m_oCellControl;
// raw <xfpb:xfComplement i="..."/> index, resolved via CFeaturePropertyBagFile
nullable_int m_oXfComplementIndex;
};

class CCellXfs : public WritingElementWithChilds<CXfs>
Expand Down
Loading
Loading