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,10 +42,11 @@ void Formula::readFields(CFRecord& record)
{
unsigned short flags;
record >> cell >> val >> flags;
fAlwaysCalc = GETBIT(flags, 0);
fFill = GETBIT(flags, 2);
fShrFmla = GETBIT(flags, 3);
fClearErrors = GETBIT(flags, 5);
fAlwaysCalc = GETBIT(flags, 0);
fFill = GETBIT(flags, 2);
fShrFmla = GETBIT(flags, 3);
fClearErrors = GETBIT(flags, 5);
unsigned int chn = 0;
record >> chn;
......
......@@ -25,16 +25,9 @@ public:
static const ElementType type = typeShrFmla;
//-----------------------------
RefU ref_;
BackwardOnlyParam<unsigned char> cUse;
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
RefU ref_;
BackwardOnlyParam<unsigned char> cUse;
SharedParsedFormula formula;
};
......
......@@ -74,22 +74,6 @@ BiffStructurePtr CellRangeRef::clone()
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
{
if(to_string_cache.empty())
......@@ -185,20 +169,20 @@ const CellRef CellRangeRef::getTopLeftCell() const
void CellRangeRef::operator+=(const CellRef& appended_ref)
{
rowFirst += rowFirstRelative ? appended_ref.getRow() : 0;
rowLast += rowLastRelative ? appended_ref.getRow() : 0;
rowFirst += rowFirstRelative ? appended_ref.getRow() : 0;
rowLast += rowLastRelative ? appended_ref.getRow() : 0;
columnFirst += columnFirstRelative ? appended_ref.getColumn() : 0;
columnLast += columnLastRelative ? appended_ref.getColumn() : 0;
columnLast += columnLastRelative ? appended_ref.getColumn() : 0;
to_string_cache.clear();
}
void CellRangeRef::operator-=(const CellRef& subtracted_ref)
{
rowFirst -= rowFirstRelative ? subtracted_ref.getRow() : 0;
rowLast -= rowLastRelative ? subtracted_ref.getRow() : 0;
rowFirst -= rowFirstRelative ? subtracted_ref.getRow() : 0;
rowLast -= rowLastRelative ? subtracted_ref.getRow() : 0;
columnFirst -= columnFirstRelative ? subtracted_ref.getColumn() : 0;
columnLast -= columnLastRelative ? subtracted_ref.getColumn() : 0;
columnLast -= columnLastRelative ? subtracted_ref.getColumn() : 0;
to_string_cache.clear();
}
......@@ -216,6 +200,13 @@ void CellRangeRef::setRowRelativity(const bool is_relative)
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
......@@ -27,22 +27,24 @@ public:
static const ElementType type = typeCellRangeRef;
const std::wstring toString(const bool useShortForm = true) const;
void fromString(const std::wstring& str);
const std::wstring toString(const bool useShortForm = true) const;
void fromString(const std::wstring& str);
operator const std::wstring () const;
const CellRef getTopLeftCell() const;
const int getRowFirst() const { return rowFirst; }
const int getRowLast() const { return rowLast; }
const bool getRowFirstRelative() const { return rowFirstRelative; }
const bool getRowLastRelative() const { return rowLastRelative; }
const int getColumnFirst() const { return columnFirst; }
const int getColumnLast() const { return columnLast; }
const bool getColumnFirstRelative() const { return columnFirstRelative; }
const bool getColumnLastRelative() const { return columnLastRelative; }
void setColumnRelativity(const bool is_relative);
void setRowRelativity(const bool is_relative);
const int getRowFirst() const { return rowFirst; }
const int getRowLast() const { return rowLast; }
const bool getRowFirstRelative() const { return rowFirstRelative; }
const bool getRowLastRelative() const { return rowLastRelative; }
const int getColumnFirst() const { return columnFirst; }
const int getColumnLast() const { return columnLast; }
const bool getColumnFirstRelative() const { return columnFirstRelative; }
const bool getColumnLastRelative() const { return columnLastRelative; }
void setColumnRelativity(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& subtracted_ref);
......@@ -50,14 +52,14 @@ public:
virtual void load(CFRecord& record) {}
virtual void store(CFRecord& record) {}
int rowFirst;
int rowLast;
bool rowFirstRelative;
bool rowLastRelative;
int columnFirst;
int columnLast;
bool columnFirstRelative;
bool columnLastRelative;
int rowFirst;
int rowLast;
bool rowFirstRelative;
bool rowLastRelative;
int columnFirst;
int columnLast;
bool columnFirstRelative;
bool columnLastRelative;
mutable std::wstring to_string_cache;
......
......@@ -7,8 +7,8 @@ namespace XLS
class CellRef : public BiffStructure
{
BASE_STRUCTURE_DEFINE_CLASS_NAME(CellRef)
public:
BASE_STRUCTURE_DEFINE_CLASS_NAME(CellRef)
CellRef();
CellRef(const std::wstring str);
......@@ -16,11 +16,10 @@ public:
BiffStructurePtr clone();
static const ElementType type = typeCellRef;
static const ElementType type = typeCellRef;
const std::wstring toString() const;
void fromString(const std::wstring& str);
const std::wstring toString() const;
void fromString(const std::wstring& str);
operator const std::wstring () const;
void operator+=(const CellRef& appended_ref);
......@@ -31,17 +30,17 @@ private:
virtual void store(CFRecord& record) {}
public:
const int getRow() const;
const int getColumn() const;
const bool getRowRelative() const;
const bool getColumnRelative() const;
const int getRow() const;
const int getColumn() const;
const bool getRowRelative() const;
const bool getColumnRelative() const;
protected:
int row;
int column;
bool rowRelative;
bool colRelative;
bool fQuoted;
int row;
int column;
bool rowRelative;
bool colRelative;
bool fQuoted;
mutable std::wstring to_string_cache;
......
......@@ -22,11 +22,11 @@ public:
static const ElementType type = typeParsedFormula;
Rgce rgce;
RgbExtra rgcb;
Rgce rgce;
RgbExtra rgcb;
size_t cce; // Size of rgce variable. Setting explicit is mandatory
bool cce_is_set;
size_t cce; // Size of rgce variable. Setting explicit is mandatory
bool cce_is_set;
};
} // namespace XLS
......
......@@ -23,6 +23,7 @@ void SharedParsedFormula::load(CFRecord& record)
{
unsigned short cce;
record >> cce;
rgce.load(record, cce);
rgcb.load(record, rgce.getPtgs(), is_part_of_a_revision_);
}
......
......@@ -13,10 +13,10 @@ class SharedParsedFormula : public ParsedFormula
public:
SharedParsedFormula(const bool is_part_of_a_revision, const CellRef& cell_base_ref);
BiffStructurePtr clone();
virtual void load(CFRecord& record);
virtual void store(CFRecord& record);
private:
bool is_part_of_a_revision_;
};
......
......@@ -12,7 +12,7 @@ class CELL: public CompositeObject
{
BASE_OBJECT_DEFINE_CLASS_NAME(CELL)
public:
CELL(std::vector<CellRef>& shared_formulas_locations_ref);
CELL(std::vector<CellRangeRef>& shared_formulas_locations_ref);
~CELL();
BaseObjectPtr clone();
......@@ -25,7 +25,7 @@ public:
int RowNumber;
std::vector<CellRef>& shared_formulas_locations_ref_;
std::vector<CellRangeRef>& shared_formulas_locations_ref_;
};
} // namespace XLS
......
......@@ -17,7 +17,7 @@ class CELL_GROUP : public CompositeObject
{
BASE_OBJECT_DEFINE_CLASS_NAME(CELL_GROUP)
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)
{
}
......@@ -76,7 +76,7 @@ public:
std::list<BaseObjectPtr> m_DBCells;
private:
std::vector<CellRef>& shared_formulas_locations_ref_;
std::vector<CellRangeRef>& shared_formulas_locations_ref_;
};
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)
,shared_formulas_locations_ref_(shared_formulas_locations_ref)
{
......
......@@ -12,7 +12,7 @@ class CELLTABLE: public CompositeObject
{
BASE_OBJECT_DEFINE_CLASS_NAME(CELLTABLE)
public:
CELLTABLE(std::vector<CellRef>& shared_formulas_locations_ref);
CELLTABLE(std::vector<CellRangeRef>& shared_formulas_locations_ref);
~CELLTABLE();
BaseObjectPtr clone();
......@@ -23,7 +23,7 @@ public:
int serialize(std::wostream & stream);
std::vector<CellRef>& shared_formulas_locations_ref_;
std::vector<CellRangeRef>& shared_formulas_locations_ref_;
int m_count_CELL_GROUP;
};
......
......@@ -14,7 +14,7 @@
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 @@
#include <Logic/CompositeObject.h>
#include <Logic/Biff_structures/CellRef.h>
#include <Logic/Biff_structures/CellRangeRef.h>
namespace XLS
{
......@@ -13,7 +14,7 @@ class FORMULA: public CompositeObject
{
BASE_OBJECT_DEFINE_CLASS_NAME(FORMULA)
public:
FORMULA(std::vector<CellRef>& shared_formulas_locations_ref);
FORMULA(std::vector<CellRangeRef>& shared_formulas_locations_ref);
~FORMULA();
BaseObjectPtr clone();
......@@ -30,10 +31,11 @@ public:
BaseObjectPtr m_ArrayFormula;
BaseObjectPtr m_SharedFormula;
CellRef location;
std::vector<CellRef>& shared_formulas_locations_ref_;
std::vector<CellRangeRef>& shared_formulas_locations_ref_;
int m_sharedIndex;
};
} // namespace XLS
......
......@@ -17,8 +17,9 @@ namespace XLS
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)
m_SharedFormula = elements_.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
}
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>())
{
proc.repeated<Continue>(0, 0);
......@@ -92,7 +102,8 @@ const CellRef FORMULA::getLocation() const
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;
......@@ -114,6 +125,7 @@ int FORMULA::serialize(std::wostream & stream)
case 1: CP_XML_ATTR(L"t", L"b"); break;
case 2: CP_XML_ATTR(L"t", L"e"); break;
}
const std::wstring & f_ = formula->formula.getAssembledFormula();
if (!f_.empty())
{
......@@ -122,6 +134,27 @@ int FORMULA::serialize(std::wostream & stream)
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();
if (!str_val.empty())
{
......
......@@ -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)
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
......
......@@ -13,7 +13,7 @@ class SHFMLA_SET: public CompositeObject
{
BASE_OBJECT_DEFINE_CLASS_NAME(SHFMLA_SET)
public:
SHFMLA_SET(std::vector<CellRef>& shared_formulas_locations_ref);
SHFMLA_SET(std::vector<CellRangeRef>& shared_formulas_locations_ref);
~SHFMLA_SET();
BaseObjectPtr clone();
......@@ -22,7 +22,7 @@ public:
static const ElementType type = typeSHFMLA_SET;
std::vector<CellRef>& shared_formulas_locations_ref_;
std::vector<CellRangeRef> & shared_formulas_locations_ref_;
};
} // namespace XLS
......
......@@ -5,8 +5,9 @@
#include <vector>
#include <map>
#include <Logic/Biff_structures/BorderFillInfo.h>
#include "../Crypt/Decryptor.h"
#include "Biff_structures/BorderFillInfo.h"
namespace XLS
{;
......
......@@ -81,7 +81,7 @@ const bool MacroSheetSubstream::loadContent(BinProcessor& proc)
proc.mandatory<MACROSORTANDFILTER>();
proc.mandatory<Dimensions>();
std::vector<CellRef> shared_formulas_locations;
std::vector<CellRangeRef> shared_formulas_locations;
CELLTABLE cell_table(shared_formulas_locations);
proc.optional(cell_table);
......
......@@ -136,7 +136,7 @@ const bool WorksheetSubstream::loadContent(BinProcessor& proc)
elements_.pop_back();
}
std::vector<CellRef> shared_formulas_locations;
std::vector<CellRangeRef> shared_formulas_locations;
CELLTABLE cell_table(shared_formulas_locations);
if (proc.optional(cell_table))
{
......@@ -147,7 +147,8 @@ const bool WorksheetSubstream::loadContent(BinProcessor& proc)
if(0 != shared_formulas_locations.size())
{
SHFMLA_SET shfmla_set(shared_formulas_locations);
if (proc.optional(shfmla_set))
if (proc.optional(shfmla_set))
{
m_SHFMLA_SET = elements_.back();
elements_.pop_back();
......
#pragma once
#include <Logic/CompositeObject.h>
#include <Logic/Biff_structures/CellRef.h>
namespace XLS
{;
// Logical representation of WorksheetSubstream union of records
class WorksheetSubstream;
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