Commit a88ad0c2 authored by ElenaSubbotina's avatar ElenaSubbotina

XlsFormat - fix calculations in pivot tables

parent cf5458c7
...@@ -39,7 +39,6 @@ SXDtr::SXDtr() ...@@ -39,7 +39,6 @@ SXDtr::SXDtr()
{ {
} }
SXDtr::~SXDtr() SXDtr::~SXDtr()
{ {
} }
...@@ -54,7 +53,7 @@ void SXDtr::readFields(CFRecord& record) ...@@ -54,7 +53,7 @@ void SXDtr::readFields(CFRecord& record)
record >> yr >> mon >> dom >> hr >> min >> sec; record >> yr >> mon >> dom >> hr >> min >> sec;
} }
std::wstring SXDtr::get_string_date() std::wstring SXDtr::value()
{ {
std::wstringstream s; std::wstringstream s;
s << yr << L"-" << (mon < 10 ? L"0" : L"") << mon << L"-" << (dom < 10 ? L"0" : L"") << dom << L"T" s << yr << L"-" << (mon < 10 ? L"0" : L"") << mon << L"-" << (dom < 10 ? L"0" : L"") << dom << L"T"
...@@ -63,19 +62,5 @@ std::wstring SXDtr::get_string_date() ...@@ -63,19 +62,5 @@ std::wstring SXDtr::get_string_date()
return s.str(); return s.str();
} }
int SXDtr::serialize(std::wostream & strm)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE(L"d")
{
CP_XML_ATTR(L"v", get_string_date());
}
}
return 0;
}
} // namespace XLS } // namespace XLS
...@@ -48,8 +48,6 @@ public: ...@@ -48,8 +48,6 @@ public:
void readFields(CFRecord& record); void readFields(CFRecord& record);
int serialize(std::wostream & strm);
static const ElementType type = typeSXDtr; static const ElementType type = typeSXDtr;
unsigned short yr; unsigned short yr;
...@@ -59,7 +57,7 @@ public: ...@@ -59,7 +57,7 @@ public:
unsigned char min; unsigned char min;
unsigned char sec; unsigned char sec;
std::wstring get_string_date(); std::wstring value();
}; };
......
...@@ -53,17 +53,5 @@ void SXNum::readFields(CFRecord& record) ...@@ -53,17 +53,5 @@ void SXNum::readFields(CFRecord& record)
record >> num; record >> num;
} }
int SXNum::serialize(std::wostream & strm)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE(L"n")
{
CP_XML_ATTR(L"v", num.data.value);
}
}
return 0;
}
} // namespace XLS } // namespace XLS
...@@ -49,8 +49,6 @@ public: ...@@ -49,8 +49,6 @@ public:
void readFields(CFRecord& record); void readFields(CFRecord& record);
int serialize(std::wostream & strm);
static const ElementType type = typeSXNum; static const ElementType type = typeSXNum;
Xnum num; Xnum num;
......
...@@ -59,18 +59,6 @@ void SXString::readFields(CFRecord& record) ...@@ -59,18 +59,6 @@ void SXString::readFields(CFRecord& record)
record >> segment; record >> segment;
} }
} }
int SXString::serialize(std::wostream & strm)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE(L"s")
{
CP_XML_ATTR(L"v", segment.value());
}
}
return 0;
}
std::wstring SXString::value() std::wstring SXString::value()
{ {
......
...@@ -51,8 +51,6 @@ public: ...@@ -51,8 +51,6 @@ public:
std::wstring value(); std::wstring value();
int serialize(std::wostream & strm);
static const ElementType type = typeSXString; static const ElementType type = typeSXString;
unsigned short cch; unsigned short cch;
......
...@@ -39,7 +39,6 @@ SxBool::SxBool() ...@@ -39,7 +39,6 @@ SxBool::SxBool()
{ {
} }
SxBool::~SxBool() SxBool::~SxBool()
{ {
} }
...@@ -56,18 +55,5 @@ void SxBool::readFields(CFRecord& record) ...@@ -56,18 +55,5 @@ void SxBool::readFields(CFRecord& record)
val = (flags != 0); 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 } // namespace XLS
...@@ -48,8 +48,6 @@ public: ...@@ -48,8 +48,6 @@ public:
void readFields(CFRecord& record); void readFields(CFRecord& record);
int serialize(std::wostream & strm);
static const ElementType type = typeSxBool; static const ElementType type = typeSxBool;
bool val; bool val;
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
#pragma once #pragma once
#include "BiffRecord.h" #include "BiffRecord.h"
//#include "../Biff_structures/CellRangeRef.h"
namespace XLS namespace XLS
{ {
......
...@@ -52,14 +52,5 @@ void SxNil::readFields(CFRecord& record) ...@@ -52,14 +52,5 @@ void SxNil::readFields(CFRecord& record)
{ {
} }
int SxNil::serialize(std::wostream & strm)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE(L"m");
}
return 0;
}
} // namespace XLS } // namespace XLS
...@@ -48,8 +48,6 @@ public: ...@@ -48,8 +48,6 @@ public:
void readFields(CFRecord& record); void readFields(CFRecord& record);
int serialize(std::wostream & strm);
static const ElementType type = typeSxNil; static const ElementType type = typeSxNil;
}; };
......
...@@ -100,7 +100,7 @@ void PtgSxName::assemble(AssemblerStack& ptg_stack, PtgQueue& extra_data, bool f ...@@ -100,7 +100,7 @@ void PtgSxName::assemble(AssemblerStack& ptg_stack, PtgQueue& extra_data, bool f
SXOPER* cache = dynamic_cast<SXOPER*>(field->m_arSRCSXOPER[pair->iCache].get()); SXOPER* cache = dynamic_cast<SXOPER*>(field->m_arSRCSXOPER[pair->iCache].get());
if (cache) if (cache)
{ {
_Name += L"[" + cache->get_value() + L"]"; _Name += L"[" + cache->value + L"]";
} }
} }
} }
......
...@@ -35,10 +35,15 @@ ...@@ -35,10 +35,15 @@
#include "SXFORMULA_bu.h" #include "SXFORMULA_bu.h"
#include "FDB.h" #include "FDB.h"
#include "DBB.h" #include "DBB.h"
#include "SXOPER.h"
#include "PRFILTER.h"
#include "PIVOTRULE.h"
#include "../Biff_records/SXDB.h" #include "../Biff_records/SXDB.h"
#include "../Biff_records/SXDBEx.h" #include "../Biff_records/SXDBEx.h"
#include "../Biff_records/EOF.h" #include "../Biff_records/EOF.h"
#include "../Biff_records/SxItm.h"
#include "../Biff_records/SxFilt.h"
namespace XLS namespace XLS
{ {
...@@ -105,6 +110,45 @@ const bool PIVOTCACHE::loadContent(BinProcessor& proc) ...@@ -105,6 +110,45 @@ const bool PIVOTCACHE::loadContent(BinProcessor& proc)
{ {
elements_.pop_back(); elements_.pop_back();
} }
//--------------------------------------------------------------------------------------------------------------------
for (size_t i = 0; i < m_arSXFORMULA.size(); i++)
{
SXFORMULA* formula = dynamic_cast<SXFORMULA*>(m_arSXFORMULA[i].get());
if (!formula)continue;
PIVOTRULE* pivot_rule = dynamic_cast<PIVOTRULE*>(formula->m_PIVOTRULE.get());
if (!pivot_rule) continue;
for (size_t j = 0; j < pivot_rule->m_arPRFILTER.size(); j++)
{
PRFILTER* filter = dynamic_cast<PRFILTER*>(pivot_rule->m_arPRFILTER[j].get());
if (!filter) continue;
SxItm* item = dynamic_cast<SxItm*>(filter->m_SxItm.get());
SxFilt* filt = dynamic_cast<SxFilt*>(filter->m_SxFilt.get());
for (size_t i = 0; (item && filt) && i < item->rgisxvi.size(); i++)
{
short index_cache = filt->isxvd;
short index_item = item->rgisxvi[i];
if (index_cache >= 0 && index_cache < m_arFDB.size())
{
FDB* field = dynamic_cast<FDB*>(m_arFDB[index_cache].get());
if (field)
{
if (index_item >= 0 && index_item < field->m_arSRCSXOPER.size())
{
SXOPER* cache = dynamic_cast<SXOPER*>(field->m_arSRCSXOPER[index_item].get());
if (cache)
{
cache->bFormula = true;
}
}
}
}
}
}
}
return true; return true;
} }
......
...@@ -43,6 +43,8 @@ namespace XLS ...@@ -43,6 +43,8 @@ namespace XLS
SXOPER::SXOPER() SXOPER::SXOPER()
{ {
bFormula= false;
bString = false; bString = false;
bDate = false; bDate = false;
bNumber = false; bNumber = false;
...@@ -66,10 +68,10 @@ const bool SXOPER::loadContent(BinProcessor& proc) ...@@ -66,10 +68,10 @@ const bool SXOPER::loadContent(BinProcessor& proc)
if(proc.optional<SxNil>()) if(proc.optional<SxNil>())
{ {
bEmpty = true; bEmpty = true;
node = L"m";
} }
else if(proc.optional<SXNum>()) else if(proc.optional<SXNum>())
{ {
SXNum *num = dynamic_cast<SXNum*>(elements_.back().get()); SXNum *num = dynamic_cast<SXNum*>(elements_.back().get());
if (num) if (num)
{ {
...@@ -79,22 +81,36 @@ const bool SXOPER::loadContent(BinProcessor& proc) ...@@ -79,22 +81,36 @@ const bool SXOPER::loadContent(BinProcessor& proc)
num->num.data.bytes.Byte4==0); num->num.data.bytes.Byte4==0);
} }
bNumber = !bInteger; bNumber = !bInteger;
node = L"n";
value = std::to_wstring(num->num.data.value);
} }
else if(proc.optional<SxBool>()) else if(proc.optional<SxBool>())
{ {
SxBool* b = dynamic_cast<SxBool*>(elements_.back().get());
bBool = true; bBool = true;
node = L"b";
value = std::to_wstring(b->val);
} }
else if(proc.optional<SxErr>()) else if(proc.optional<SxErr>())
{ {
SxErr* err = dynamic_cast<SxErr*>(elements_.back().get());
bNumber = true; bNumber = true;
node = L"e";
value = std::to_wstring(err->wbe);
} }
else if(proc.optional<SXString>()) else if(proc.optional<SXString>())
{ {
SXString* str = dynamic_cast<SXString*>(elements_.back().get());
bString = true; bString = true;
node = L"s";
value = str->value();
} }
else if(proc.optional<SXDtr>()) else if(proc.optional<SXDtr>())
{ {
bDate =true; SXDtr* dtr = dynamic_cast<SXDtr*>(elements_.back().get());
bDate = true;
node = L"d";
value = dtr->value();
} }
else else
return false; return false;
...@@ -102,44 +118,29 @@ const bool SXOPER::loadContent(BinProcessor& proc) ...@@ -102,44 +118,29 @@ const bool SXOPER::loadContent(BinProcessor& proc)
m_element = elements_.back(); m_element = elements_.back();
elements_.pop_back(); elements_.pop_back();
return true; return true;
} }
int SXOPER::serialize(std::wostream & strm) int SXOPER::serialize(std::wostream & strm)
{ {
if (!m_element) return 0; if (!m_element) return 0;
if (node.empty()) return 0;
m_element->serialize(strm); CP_XML_WRITER(strm)
return 0;
}
std::wstring SXOPER::get_value()
{
std::wstring value;
SXNum *num = dynamic_cast<SXNum*>(m_element.get());
if (num)
{ {
value = std::to_wstring(num->num.data.value); CP_XML_NODE(node)
}
else
{ {
SXString *str = dynamic_cast<SXString*>(m_element.get()); if (!value.empty())
if (str)
{ {
value = str->segment.value(); CP_XML_ATTR(L"v", value);
} }
else if (bFormula)
{
SXDtr *dtr = dynamic_cast<SXDtr*>(m_element.get());
if (dtr)
{ {
value = dtr->get_string_date(); CP_XML_ATTR(L"f", 1);
} }
else
{
} }
} }
} return 0;
return value;
} }
} // namespace XLS } // namespace XLS
......
...@@ -49,18 +49,21 @@ public: ...@@ -49,18 +49,21 @@ public:
int serialize(std::wostream & strm); int serialize(std::wostream & strm);
std::wstring get_value();
static const ElementType type = typeSXOPER; static const ElementType type = typeSXOPER;
BaseObjectPtr m_element; BaseObjectPtr m_element;
bool bFormula;
bool bString; bool bString;
bool bDate; bool bDate;
bool bNumber; bool bNumber;
bool bEmpty; bool bEmpty;
bool bInteger; bool bInteger;
bool bBool; bool bBool;
std::wstring value;
std::wstring node;
}; };
} // namespace XLS } // namespace XLS
......
...@@ -140,8 +140,8 @@ int SXRANGE::serialize(std::wostream & strm) ...@@ -140,8 +140,8 @@ int SXRANGE::serialize(std::wostream & strm)
SXDtr* startDate = dynamic_cast<SXDtr*>(m_arSXDtr[0].get()); SXDtr* startDate = dynamic_cast<SXDtr*>(m_arSXDtr[0].get());
SXDtr* endDate = dynamic_cast<SXDtr*>(m_arSXDtr[1].get()); SXDtr* endDate = dynamic_cast<SXDtr*>(m_arSXDtr[1].get());
CP_XML_ATTR(L"startDate", startDate->get_string_date()); CP_XML_ATTR(L"startDate", startDate->value());
CP_XML_ATTR(L"endDate", endDate->get_string_date()); CP_XML_ATTR(L"endDate", endDate->value());
} }
if (m_arSXNum.size() == 3) if (m_arSXNum.size() == 3)
{ {
......
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