Commit a88ad0c2 authored by ElenaSubbotina's avatar ElenaSubbotina

XlsFormat - fix calculations in pivot tables

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