Commit da45eb4f authored by ElenaSubbotina's avatar ElenaSubbotina

XlsFormat - pivots...

parent 59d75ed1
......@@ -70,11 +70,10 @@ void SXFDB::readFields(CFRecord& record)
fCantGetUniqueItems = GETBIT(flags, 14);
fCalculatedField = GETBIT(flags, 15);
if (fAllAtoms)
{
GlobalWorkbookInfoPtr global_info = record.getGlobalWorkbookInfo();
global_info->arCacheFieldShortSize.push_back(fShortIitms);
}
GlobalWorkbookInfoPtr global_info = record.getGlobalWorkbookInfo();
global_info->arPivotCacheFieldShortSize.push_back(fShortIitms);
global_info->arPivotCacheFields.push_back(fAllAtoms);
}
} // namespace XLS
......
......@@ -35,8 +35,9 @@
namespace XLS
{
SXLI::SXLI()
SXLI::SXLI(int count_)
{
count = count_;
}
......@@ -81,10 +82,13 @@ void SXLI::readFields(CFRecord& record)
if (item.fSbt && item.itmType < 0x000D)
item.isxviMac++;
for (short i = 0; i < item.isxviMac; i++)
for (short i = 0; i < count/*item.isxviMac*/; i++)
{
short val; record >> val;
item.rgisxvi.push_back(val);
if (val >= 0x0000 && val <= 0x7EF4)
{
item.rgisxvi.push_back(val);
}
}
m_arItems.push_back(item);
......
......@@ -55,7 +55,7 @@ class SXLI: public BiffRecordContinued
BIFF_RECORD_DEFINE_TYPE_INFO(SXLI)
BASE_OBJECT_DEFINE_CLASS_NAME(SXLI)
public:
SXLI();
SXLI(int count_);
~SXLI();
BaseObjectPtr clone();
......@@ -65,6 +65,7 @@ public:
static const ElementType type = typeSXLI;
std::vector<SXLIItem> m_arItems;
int count;
};
} // namespace XLS
......
......@@ -73,14 +73,10 @@ int SXVI::serialize(std::wostream & strm)
{
CP_XML_NODE(L"item")
{
if (fMissing)
CP_XML_ATTR(L"m", 1);
if (fHidden)
CP_XML_ATTR(L"h", 1);
if (fHideDetail)
CP_XML_ATTR(L"h", 1);
if (fFormula)
CP_XML_ATTR(L"f", 1);
if (fMissing) CP_XML_ATTR(L"m", 1);
if (fHidden) CP_XML_ATTR(L"h", 1);
if (fHideDetail)CP_XML_ATTR(L"sd", 1);
if (fFormula) CP_XML_ATTR(L"f", 1);
if (itmType == 0)
{
......
......@@ -56,6 +56,18 @@ void SxBool::readFields(CFRecord& record)
val = (flags != 0);
}
int SxBool::serialize(std::wostream & strm)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE(L"b")
{
CP_XML_ATTR(L"v", val);
}
}
return 0;
}
} // namespace XLS
......@@ -48,6 +48,8 @@ public:
void readFields(CFRecord& record);
int serialize(std::wostream & strm);
static const ElementType type = typeSxBool;
bool val;
......
......@@ -53,7 +53,7 @@ BaseObjectPtr SxFilt::clone()
void SxFilt::readFields(CFRecord& record)
{
unsigned short flags1;
unsigned char flags2;
unsigned short flags2;
record >> flags1 >> isxvd >> flags2 >> grbitSbt >> cisxvi;
......@@ -63,7 +63,8 @@ void SxFilt::readFields(CFRecord& record)
sxaxisData = GETBIT(flags1, 3);
iDim = GETBITS(flags1, 4, 15);
fSelected = GETBIT(flags2, 0);
isxvd = GETBITS(flags2, 0, 9);
fSelected = GETBIT(flags2, 10);
}
} // namespace XLS
......
......@@ -58,7 +58,7 @@ public:
unsigned short isxvd;
bool fSelected;
unsigned short grbitSbt;
short grbitSbt;
unsigned short cisxvi;
};
......
......@@ -45,13 +45,51 @@ BiffStructurePtr PtgSxName::clone()
void PtgSxName::loadFields(CFRecord& record)
{
record >> sxIndex;
global_info = record.getGlobalWorkbookInfo();
}
void PtgSxName::assemble(AssemblerStack& ptg_stack, PtgQueue& extra_data, bool full_ref)
{
Log::info("PtgSxName structure is not assemble.");
//RevNamePtr tab_id;
//if(!extra_data.empty() && (tab_id = boost::dynamic_pointer_cast<RevName>(extra_data.front())))
//{
// Log::error("PtgNameX struct for revisions is not assemble.");
// ptg_stack.push(L"#REF!");
// extra_data.pop();
// return;
//}
std::wstring _Name;
if(sxIndex > 0 && sxIndex <= global_info->AddinUdfs.size() && !(_Name = global_info->AddinUdfs[sxIndex - 1]).empty())
{
ptg_stack.push(_Name);
}
else if(sxIndex > 0 && sxIndex <= global_info->xti_parsed.size())
{
std::wstring sheet = global_info->xti_parsed[sxIndex-1];
if (!sheet.empty()) sheet += L"!";
if (sxIndex > 0 && sxIndex <= global_info->arDefineNames.size())
{
_Name = global_info->arDefineNames[sxIndex - 1];
}
if (sheet.empty() && _Name.empty() && sxIndex <= global_info->arExternalNames.size() && sxIndex > 0)
{
_Name = global_info->arExternalNames[sxIndex - 1];
}
ptg_stack.push(sheet + _Name);
}
else
{
Log::warning("PtgSxName structure is not assemble.");
ptg_stack.push(L""); // This would let us to continue without an error
}
ptg_stack.push(L"#REF!");
}
......
......@@ -44,14 +44,13 @@ class PtgSxName: public OperandPtg
public:
BiffStructurePtr clone();
virtual void loadFields(CFRecord& record);
virtual void loadFields(CFRecord& record);
virtual void assemble(AssemblerStack& ptg_stack, PtgQueue& extra_data, bool full_ref = false);
private:
_UINT32 sxIndex;
private:
GlobalWorkbookInfoPtr global_info;
};
} // namespace XLS
......
......@@ -55,10 +55,13 @@ BiffStructurePtr XFExtNoFRT::clone()
void XFExtNoFRT::load(CFRecord& record)
{
if (record.isEOF()) return;
record.skipNunBytes(6); // reserved
unsigned short cexts;
record >> cexts;
for(unsigned short i = 0; i < cexts; ++i)
for(unsigned short i = 0; !record.isEOF() && i < cexts; ++i)
{
ExtProp prop;
record >> prop;
......
......@@ -44,8 +44,7 @@ DBB::DBB()
bDate = false;
bNumber = false;
bEmpty = false;
fShortIitms = false;
bBool = false;
}
DBB::~DBB()
......@@ -75,6 +74,7 @@ const bool DBB::loadContent(BinProcessor& proc)
bDate |= operatr->bDate;
bNumber |= operatr->bNumber;
bEmpty |= operatr->bEmpty;
bBool |= operatr->bBool;
}
if (!m_SXDBB && m_arSXOPER.empty())
......@@ -92,34 +92,34 @@ int DBB::serialize(std::wostream & strm)
{
CP_XML_NODE(L"r")
{
if (m_arSXOPER.empty() == false)
int indexOPER = 0;
size_t posBlob = 0;
for (size_t i = 0; i < arPivotCacheFields.size(); i++)
{
for (size_t i = 0; i < m_arSXOPER.size(); i++)
if(arPivotCacheFields[i] == false)
{
m_arSXOPER[i]->serialize(CP_XML_STREAM());
m_arSXOPER[indexOPER++]->serialize(CP_XML_STREAM());
}
}
else
{
if (fShortIitms == false)
else
{
for (size_t i = 0; i < dbb->size; i++)
if (arPivotCacheFieldShortSize[i])//fShortIitms
{
unsigned short * values = (unsigned short *)(dbb->blob.get() + posBlob);
CP_XML_NODE(L"x")
{
CP_XML_ATTR(L"v", dbb->blob[i]);
CP_XML_ATTR(L"v", *values);
}
posBlob+=2;
}
}
else
{
unsigned short * values = (unsigned short *)dbb->blob.get();
for (size_t i = 0; i < dbb->size / 2; i++)
else
{
unsigned char * values = (unsigned char *)(dbb->blob.get() + posBlob);
CP_XML_NODE(L"x")
{
CP_XML_ATTR(L"v", values[i]);
CP_XML_ATTR(L"v", *values);
}
posBlob++;
}
}
}
......
......@@ -55,12 +55,14 @@ public:
std::vector<BaseObjectPtr> m_arSXOPER;
//---------------------------------------------------
bool fShortIitms;
std::vector<bool> arPivotCacheFields;
std::vector<bool> arPivotCacheFieldShortSize;
bool bString;
bool bDate;
bool bNumber;
bool bEmpty;
bool bBool;
};
} // namespace XLS
......
......@@ -79,6 +79,7 @@ FDB::FDB()
bNumber = false;
bEmpty = false;
bInteger = false;
bBool = false;
}
FDB::~FDB()
......@@ -166,6 +167,7 @@ const bool FDB::loadContent(BinProcessor& proc)
bNumber |= operatr->bNumber;
bEmpty |= operatr->bEmpty;
bInteger|= operatr->bInteger;
bBool |= operatr->bBool;
}
return true;
......@@ -249,15 +251,17 @@ int FDB::serialize(std::wostream & strm)
{
CP_XML_ATTR(L"containsMixedTypes", 1);
}
else if (!bEmpty && !bString)
else if (!bEmpty && !bString && !bBool)
{
CP_XML_ATTR(L"containsSemiMixedTypes", 0);
}
if (bNumber) CP_XML_ATTR(L"containsNumber", 1);
if (bDate) CP_XML_ATTR(L"containsDate", 1);
if (!bString) CP_XML_ATTR(L"containsString", 0);
if (bEmpty) CP_XML_ATTR(L"containsBlank", 1);
if (bInteger) CP_XML_ATTR(L"containsInteger", 1);
if (!bString && (bInteger || bDate || bNumber || bEmpty))
CP_XML_ATTR(L"containsString", 0);
if (fdb->fnumMinMaxValid)
{
......
......@@ -65,6 +65,7 @@ public:
bool bNumber;
bool bEmpty;
bool bInteger;
bool bBool;
};
......
......@@ -62,6 +62,9 @@ const bool PIVOTCACHE::loadContent(BinProcessor& proc)
{
GlobalWorkbookInfoPtr global_info = proc.getGlobalWorkbookInfo();
global_info->arPivotCacheFieldShortSize.clear();
global_info->arPivotCacheFields.clear();
if(!proc.mandatory<SXDB>())
{
return false;
......@@ -95,14 +98,8 @@ const bool PIVOTCACHE::loadContent(BinProcessor& proc)
DBB* dbb = dynamic_cast<DBB*>(m_arDBB.back().get());
if (global_info->arCacheFieldShortSize.size() >= m_arDBB.size())
{
dbb->fShortIitms = global_info->arCacheFieldShortSize[m_arDBB.size() - 1];
}
else
{
//???? группы??
}
dbb->arPivotCacheFieldShortSize = global_info->arPivotCacheFieldShortSize;
dbb->arPivotCacheFields = global_info->arPivotCacheFields;
}
if (proc.optional<EOF_T>())
{
......
......@@ -55,6 +55,8 @@ public:
std::vector<BaseObjectPtr> m_arFDB;
std::vector<BaseObjectPtr> m_arDBB;
std::vector<bool> m_arAllAtoms;
};
} // namespace XLS
......
......@@ -139,7 +139,18 @@ int PIVOTCACHEDEFINITION::serialize_definitions(std::wostream & strm)
}
}
}
if (pivot_cache->m_arSXFORMULA.empty() == false)
{
CP_XML_NODE(L"calculatedItems")
{
CP_XML_ATTR(L"count", pivot_cache->m_arSXFORMULA.size());
for (size_t i = 0; i < pivot_cache->m_arSXFORMULA.size(); i++)
{
pivot_cache->m_arSXFORMULA[i]->serialize(CP_XML_STREAM());
}
}
}
}
}
return 0;
......
......@@ -66,6 +66,8 @@ const bool PIVOTCORE::loadContent(BinProcessor& proc)
m_SxView = elements_.back();
elements_.pop_back();
SxView* sxView = dynamic_cast<SxView*>(m_SxView.get());
int count = 0;
count = proc.repeated<PIVOTVD>(0, 0);
......@@ -90,12 +92,21 @@ const bool PIVOTCORE::loadContent(BinProcessor& proc)
{
m_arSXDI.push_back(elements_.front()); elements_.pop_front();
}
count = proc.repeated<PIVOTLI>(0, 0);
while(count--)
PIVOTLI rwLines(sxView->cDimRw);
if (proc.optional(rwLines))
{
m_arPIVOTLI.push_back(elements_.front()); elements_.pop_front();
}
PIVOTLI colLines(sxView->cDimCol);
if (proc.optional(colLines))
{
m_arPIVOTLI.push_back(elements_.front()); elements_.pop_front();
}
//count = proc.repeated<PIVOTLI>(0, 0);
//while(count--)
//{
// m_arPIVOTLI.push_back(elements_.front()); elements_.pop_front();
//}
if (proc.mandatory<PIVOTEX>())
{
......
......@@ -38,8 +38,9 @@
namespace XLS
{
PIVOTLI::PIVOTLI()
PIVOTLI::PIVOTLI(int count_lines_)
{
count_lines = count_lines_;
}
PIVOTLI::~PIVOTLI()
......@@ -54,7 +55,9 @@ BaseObjectPtr PIVOTLI::clone()
// PIVOTLI = SXLI *Continue
const bool PIVOTLI::loadContent(BinProcessor& proc)
{
if(!proc.mandatory<SXLI>())
SXLI sx_line(count_lines);
if(!proc.mandatory(sx_line))
{
return false;
}
......@@ -110,6 +113,7 @@ int PIVOTLI::serialize(std::wostream & strm)
}
}
}
return 0;
}
} // namespace XLS
......@@ -40,7 +40,7 @@ class PIVOTLI: public CompositeObject
{
BASE_OBJECT_DEFINE_CLASS_NAME(PIVOTLI)
public:
PIVOTLI();
PIVOTLI(int count_lines_);
~PIVOTLI();
BaseObjectPtr clone();
......@@ -52,6 +52,8 @@ public:
static const ElementType type = typePIVOTLI;
BaseObjectPtr m_SXLI;
int count_lines;
};
} // namespace XLS
......
......@@ -38,6 +38,28 @@
namespace XLS
{
// (SxName *SXPair)
class Parenthesis_SXFMLA: public ABNFParenthesis
{
BASE_OBJECT_DEFINE_CLASS_NAME(Parenthesis_SXFMLA)
public:
BaseObjectPtr clone()
{
return BaseObjectPtr(new Parenthesis_SXFMLA(*this));
}
const bool loadContent(BinProcessor& proc)
{
if(!proc.mandatory<SxName>())
{
return false;
}
int count = proc.repeated<SXPair>(0, 0);
return true;
};
};
SXFMLA::SXFMLA()
{
......@@ -57,6 +79,8 @@ BaseObjectPtr SXFMLA::clone()
// SXFMLA = SxFmla *(SxName *SXPair)
const bool SXFMLA::loadContent(BinProcessor& proc)
{
GlobalWorkbookInfoPtr global_info = proc.getGlobalWorkbookInfo();
if(!proc.mandatory<SxFmla>())
{
return false;
......@@ -64,6 +88,34 @@ const bool SXFMLA::loadContent(BinProcessor& proc)
m_SxFmla = elements_.back();
elements_.pop_back();
int count = proc.repeated<Parenthesis_SXFMLA>(0, 0);
while(!elements_.empty())
{
if (dynamic_cast<SxName*>(elements_.front().get()))
{
_sx_name sx_name;
sx_name.name = elements_.front(); elements_.pop_front();
global_info->arPivotSxNames.push_back(sx_name);
}
else
{
while(!elements_.empty())
{
if (dynamic_cast<SxName*>(elements_.front().get()))
{
break;
}
else
{
global_info->arPivotSxNames.back().pair.push_back(elements_.front());
elements_.pop_front();
}
}
}
}
return true;
}
......
......@@ -35,11 +35,11 @@
namespace XLS
{
class SXFMLA: public CompositeObject
{
BASE_OBJECT_DEFINE_CLASS_NAME(SXFMLA)
public:
SXFMLA();
~SXFMLA();
......@@ -49,7 +49,7 @@ public:
static const ElementType type = typeSXFMLA;
BaseObjectPtr m_SxFmla;
BaseObjectPtr m_SxFmla;
};
} // namespace XLS
......
......@@ -34,7 +34,11 @@
#include "SXFMLA_bu.h"
#include "PIVOTRULE.h"
#include "../Biff_records/SXFormula.h"
#include "../Biff_records/SxFmla.h"
#include "../Biff_records/SxName.h"
#include "../Biff_records/SXPair.h"
namespace XLS
{
......@@ -56,6 +60,8 @@ BaseObjectPtr SXFORMULA::clone()
// SXFORMULA = SXFMLA PIVOTRULE SXFormula
const bool SXFORMULA::loadContent(BinProcessor& proc)
{
global_info = proc.getGlobalWorkbookInfo();
if(!proc.mandatory<SXFMLA>())
{
return false;
......@@ -74,6 +80,29 @@ const bool SXFORMULA::loadContent(BinProcessor& proc)
elements_.pop_back();
} return true;
}
int SXFORMULA::serialize(std::wostream & strm)
{
SXFMLA* fmla = dynamic_cast<SXFMLA*>(m_SXFMLA.get());
if (!fmla) return 0;
SxFmla* sx_fmla = dynamic_cast<SxFmla*>(fmla->m_SxFmla.get());
CP_XML_WRITER(strm)
{
CP_XML_NODE(L"calculatedItem")
{
CP_XML_ATTR(L"formula", sx_fmla->fmla.getAssembledFormula());
//for (size_t j = 0; j < global_info->arPivotSxNames.size(); j++)//???
//{
// SxName *name = dynamic_cast<SxName*>(global_info->arPivotSxNames[j].m_SxName.get());
// CP_XML_NODE(L"pivotArea")
// {
// }
//}
}
}
return 0;
}
} // namespace XLS
......@@ -47,11 +47,15 @@ public:
virtual const bool loadContent(BinProcessor& proc);
int serialize(std::wostream & stream);
static const ElementType type = typeSXFORMULA;
BaseObjectPtr m_SXFMLA;
BaseObjectPtr m_PIVOTRULE;
BaseObjectPtr m_SXFormula;
GlobalWorkbookInfoPtr global_info;
};
} // namespace XLS
......
......@@ -48,6 +48,7 @@ SXOPER::SXOPER()
bNumber = false;
bEmpty = false;
bInteger= false;
bBool = false;
}
SXOPER::~SXOPER()
......@@ -81,7 +82,7 @@ const bool SXOPER::loadContent(BinProcessor& proc)
}
else if(proc.optional<SxBool>())
{
bNumber = true;
bBool = true;
}
else if(proc.optional<SxErr>())
{
......
......@@ -58,6 +58,7 @@ public:
bool bNumber;
bool bEmpty;
bool bInteger;
bool bBool;
};
} // namespace XLS
......
......@@ -60,6 +60,13 @@ static const std::wstring DefaultPalette[] = {
L"00003366", L"00339966", L"00003300", L"00333300", L"00993300", L"00993366", L"00333399", L"00333333"
};
struct _sx_name
{
BaseObjectPtr name;
std::vector<BaseObjectPtr> pair;
};
class GlobalWorkbookInfo
{
public:
......@@ -75,7 +82,6 @@ public:
unsigned int GenerateAXESId();
unsigned short CodePage;
CRYPT::DecryptorPtr decryptor;
std::wstring password;
......@@ -100,7 +106,9 @@ public:
const static unsigned int initial_AXES_id = 0x2000000;
std::map<int, BaseObjectPtr> mapPivotCache;
std::vector<bool> arCacheFieldShortSize;
std::vector<bool> arPivotCacheFields;
std::vector<bool> arPivotCacheFieldShortSize;
std::vector<_sx_name> arPivotSxNames;
std::map<std::wstring, std::vector<std::wstring>> mapDefineNames;
std::vector<std::wstring> arDefineNames;
......
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