Commit 4f24ed37 authored by ElenaSubbotina's avatar ElenaSubbotina

XlsFormatReader - dataValidations

parent 036c3b37
......@@ -61,7 +61,7 @@ BaseObjectPtr CF::clone()
void CF::readFields(CFRecord& record)
{
GlobalWorkbookInfoPtr global_info = record.getGlobalWorkbookInfo();
global_info_ = record.getGlobalWorkbookInfo();
unsigned short cce1;
unsigned short cce2;
......@@ -72,10 +72,11 @@ void CF::readFields(CFRecord& record)
rgce1.load(record, cce1);
rgce2.load(record, cce2);
ipriority_ = ++record.getGlobalWorkbookInfo()->cmt_rules;
rgbdxf.serialize(record.getGlobalWorkbookInfo()->users_Dxfs_stream);
dxfId_ = global_info->cellStyleDxfs_count++;
ipriority_ = ++global_info_->cmt_rules;
rgbdxf.serialize(global_info_->users_Dxfs_stream);
dxfId_ = global_info_->cellStyleDxfs_count++;
}
int CF::serialize(std::wostream & stream)
......@@ -84,9 +85,6 @@ int CF::serialize(std::wostream & stream)
return 0;
CFEx * cfEx = dynamic_cast<CFEx *>(m_CFEx.get());
if (cfEx)
{
}
CP_XML_WRITER(stream)
{
......@@ -120,22 +118,31 @@ int CF::serialize(std::wostream & stream)
if ((cfEx) && (cfEx->content.fHasDXF))
{
cfEx->content.dxf.serialize(CP_XML_STREAM());
//cfEx->content.dxf.serialize(CP_XML_STREAM()); - вложенный формат низя?
if (cfEx->dxfId_ >= 0 )
dxfId_ = cfEx->dxfId_;
}
else
{
if (dxfId_ >= 0)
CP_XML_ATTR(L"dxfId", dxfId_);
}
std::wstring s1 = rgce1.getAssembledFormula();
std::wstring s2 = rgce2.getAssembledFormula();
CP_XML_NODE(L"formula")
if (!s1.empty())
{
if (!s1.empty())
CP_XML_NODE(L"formula")
{
CP_XML_STREAM() << xml::utils::replace_text_to_xml(s1);
else if(!s2.empty())
}
}
if(!s2.empty())
{
CP_XML_NODE(L"formula")
{
CP_XML_STREAM() << xml::utils::replace_text_to_xml(s2);
}
}
}
}
......
......@@ -69,6 +69,8 @@ public:
CFParsedFormulaNoCCE rgce2;
BaseObjectPtr m_CFEx;
GlobalWorkbookInfoPtr global_info_;
};
typedef boost::shared_ptr<CF> CFPtr;
......
......@@ -37,6 +37,7 @@ namespace XLS
CFEx::CFEx()
{
dxfId_ = -1;
}
......@@ -57,6 +58,11 @@ void CFEx::readFields(CFRecord& record)
if(!fIsCF12)
{
record >> content;
if (content.dxf.serialize(record.getGlobalWorkbookInfo()->users_Dxfs_stream) >= 0)
{
dxfId_ = record.getGlobalWorkbookInfo()->cellStyleDxfs_count++;
}
}
}
......
......@@ -49,17 +49,17 @@ public:
~CFEx();
BaseObjectPtr clone();
void readFields(CFRecord& record);
static const ElementType type = typeCFEx;
//-----------------------------
FrtRefHeaderU frtRefHeaderU;
unsigned int fIsCF12;
_UINT16 nID;
CFExNonCF12 content;
//-----------------------------
int dxfId_;
};
} // namespace XLS
......
......@@ -53,7 +53,9 @@ BaseObjectPtr DVal::clone()
void DVal::readFields(CFRecord& record)
{
unsigned short flags;
record >> flags >> xLeft >> yTop >> idObj >> idvMac;
fWnClosed = GETBIT(flags, 0);
}
......
......@@ -32,8 +32,33 @@
#include "Dv.h"
#include <utils.h>
#include <boost/algorithm/string.hpp>
namespace XLS
{
static std::wstring replace_zero (const std::wstring &str, const std::wstring &delimetr)
{
if (str.empty()) return L"";
std::wstring out;
int pos = 0;
while(true)
{
if (pos >= str.size()) break;
if (str[pos] == '\0')
{
out += delimetr;
}
else
{
out += str[pos];
}
pos++;
}
return out;
}
BaseObjectPtr Dv::clone()
{
......@@ -45,22 +70,51 @@ void Dv::readFields(CFRecord& record)
_UINT32 flags;
record >> flags;
valType = static_cast<unsigned char>(GETBITS(flags, 0, 3));
errStyle = static_cast<unsigned char>(GETBITS(flags, 4, 6));
valType = static_cast<unsigned char>(GETBITS(flags, 0, 3));
errStyle = static_cast<unsigned char>(GETBITS(flags, 4, 6));
fStrLookup = GETBIT(flags, 7);
fAllowBlank = GETBIT(flags, 8);
fSuppressCombo = GETBIT(flags, 9);
mdImeMode = static_cast<unsigned char>(GETBITS(flags, 10, 17));
fShowInputMsg = GETBIT(flags, 18);
fShowErrorMsg = GETBIT(flags, 19);
typOperator = static_cast<unsigned char>(GETBITS(flags, 20, 23));
fStrLookup = GETBIT(flags, 7);
fAllowBlank = GETBIT(flags, 8);
fSuppressCombo = GETBIT(flags, 9);
mdImeMode = static_cast<unsigned char>(GETBITS(flags, 10, 17));
fShowInputMsg = GETBIT(flags, 18);
fShowErrorMsg = GETBIT(flags, 19);
typOperator = static_cast<unsigned char>(GETBITS(flags, 20, 23));
record >> PromptTitle >> ErrorTitle >> Prompt >> Error;
formula1.load(record);
formula2.load(record);
record >> sqref;
}
int Dv::serialize(std::wostream & stream)
{
CP_XML_WRITER(stream)
{
CP_XML_NODE(L"dataValidation")
{
CP_XML_ATTR(L"sqref", sqref.strValue);
CP_XML_ATTR(L"type", L"list");
std::wstring sFormula1 = replace_zero(formula1.getAssembledFormula(), L",");
std::wstring sFormula2 = replace_zero(formula2.getAssembledFormula(), L",");
if (!sFormula1.empty())
{
//boost::algorithm::replace_all(sFormula1 , "\0", L",");
CP_XML_NODE(L"formula1") {CP_XML_STREAM() << xml::utils::replace_text_to_xml(sFormula1);}
}
if (!sFormula2.empty())
{
//boost::algorithm::replace_all(sFormula2 , "\0", L",");
CP_XML_NODE(L"formula2") {CP_XML_STREAM() << xml::utils::replace_text_to_xml(sFormula2);}
}
}
}
return 0;
}
} // namespace XLS
......@@ -47,30 +47,34 @@ class Dv: public BiffRecord
BASE_OBJECT_DEFINE_CLASS_NAME(Dv)
public:
BaseObjectPtr clone();
void readFields(CFRecord& record);
static const ElementType type = typeDv;
int serialize(std::wostream & stream);
//-----------------------------
unsigned char valType;
unsigned char errStyle;
bool fStrLookup;
bool fAllowBlank;
bool fSuppressCombo;
bool fStrLookup;
bool fAllowBlank;
bool fSuppressCombo;
unsigned char mdImeMode;
bool fShowInputMsg;
bool fShowErrorMsg;
bool fShowInputMsg;
bool fShowErrorMsg;
unsigned char typOperator;
XLUnicodeString PromptTitle;
XLUnicodeString ErrorTitle;
XLUnicodeString Prompt;
XLUnicodeString Error;
DVParsedFormula formula1;
DVParsedFormula formula2;
SqRefU sqref;
SqRefU sqref;
};
......
......@@ -40,7 +40,8 @@ namespace XLS
Pos::Pos()
{
m_iLinkObject = -1;
m_iLinkObject = -1;
m_iLayoutTarget = 0; //not set, 1 - outer, 2 -inner
}
......@@ -98,6 +99,10 @@ int Pos::serialize(std::wostream & _stream)
{
CP_XML_NODE(L"c:manualLayout")
{
if (m_iLayoutTarget > 0)
{
CP_XML_NODE(L"c:layoutTarget"){CP_XML_ATTR(L"val", m_iLayoutTarget == 1 ? L"outer" : L"inner");}
}
//if (m_iLinkObject == 1) x += 0.5 + (w > 0 ? w : 0);
//if (m_iLinkObject == 2) x += 0.5 + (w > 0 ? w : 0);
if (m_iLinkObject == 3) y += 0 + (h > 0 ? h : 0);
......
......@@ -67,6 +67,7 @@ public:
//-----------------------------
int m_iLayoutTarget;
short m_iLinkObject;
BaseObjectPtr m_Frame;
......
......@@ -37,8 +37,7 @@ namespace XLS
{
DVParsedFormula::DVParsedFormula()
: ParsedFormula(CellRef())
DVParsedFormula::DVParsedFormula() : ParsedFormula(CellRef())
{
}
......
......@@ -45,8 +45,6 @@ public:
DVParsedFormula();
BiffStructurePtr clone();
virtual void load(CFRecord& record);
};
} // namespace XLS
......
......@@ -59,13 +59,26 @@ BiffStructurePtr PtgStr::clone()
void PtgStr::loadFields(CFRecord& record)
{
record >> string_;
ShortXLUnicodeString s;
record >> s;
string_ = s;
int pos1 = string_.find(L"\"");
int pos2 = string_.rfind(L"\"");
if (pos1 == 0 && pos2 >= string_.length() - 1)
{
string_ = string_.substr(1, string_.length() - 2);
}
string_ = L"\"" + string_ + L"\"";
}
void PtgStr::assemble(AssemblerStack& ptg_stack, PtgQueue& extra_data, bool full_ref)
{
ptg_stack.push(L"\"" + boost::algorithm::replace_all_copy(std::wstring(string_), L"\"", L"\"\"") + L"\"");
ptg_stack.push(string_);
}
......
......@@ -47,7 +47,6 @@ public:
PtgStr(const std::wstring & str);
BiffStructurePtr clone();
virtual void loadFields(CFRecord& record);
......@@ -56,7 +55,7 @@ public:
static const unsigned short fixed_id = 0x17;
private:
ShortXLUnicodeString string_;
std::wstring string_;
};
} // namespace XLS
......
......@@ -48,21 +48,22 @@ void SqRefU::load(CFRecord& record)
{
unsigned short cref;
record >> cref;
std::wstring sqref_str;
for (size_t i = 0; i < cref ; ++i)
{
Ref8U ref8;
record >> ref8;
sqref_str += std::wstring (ref8.toString(false).c_str()) + ((i == cref - 1) ? L"" : L" ");
strValue += std::wstring (ref8.toString(false).c_str()) + ((i == cref - 1) ? L"" : L" ");
}
sqref = sqref_str;
}
const CellRef SqRefU::getLocationFirstCell() const
{
std::vector<CellRangeRef> refs;
AUX::str2refs(sqref, refs);
AUX::str2refs(strValue, refs);
if(!refs.size())
{
return CellRef();
......
......@@ -49,10 +49,9 @@ public:
virtual void load(CFRecord& record);
const CellRef getLocationFirstCell() const;
std::wstring sqref;
std::wstring strValue;
};
} // namespace XLS
......
......@@ -107,7 +107,7 @@ int CONDFMT12::serialize(std::wostream & stream)
{
CondFmt12 * condFmt = dynamic_cast<CondFmt12*>(m_CondFmt12.get());
CP_XML_ATTR(L"sqref", condFmt->mainCF.sqref.sqref);
CP_XML_ATTR(L"sqref", condFmt->mainCF.sqref.strValue);
//condition_id
//condition_pos
for (int i = 0; i < m_arCF12.size(); i++)
......
......@@ -162,7 +162,6 @@ const bool CONDFMTS::loadContent(BinProcessor& proc)
return res;
}
int CONDFMTS::serialize(std::wostream & stream)
{
if (m_arCONDFMT.empty()) return 0;
......
......@@ -109,7 +109,7 @@ int CONDFMT::serialize(std::wostream & stream)
{
CondFmt * condFmt = dynamic_cast<CondFmt*>(m_CondFmt.get());
CP_XML_ATTR(L"sqref", condFmt->sqref.sqref);
CP_XML_ATTR(L"sqref", condFmt->sqref.strValue);
//condition_id
//condition_pos
for (int i = 0; i < m_arCF.size(); i++)
......
......@@ -50,6 +50,11 @@ public:
virtual const bool loadContent(BinProcessor& proc);
static const ElementType type = typeDVAL;
int serialize(std::wostream & stream);
BaseObjectPtr m_DVal;
std::vector<BaseObjectPtr> m_arDv;
};
} // namespace XLS
......
......@@ -61,10 +61,44 @@ const bool DVAL::loadContent(BinProcessor& proc)
{
return false;
}
proc.repeated<Dv>(0, 65534);
m_DVal = elements_.back(); elements_.pop_back();
int count = proc.repeated<Dv>(0, 65534);
while (count > 0)
{
m_arDv.insert(m_arDv.begin(), elements_.back());
elements_.pop_back();
count--;
}
return true;
}
int DVAL::serialize(std::wostream & stream)
{
if (!m_DVal) return 0;
if (m_arDv.empty()) return 0;
CP_XML_WRITER(stream)
{
CP_XML_NODE(L"dataValidations")
{
CP_XML_ATTR(L"count", m_arDv.size());
DVal * dval = dynamic_cast<DVal*>(m_DVal.get());
for (int i = 0 ; i < m_arDv.size(); i++)
{
if (!m_arDv[i]) continue;
m_arDv[i]->serialize(CP_XML_STREAM());
}
}
}
return 0;
}
} // namespace XLS
......@@ -715,8 +715,18 @@ int ChartSheetSubstream::serialize_plot_area (std::wostream & _stream)
{
PlotAreaFRAME = dynamic_cast<FRAME*> (axes->m_PlotArea_FRAME.get());
PlotAreaPos = dynamic_cast<Pos*> (parent0->m_Pos.get());
if (PlotAreaPos && !parent0->m_arCRT.empty())
{
CRT * crt = dynamic_cast<CRT*>(parent0->m_arCRT[0].get());
if ((crt) && ( crt->m_iChartType == CHART_TYPE_Radar ||
crt->m_iChartType == CHART_TYPE_RadarArea))//еще?
{
PlotAreaPos->m_iLayoutTarget = 2; //inner
}
}
if (PlotAreaFRAME && PlotAreaPos)
if (PlotAreaPos && PlotAreaFRAME)
{
PlotAreaPos->m_Frame = PlotAreaFRAME->m_Frame;
}
......@@ -750,7 +760,6 @@ int ChartSheetSubstream::serialize_plot_area (std::wostream & _stream)
if (PlotAreaPos && (sht_props) && (sht_props->fAlwaysAutoPlotArea != false))
{
PlotAreaPos->serialize(CP_XML_STREAM());
}
......
......@@ -354,7 +354,14 @@ const bool WorksheetSubstream::loadContent(BinProcessor& proc)
count--;
}
}break;
case rt_DVal: proc.optional<DVAL>(); break;
case rt_DVal:
{
if (proc.optional<DVAL>())
{
m_DVAL = elements_.back();
elements_.pop_back();
}
}break;
case rt_CodeName:
{
if (proc.optional<CodeName> ())
......
......@@ -70,6 +70,7 @@ public:
BaseObjectPtr m_CodeName;
BaseObjectPtr m_SheetExt;
BaseObjectPtr m_DxGCol;
BaseObjectPtr m_DVAL;
std::vector<BaseObjectPtr> m_arMergeCells;
std::vector<BaseObjectPtr> m_arWINDOW;
......
......@@ -428,6 +428,11 @@ void XlsConverter::convert(XLS::WorksheetSubstream* sheet)
sheet->m_CONDFMTS->serialize(xlsx_context->current_sheet().conditionalFormatting());
}
if (sheet->m_DVAL)
{
sheet->m_DVAL->serialize(xlsx_context->current_sheet().dataValidations());
}
convert((XLS::OBJECTS*)sheet->m_OBJECTS.get(), sheet);
if (sheet->m_arNote.size() > 0 && xls_global_info->Version < 0x0600)
......
......@@ -64,6 +64,7 @@ public:
std::wstringstream customViews_;
std::wstringstream conditionalFormatting_;
std::wstringstream picture_background_;
std::wstringstream dataValidations_;
rels rels_;
......@@ -164,7 +165,10 @@ std::wostream & xlsx_xml_worksheet::picture_background()
{
return impl_->picture_background_;
}
std::wostream & xlsx_xml_worksheet::dataValidations()
{
return impl_->dataValidations_;
}
//-----------------------------------------------------------------
rels & xlsx_xml_worksheet::sheet_rels()
{
......@@ -204,6 +208,8 @@ void xlsx_xml_worksheet::write_to(std::wostream & strm)
CP_XML_STREAM() << impl_->conditionalFormatting_.str();
CP_XML_STREAM() << impl_->dataValidations_.str();
CP_XML_STREAM() << impl_->hyperlinks_.str();
CP_XML_STREAM() << impl_->pageProperties_.str();
......
......@@ -69,6 +69,7 @@ public:
std::wostream & customViews();
std::wostream & conditionalFormatting();
std::wostream & picture_background();
std::wostream & dataValidations();
rels & sheet_rels();//hyperlink, background image, external, media ...
......
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