Commit a2de12ab authored by Elen.Subbotina's avatar Elen.Subbotina Committed by Alexander Trofimov

XLSFormat - shared formulas

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@65716 954022d7-b5bf-4e40-9824-e11837661b57
parent 5ec62192
...@@ -42,6 +42,7 @@ void Formula::readFields(CFRecord& record) ...@@ -42,6 +42,7 @@ void Formula::readFields(CFRecord& record)
{ {
unsigned short flags; unsigned short flags;
record >> cell >> val >> flags; record >> cell >> val >> flags;
fAlwaysCalc = GETBIT(flags, 0); fAlwaysCalc = GETBIT(flags, 0);
fFill = GETBIT(flags, 2); fFill = GETBIT(flags, 2);
fShrFmla = GETBIT(flags, 3); fShrFmla = GETBIT(flags, 3);
......
...@@ -29,13 +29,6 @@ public: ...@@ -29,13 +29,6 @@ public:
BackwardOnlyParam<unsigned char> cUse; BackwardOnlyParam<unsigned char> cUse;
SharedParsedFormula formula; SharedParsedFormula formula;
public:
//BO_ATTRIB_MARKUP_BEGIN
//BO_ATTRIB_MARKUP_COMPLEX(ref_)
//BO_ATTRIB_MARKUP_ATTRIB(cUse)
//BO_ATTRIB_MARKUP_COMPLEX(formula)
//BO_ATTRIB_MARKUP_END
}; };
typedef boost::shared_ptr<ShrFmla> ShrFmlaPtr; typedef boost::shared_ptr<ShrFmla> ShrFmlaPtr;
......
...@@ -74,22 +74,6 @@ BiffStructurePtr CellRangeRef::clone() ...@@ -74,22 +74,6 @@ BiffStructurePtr CellRangeRef::clone()
return BiffStructurePtr(new CellRangeRef(*this)); return BiffStructurePtr(new CellRangeRef(*this));
} }
//
//void CellRangeRef::getXMLAttributes(MSXML2::IXMLDOMElementPtr xml_tag)
//{
// std::wstring name = getStructAttribute(xml_tag, L"name");
// fromString(static_cast<wchar_t*>(name));
//}
//
//
//void CellRangeRef::(MSXML2::IXMLDOMElementPtr xml_tag)
//{
// xml_tag->setAttribute(L"name", toString().c_str());
// xml_tag->setAttribute(L"top_left_cell", getTopLeftCell().toString().c_str());
// xml_tag->setAttribute(L"bottom_right_cell", CellRef(rowLast, columnLast, rowLastRelative, columnLastRelative).toString().c_str());
//}
const std::wstring CellRangeRef::toString(const bool useShortForm) const const std::wstring CellRangeRef::toString(const bool useShortForm) const
{ {
if(to_string_cache.empty()) if(to_string_cache.empty())
...@@ -216,6 +200,13 @@ void CellRangeRef::setRowRelativity(const bool is_relative) ...@@ -216,6 +200,13 @@ void CellRangeRef::setRowRelativity(const bool is_relative)
to_string_cache.clear(); to_string_cache.clear();
} }
bool CellRangeRef::inRange(const CellRef& cell)
{
if (cell.getColumn() <= columnLast && cell.getColumn() >= columnFirst &&
cell.getRow() <= rowLast && cell.getRow() >= rowFirst) return true;
return false;
}
} // namespace XLS } // namespace XLS
...@@ -44,6 +44,8 @@ public: ...@@ -44,6 +44,8 @@ public:
void setColumnRelativity(const bool is_relative); void setColumnRelativity(const bool is_relative);
void setRowRelativity(const bool is_relative); void setRowRelativity(const bool is_relative);
bool inRange(const CellRef& cell);
void operator+=(const CellRef& appended_ref); void operator+=(const CellRef& appended_ref);
void operator-=(const CellRef& subtracted_ref); void operator-=(const CellRef& subtracted_ref);
......
...@@ -7,8 +7,8 @@ namespace XLS ...@@ -7,8 +7,8 @@ namespace XLS
class CellRef : public BiffStructure class CellRef : public BiffStructure
{ {
BASE_STRUCTURE_DEFINE_CLASS_NAME(CellRef)
public: public:
BASE_STRUCTURE_DEFINE_CLASS_NAME(CellRef)
CellRef(); CellRef();
CellRef(const std::wstring str); CellRef(const std::wstring str);
...@@ -18,7 +18,6 @@ public: ...@@ -18,7 +18,6 @@ public:
static const ElementType type = typeCellRef; static const ElementType type = typeCellRef;
const std::wstring toString() const; const std::wstring toString() const;
void fromString(const std::wstring& str); void fromString(const std::wstring& str);
operator const std::wstring () const; operator const std::wstring () const;
......
...@@ -23,6 +23,7 @@ void SharedParsedFormula::load(CFRecord& record) ...@@ -23,6 +23,7 @@ void SharedParsedFormula::load(CFRecord& record)
{ {
unsigned short cce; unsigned short cce;
record >> cce; record >> cce;
rgce.load(record, cce); rgce.load(record, cce);
rgcb.load(record, rgce.getPtgs(), is_part_of_a_revision_); rgcb.load(record, rgce.getPtgs(), is_part_of_a_revision_);
} }
......
...@@ -13,10 +13,10 @@ class SharedParsedFormula : public ParsedFormula ...@@ -13,10 +13,10 @@ class SharedParsedFormula : public ParsedFormula
public: public:
SharedParsedFormula(const bool is_part_of_a_revision, const CellRef& cell_base_ref); SharedParsedFormula(const bool is_part_of_a_revision, const CellRef& cell_base_ref);
BiffStructurePtr clone(); BiffStructurePtr clone();
virtual void load(CFRecord& record); virtual void load(CFRecord& record);
virtual void store(CFRecord& record); virtual void store(CFRecord& record);
private:
bool is_part_of_a_revision_; bool is_part_of_a_revision_;
}; };
......
...@@ -12,7 +12,7 @@ class CELL: public CompositeObject ...@@ -12,7 +12,7 @@ class CELL: public CompositeObject
{ {
BASE_OBJECT_DEFINE_CLASS_NAME(CELL) BASE_OBJECT_DEFINE_CLASS_NAME(CELL)
public: public:
CELL(std::vector<CellRef>& shared_formulas_locations_ref); CELL(std::vector<CellRangeRef>& shared_formulas_locations_ref);
~CELL(); ~CELL();
BaseObjectPtr clone(); BaseObjectPtr clone();
...@@ -25,7 +25,7 @@ public: ...@@ -25,7 +25,7 @@ public:
int RowNumber; int RowNumber;
std::vector<CellRef>& shared_formulas_locations_ref_; std::vector<CellRangeRef>& shared_formulas_locations_ref_;
}; };
} // namespace XLS } // namespace XLS
......
...@@ -17,7 +17,7 @@ class CELL_GROUP : public CompositeObject ...@@ -17,7 +17,7 @@ class CELL_GROUP : public CompositeObject
{ {
BASE_OBJECT_DEFINE_CLASS_NAME(CELL_GROUP) BASE_OBJECT_DEFINE_CLASS_NAME(CELL_GROUP)
public: public:
CELL_GROUP(std::vector<CellRef>& shared_formulas_locations_ref) : CELL_GROUP(std::vector<CellRangeRef>& shared_formulas_locations_ref) :
shared_formulas_locations_ref_(shared_formulas_locations_ref) shared_formulas_locations_ref_(shared_formulas_locations_ref)
{ {
} }
...@@ -76,7 +76,7 @@ public: ...@@ -76,7 +76,7 @@ public:
std::list<BaseObjectPtr> m_DBCells; std::list<BaseObjectPtr> m_DBCells;
private: private:
std::vector<CellRef>& shared_formulas_locations_ref_; std::vector<CellRangeRef>& shared_formulas_locations_ref_;
}; };
int CELL_GROUP::serialize(std::wostream & stream) int CELL_GROUP::serialize(std::wostream & stream)
...@@ -245,7 +245,7 @@ int CELL_GROUP::serialize(std::wostream & stream) ...@@ -245,7 +245,7 @@ int CELL_GROUP::serialize(std::wostream & stream)
//----------------------------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------------------------
CELLTABLE::CELLTABLE(std::vector<CellRef>& shared_formulas_locations_ref) : CELLTABLE::CELLTABLE(std::vector<CellRangeRef>& shared_formulas_locations_ref) :
m_count_CELL_GROUP(0) m_count_CELL_GROUP(0)
,shared_formulas_locations_ref_(shared_formulas_locations_ref) ,shared_formulas_locations_ref_(shared_formulas_locations_ref)
{ {
......
...@@ -12,7 +12,7 @@ class CELLTABLE: public CompositeObject ...@@ -12,7 +12,7 @@ class CELLTABLE: public CompositeObject
{ {
BASE_OBJECT_DEFINE_CLASS_NAME(CELLTABLE) BASE_OBJECT_DEFINE_CLASS_NAME(CELLTABLE)
public: public:
CELLTABLE(std::vector<CellRef>& shared_formulas_locations_ref); CELLTABLE(std::vector<CellRangeRef>& shared_formulas_locations_ref);
~CELLTABLE(); ~CELLTABLE();
BaseObjectPtr clone(); BaseObjectPtr clone();
...@@ -23,7 +23,7 @@ public: ...@@ -23,7 +23,7 @@ public:
int serialize(std::wostream & stream); int serialize(std::wostream & stream);
std::vector<CellRef>& shared_formulas_locations_ref_; std::vector<CellRangeRef>& shared_formulas_locations_ref_;
int m_count_CELL_GROUP; int m_count_CELL_GROUP;
}; };
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
namespace XLS namespace XLS
{ {
CELL::CELL(std::vector<CellRef>& shared_formulas_locations_ref) : shared_formulas_locations_ref_(shared_formulas_locations_ref) CELL::CELL(std::vector<CellRangeRef>& shared_formulas_locations_ref) : shared_formulas_locations_ref_(shared_formulas_locations_ref)
{ {
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <Logic/CompositeObject.h> #include <Logic/CompositeObject.h>
#include <Logic/Biff_structures/CellRef.h> #include <Logic/Biff_structures/CellRef.h>
#include <Logic/Biff_structures/CellRangeRef.h>
namespace XLS namespace XLS
{ {
...@@ -13,7 +14,7 @@ class FORMULA: public CompositeObject ...@@ -13,7 +14,7 @@ class FORMULA: public CompositeObject
{ {
BASE_OBJECT_DEFINE_CLASS_NAME(FORMULA) BASE_OBJECT_DEFINE_CLASS_NAME(FORMULA)
public: public:
FORMULA(std::vector<CellRef>& shared_formulas_locations_ref); FORMULA(std::vector<CellRangeRef>& shared_formulas_locations_ref);
~FORMULA(); ~FORMULA();
BaseObjectPtr clone(); BaseObjectPtr clone();
...@@ -30,10 +31,11 @@ public: ...@@ -30,10 +31,11 @@ public:
BaseObjectPtr m_ArrayFormula; BaseObjectPtr m_ArrayFormula;
BaseObjectPtr m_SharedFormula; BaseObjectPtr m_SharedFormula;
CellRef location; CellRef location;
std::vector<CellRef>& shared_formulas_locations_ref_; std::vector<CellRangeRef>& shared_formulas_locations_ref_;
int m_sharedIndex;
}; };
} // namespace XLS } // namespace XLS
......
...@@ -17,8 +17,9 @@ namespace XLS ...@@ -17,8 +17,9 @@ namespace XLS
extern int cellStyleXfs_count; extern int cellStyleXfs_count;
FORMULA::FORMULA(std::vector<CellRef>& shared_formulas_locations_ref) : shared_formulas_locations_ref_(shared_formulas_locations_ref) FORMULA::FORMULA(std::vector<CellRangeRef>& shared_formulas_locations_ref) : shared_formulas_locations_ref_(shared_formulas_locations_ref)
{ {
m_sharedIndex = -1;
} }
...@@ -72,11 +73,20 @@ const bool FORMULA::loadContent(BinProcessor& proc) ...@@ -72,11 +73,20 @@ const bool FORMULA::loadContent(BinProcessor& proc)
m_SharedFormula = elements_.back(); m_SharedFormula = elements_.back();
elements_.pop_back(); elements_.pop_back();
shared_formulas_locations_ref_.push_back(location); m_sharedIndex = shared_formulas_locations_ref_.size();
shared_formulas_locations_ref_.push_back(shr_formula.ref_);
} }
//proc.optional<SUB>(); // I haven't found any mention about SUB in the docs //proc.optional<SUB>(); // I haven't found any mention about SUB in the docs
} }
if ((formula) && (formula->fShrFmla.value()) && (formula->fShrFmla))
{
for (int i = 0; i < shared_formulas_locations_ref_.size(); i++)
{
if (shared_formulas_locations_ref_[i].inRange(location)) m_sharedIndex = i;
}
}
if(proc.optional<String>()) if(proc.optional<String>())
{ {
proc.repeated<Continue>(0, 0); proc.repeated<Continue>(0, 0);
...@@ -93,6 +103,7 @@ const CellRef FORMULA::getLocation() const ...@@ -93,6 +103,7 @@ const CellRef FORMULA::getLocation() const
int FORMULA::serialize(std::wostream & stream) int FORMULA::serialize(std::wostream & stream)
{ {
Formula *formula = dynamic_cast<Formula *>(m_Formula.get()); Formula *formula = dynamic_cast<Formula *>(m_Formula.get());
ShrFmla *shared = dynamic_cast<ShrFmla *>(m_SharedFormula.get());
if (formula == NULL) return 0; if (formula == NULL) return 0;
...@@ -114,6 +125,7 @@ int FORMULA::serialize(std::wostream & stream) ...@@ -114,6 +125,7 @@ int FORMULA::serialize(std::wostream & stream)
case 1: CP_XML_ATTR(L"t", L"b"); break; case 1: CP_XML_ATTR(L"t", L"b"); break;
case 2: CP_XML_ATTR(L"t", L"e"); break; case 2: CP_XML_ATTR(L"t", L"e"); break;
} }
const std::wstring & f_ = formula->formula.getAssembledFormula(); const std::wstring & f_ = formula->formula.getAssembledFormula();
if (!f_.empty()) if (!f_.empty())
{ {
...@@ -122,6 +134,27 @@ int FORMULA::serialize(std::wostream & stream) ...@@ -122,6 +134,27 @@ int FORMULA::serialize(std::wostream & stream)
CP_XML_STREAM() << xml::utils::replace_text_to_xml(f_); CP_XML_STREAM() << xml::utils::replace_text_to_xml(f_);
} }
} }
else if (shared)
{
const std::wstring & f_ = shared->formula.getAssembledFormula();
CP_XML_NODE(L"f")
{
std::wstring shared_ref = shared->ref_.toString();
CP_XML_ATTR(L"ref", shared_ref);
CP_XML_ATTR(L"t", L"shared");
CP_XML_ATTR(L"si", m_sharedIndex);
CP_XML_STREAM() << xml::utils::replace_text_to_xml(f_);
}
}
else if ((formula->fShrFmla.value()) && (formula->fShrFmla == true) && m_sharedIndex >= 0)
{
CP_XML_NODE(L"f")
{
CP_XML_ATTR(L"t", L"shared");
CP_XML_ATTR(L"si", m_sharedIndex);
}
}
std::wstring str_val = formula->val.getValue(); std::wstring str_val = formula->val.getValue();
if (!str_val.empty()) if (!str_val.empty())
{ {
......
...@@ -6,7 +6,8 @@ namespace XLS ...@@ -6,7 +6,8 @@ namespace XLS
{ {
SHFMLA_SET::SHFMLA_SET(std::vector<CellRef>& shared_formulas_locations_ref) : shared_formulas_locations_ref_(shared_formulas_locations_ref) SHFMLA_SET::SHFMLA_SET(std::vector<CellRangeRef>& shared_formulas_locations_ref) :
shared_formulas_locations_ref_(shared_formulas_locations_ref)
{ {
} }
...@@ -27,18 +28,6 @@ const bool SHFMLA_SET::loadContent(BinProcessor& proc) ...@@ -27,18 +28,6 @@ const bool SHFMLA_SET::loadContent(BinProcessor& proc)
return true; return true;
} }
//void SHFMLA_SET::toXML(MSXML2::IXMLDOMElementPtr own_tag)
//{
// size_t counter = 0;
// for(std::vector<CellRef>::const_iterator it = shared_formulas_locations_ref_.begin(), itEnd = shared_formulas_locations_ref_.end(); it != itEnd; ++it)
// {
// MSXML2::IXMLDOMElementPtr shrfmla_tag = XMLSTUFF::createElement(L"shfmla", own_tag);
// shrfmla_tag->setAttribute(L"si", counter++);
// shrfmla_tag->setAttribute(L"ref", it->toString().c_str());
// shrfmla_tag->setAttribute(L"row", it->getRow());
// shrfmla_tag->setAttribute(L"col", it->getColumn());
// }
//}
} // namespace XLS } // namespace XLS
......
...@@ -13,7 +13,7 @@ class SHFMLA_SET: public CompositeObject ...@@ -13,7 +13,7 @@ class SHFMLA_SET: public CompositeObject
{ {
BASE_OBJECT_DEFINE_CLASS_NAME(SHFMLA_SET) BASE_OBJECT_DEFINE_CLASS_NAME(SHFMLA_SET)
public: public:
SHFMLA_SET(std::vector<CellRef>& shared_formulas_locations_ref); SHFMLA_SET(std::vector<CellRangeRef>& shared_formulas_locations_ref);
~SHFMLA_SET(); ~SHFMLA_SET();
BaseObjectPtr clone(); BaseObjectPtr clone();
...@@ -22,7 +22,7 @@ public: ...@@ -22,7 +22,7 @@ public:
static const ElementType type = typeSHFMLA_SET; static const ElementType type = typeSHFMLA_SET;
std::vector<CellRef>& shared_formulas_locations_ref_; std::vector<CellRangeRef> & shared_formulas_locations_ref_;
}; };
} // namespace XLS } // namespace XLS
......
...@@ -5,8 +5,9 @@ ...@@ -5,8 +5,9 @@
#include <vector> #include <vector>
#include <map> #include <map>
#include <Logic/Biff_structures/BorderFillInfo.h>
#include "../Crypt/Decryptor.h" #include "../Crypt/Decryptor.h"
#include "Biff_structures/BorderFillInfo.h"
namespace XLS namespace XLS
{; {;
......
...@@ -81,7 +81,7 @@ const bool MacroSheetSubstream::loadContent(BinProcessor& proc) ...@@ -81,7 +81,7 @@ const bool MacroSheetSubstream::loadContent(BinProcessor& proc)
proc.mandatory<MACROSORTANDFILTER>(); proc.mandatory<MACROSORTANDFILTER>();
proc.mandatory<Dimensions>(); proc.mandatory<Dimensions>();
std::vector<CellRef> shared_formulas_locations; std::vector<CellRangeRef> shared_formulas_locations;
CELLTABLE cell_table(shared_formulas_locations); CELLTABLE cell_table(shared_formulas_locations);
proc.optional(cell_table); proc.optional(cell_table);
......
...@@ -136,7 +136,7 @@ const bool WorksheetSubstream::loadContent(BinProcessor& proc) ...@@ -136,7 +136,7 @@ const bool WorksheetSubstream::loadContent(BinProcessor& proc)
elements_.pop_back(); elements_.pop_back();
} }
std::vector<CellRef> shared_formulas_locations; std::vector<CellRangeRef> shared_formulas_locations;
CELLTABLE cell_table(shared_formulas_locations); CELLTABLE cell_table(shared_formulas_locations);
if (proc.optional(cell_table)) if (proc.optional(cell_table))
{ {
...@@ -147,6 +147,7 @@ const bool WorksheetSubstream::loadContent(BinProcessor& proc) ...@@ -147,6 +147,7 @@ const bool WorksheetSubstream::loadContent(BinProcessor& proc)
if(0 != shared_formulas_locations.size()) if(0 != shared_formulas_locations.size())
{ {
SHFMLA_SET shfmla_set(shared_formulas_locations); SHFMLA_SET shfmla_set(shared_formulas_locations);
if (proc.optional(shfmla_set)) if (proc.optional(shfmla_set))
{ {
m_SHFMLA_SET = elements_.back(); m_SHFMLA_SET = elements_.back();
......
#pragma once #pragma once
#include <Logic/CompositeObject.h> #include <Logic/CompositeObject.h>
#include <Logic/Biff_structures/CellRef.h>
namespace XLS namespace XLS
{; {;
// Logical representation of WorksheetSubstream union of records // Logical representation of WorksheetSubstream union of records
class WorksheetSubstream; class WorksheetSubstream;
typedef boost::shared_ptr<WorksheetSubstream> WorksheetSubstreamPtr; typedef boost::shared_ptr<WorksheetSubstream> WorksheetSubstreamPtr;
......
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