Commit eae048a8 authored by ElenaSubbotina's avatar ElenaSubbotina

OdfFormatReader - fix bugs conditionalFormatting, number styles, ...

parent a52c1860
......@@ -50,7 +50,7 @@ public:
std::wstring convert(std::wstring const & expr);
// $Лист1.$A$1 -> Лист1!$A$1
std::wstring convert_named_ref(std::wstring const & expr, bool withTableName = true);
std::wstring convert_named_ref(std::wstring const & expr, bool withTableName = true, std::wstring separator = L" ");
//a-la convert without check formula
std::wstring convert_named_expr(std::wstring const & expr, bool withTableName = true);
......
......@@ -300,7 +300,6 @@ namespace formulasconvert {
if (what[1].matched)
{
std::wstring inner = what[1].str();
boost::algorithm::replace_all(inner, L".", L"ТОСHKA");
boost::algorithm::replace_all(inner, L" ", L"PROBEL");
return inner;
}
......@@ -314,6 +313,7 @@ namespace formulasconvert {
if (what[1].matched)
{
std::wstring inner = what[1].str();
boost::algorithm::replace_all(inner, L".", L"ТОСHKA");
boost::algorithm::replace_all(inner, L"(", L"SCOBCAIN");
boost::algorithm::replace_all(inner, L")", L"SCOBCAOUT");
......@@ -327,6 +327,8 @@ namespace formulasconvert {
else if (what[2].matched)
{
std::wstring inner = what[2].str();
boost::algorithm::replace_all(inner, L".", L"ТОСHKA");
boost::algorithm::replace_all(inner, L"(", L"SCOBCAIN");
boost::algorithm::replace_all(inner, L")", L"SCOBCAOUT");
......@@ -407,47 +409,53 @@ namespace formulasconvert {
if (is_forbidden(expr))
return L"NULLFORMULA()";
boost::wregex complexRef(L"('(?!\\s\\'){0,1}.*?')");
std::wstring workstr = boost::regex_replace(
expr,
complexRef,
&replace_point_space,
boost::match_default | boost::format_all);
std::wstring workstr = expr;
//boost::wregex complexRef(L"('(?!\\s\\'){0,1}.*?')");// Better_Donut.ods- cell(c27)
//std::wstring workstr = boost::regex_replace(
// expr,
// complexRef,
// &replace_point_space,
// boost::match_default | boost::format_all);
check_formula(workstr);
bool isFormula = check_formula(workstr);
workstr = boost::regex_replace(
boost::regex_replace(
workstr,
boost::wregex(L"('.*?')|(\".*?\")"),
&convert_scobci, boost::match_default | boost::format_all);
//boost::algorithm::replace_all(workstr, L"'", L"APOSTROF");
replace_cells_range (workstr, true);
replace_semicolons (workstr);
replace_vertical (workstr);
if (isFormula)
{
boost::algorithm::replace_all(workstr, L"FDIST(", L"_xlfn.F.DIST(");
int res_find=0;
if ((res_find = workstr.find(L"CONCATINATE")) > 0)
{
//могут быть частично заданы диапазоны
//todooo
}
//todooo INDEX((A1:C6~A8:C11),2,2,2) - ???? - INDEX_emb.ods
}
//-----------------------------------------------------------
boost::algorithm::replace_all(workstr, L"PROBEL" , L" ");
boost::algorithm::replace_all(workstr, L"APOSTROF" , L"'");
boost::algorithm::replace_all(workstr, L"TOCHKA" , L".");
boost::algorithm::replace_all(workstr, L"ТОСHKA" , L".");
boost::algorithm::replace_all(workstr, L"SCOBCAIN", L"(");
boost::algorithm::replace_all(workstr, L"SCOBCAOUT", L")");
boost::algorithm::replace_all(workstr, L"SCOBCAIN" , L"(");
boost::algorithm::replace_all(workstr, L"SCOBCAOUT" , L")");
boost::algorithm::replace_all(workstr, L"KVADRATIN", L"[");
boost::algorithm::replace_all(workstr, L"KVADRATIN" , L"[");
boost::algorithm::replace_all(workstr, L"KVADRATOUT", L"]");
boost::algorithm::replace_all(workstr, L"PROBEL", L" ");
boost::algorithm::replace_all(workstr, L"KAVYCHKA", L"\"");
boost::algorithm::replace_all(workstr, L"PROBEL" , L" ");
boost::algorithm::replace_all(workstr, L"KAVYCHKA" , L"\"");
return workstr;
}
......@@ -535,7 +543,7 @@ namespace formulasconvert {
{
return impl_->convert_chart_distance(expr);
}
std::wstring odf2oox_converter::convert_named_ref(const std::wstring& expr, bool withTableName)
std::wstring odf2oox_converter::convert_named_ref(const std::wstring& expr, bool withTableName, std::wstring separator)
{
boost::wregex complexRef(L"('(?!\\s\\'){0,1}.*?')");// поиск того что в апострофах и замена там
......@@ -550,6 +558,11 @@ namespace formulasconvert {
impl_->replace_named_ref(workstr, withTableName);
if (separator != L" ")
{
boost::algorithm::replace_all(workstr, L" " , separator);
}
boost::algorithm::replace_all(workstr, L"PROBEL" , L" ");
boost::algorithm::replace_all(workstr, L"APOSTROF" , L"'");
boost::algorithm::replace_all(workstr, L"TOCHKA" , L".");
......
......@@ -82,6 +82,8 @@ namespace oox {
//expr
_CP_OPT(std::wstring) formula;
_CP_OPT(std::wstring) formula_type;
_CP_OPT(std::wstring) text;
_CP_OPT(std::wstring) formula2;
//color scale icon set data_bar
std::vector<_cfvo> cfvo;
//color scale data_bar(1 element)
......@@ -135,8 +137,7 @@ public:
if (c.rules[j].percent) CP_XML_ATTR(L"percent", *c.rules[j].percent);
if (c.rules[j].operator_) CP_XML_ATTR(L"operator", *c.rules[j].operator_);
if (c.rules[j].stopIfTrue) CP_XML_ATTR(L"stopIfTrue", *c.rules[j].stopIfTrue);
//CP_XML_ATTR(L"text" , L"");
if (c.rules[j].text) CP_XML_ATTR(L"text", *c.rules[j].text);
//CP_XML_ATTR(L"rank" , 0);
//CP_XML_ATTR(L"bottom" , 0);
//CP_XML_ATTR(L"equalAverage" , 0);
......@@ -144,13 +145,20 @@ public:
if (c.rules[j].type == 1)
{
CP_XML_ATTR(L"type", *c.rules[j].formula_type);
if (c.rules[j].formula)
if ((c.rules[j].formula) && (!c.rules[j].formula->empty()))
{
CP_XML_NODE(L"formula")
{
CP_XML_CONTENT(*c.rules[j].formula);
}
}
if ((c.rules[j].formula2) && (!c.rules[j].formula2->empty()))
{
CP_XML_NODE(L"formula")
{
CP_XML_CONTENT(*c.rules[j].formula2);
}
}
}
else if (c.rules[j].type == 2)
{
......@@ -233,7 +241,7 @@ void xlsx_conditionalFormatting_context::add(std::wstring ref)
formulasconvert::odf2oox_converter converter;
impl_->conditionalFormattings_.push_back(conditionalFormatting());
impl_->conditionalFormattings_.back().ref = converter.convert_named_ref(ref, false);
impl_->conditionalFormattings_.back().ref = converter.convert_named_ref(ref, false, L";");
}
void xlsx_conditionalFormatting_context::add_rule(int type)
......@@ -244,8 +252,10 @@ void xlsx_conditionalFormatting_context::add_rule(int type)
}
void xlsx_conditionalFormatting_context::set_formula(std::wstring f)
{
formulasconvert::odf2oox_converter converter;
int pos = -1;
std::wstring val;
if ( 0 <= (pos = f.find(L"formula-is(")))
{
impl_->conditionalFormattings_.back().rules.back().formula_type = L"expression";
......@@ -272,6 +282,7 @@ void xlsx_conditionalFormatting_context::set_formula(std::wstring f)
}
else if (0 <= (pos = f.find(L"top")))
{
impl_->conditionalFormattings_.back().rules.back().formula_type = L"top10";
}
else if (0 <= (pos = f.find(L"!=")))
{
......@@ -303,13 +314,29 @@ void xlsx_conditionalFormatting_context::set_formula(std::wstring f)
impl_->conditionalFormattings_.back().rules.back().operator_ = L"greaterThan";
val = f.substr(1);
}
else if (0 <= (pos = f.find(L"contains-text")))
{
impl_->conditionalFormattings_.back().rules.back().formula_type = L"containsText";
impl_->conditionalFormattings_.back().rules.back().text = f.substr(15, f.length() - 17);
val.clear();
}
else if (0 <= (pos = f.find(L"between")))
{
impl_->conditionalFormattings_.back().rules.back().operator_ = L"between";
val = f.substr(8, f.length() - 9);
if (0 <= (pos = val.find(L",")))
{
impl_->conditionalFormattings_.back().rules.back().formula2 = converter.convert_named_expr(val.substr(pos + 1));
val = val.substr(0, pos);
}
}
else
{
val = f;
}
}
formulasconvert::odf2oox_converter converter;
impl_->conditionalFormattings_.back().rules.back().formula = converter.convert_named_expr(val);
}
void xlsx_conditionalFormatting_context::set_dataBar(_CP_OPT(int) min, _CP_OPT(int) max)
......
......@@ -30,6 +30,7 @@
*
*/
#include <vector>
#include <cpdoccore/xml/utils.h>
#include "xlsx_numFmts.h"
......@@ -77,7 +78,7 @@ void xlsx_num_fmts::serialize(std::wostream & _Wostream) const
_Wostream << L"<numFmts count=\"" << impl_->formats_.size() << L"\">";
for (size_t i = 0; i < impl_->formats_.size(); ++i)
{
_Wostream << L"<numFmt formatCode=\"" << impl_->formats_[i] <<
_Wostream << L"<numFmt formatCode=\"" << xml::utils::replace_text_to_xml(impl_->formats_[i]) <<
L"\" numFmtId=\"" << impl_->transform_id(i) << "\" />";
}
......
......@@ -188,7 +188,12 @@ size_t xlsx_style_manager::Impl::xfId(const odf_reader::text_format_properties_c
void xlsx_style_manager::Impl::serialize(std::wostream & _Wostream)
{
_Wostream << L"<styleSheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\">";
_Wostream << L"<styleSheet";
_Wostream << L" xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\"";
_Wostream << L" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\"";
_Wostream << L" mc:Ignorable=\"x14ac\"";
_Wostream << L" xmlns:x14ac=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac\"";
_Wostream << L">";
numFmts_.serialize (_Wostream);
fonts_.serialize (_Wostream);
......@@ -201,8 +206,6 @@ void xlsx_style_manager::Impl::serialize(std::wostream & _Wostream)
cellStyles_.serialize(_Wostream);
dxfs_.serialize(_Wostream);
_Wostream << L"</styleSheet>";
}
......@@ -253,7 +256,7 @@ size_t xlsx_style_manager::xfId(const odf_reader::text_format_properties_content
const std::wstring &num_format, bool default_set)
{
bool is_visible;
return impl_->xfId(textProp, parProp, cellProp, xlxsCellFormat, num_format,default_set, is_visible);
return impl_->xfId(textProp, parProp, cellProp, xlxsCellFormat, num_format, default_set, is_visible);
}
size_t xlsx_style_manager::xfId(const odf_reader::text_format_properties_content * textProp,
......
......@@ -113,7 +113,7 @@ void xlsx_conversion_context::start_document()
std::vector<const odf_reader::style_instance *> instances;
instances.push_back(odfContext.styleContainer().style_default_by_type(odf_types::style_family::TableCell));
instances.push_back(odfContext.styleContainer().style_by_name(L"Default",odf_types::style_family::TableCell,false));
instances.push_back(odfContext.styleContainer().style_by_name(L"Default", odf_types::style_family::TableCell, false));
odf_reader::text_format_properties_content textFormatProperties = calc_text_properties_content(instances);
odf_reader::paragraph_format_properties parFormatProperties = calc_paragraph_properties_content(instances);
......@@ -124,7 +124,7 @@ void xlsx_conversion_context::start_document()
cellFormat.set_cell_type(XlsxCellType::s);
cellFormat.set_num_format(oox::odf_string_to_build_in(0));
default_style_ = get_style_manager().xfId(&textFormatProperties, &parFormatProperties, &cellFormatProperties, &cellFormat, L"",true);
default_style_ = get_style_manager().xfId(&textFormatProperties, &parFormatProperties, &cellFormatProperties, &cellFormat, L"", true);
}
......
......@@ -227,10 +227,13 @@ void calcext_formatting_entry::xlsx_convert(oox::xlsx_conversion_context & Conte
// calcext_color_scale_entry
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * calcext_color_scale_entry::ns = L"calcext";
const wchar_t * calcext_color_scale_entry::name = L"color_scale_entry";
const wchar_t * calcext_color_scale_entry::name = L"color-scale-entry";
void calcext_color_scale_entry::add_attributes( const xml::attributes_wc_ptr & Attributes )
{
CP_APPLY_ATTR(L"calcext:value", calcext_value_);
CP_APPLY_ATTR(L"calcext:type", calcext_type_);
CP_APPLY_ATTR(L"calcext:color", calcext_color_);
}
void calcext_color_scale_entry::add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name)
{
......
......@@ -414,12 +414,23 @@ void number_number::oox_convert(oox::num_format_context & Context)
void number_text::oox_convert(oox::num_format_context & Context)
{
std::wostream & strm = Context.output();
std::wstringstream strm;
BOOST_FOREACH(const office_element_ptr & elm, text_)
{
elm->text_to_stream(strm);
}
std::wstring text_ = strm.str();
if (text_ == L"%")
{
}
else
{
text_ = L"\"" + text_ + L"\""; //Book 70.ods Design of Pile Cap.ods
}
Context.output() << text_;
}
......
......@@ -753,7 +753,7 @@ void table_table_cell::xlsx_convert(oox::xlsx_conversion_context & Context)
is_style_visible = (styleName.length() > 0 || defaultColumnCellStyle) ? true : false;
xfId_last_set= Context.get_style_manager().xfId(&textFormatProperties, &parFormatProperties, &cellFormatProperties, &cellFormat, num_format,false, is_style_visible);
xfId_last_set= Context.get_style_manager().xfId(&textFormatProperties, &parFormatProperties, &cellFormatProperties, &cellFormat, num_format, false, is_style_visible);
if ( table_table_cell_content_.elements_.size() > 0 ||
!formula.empty() ||
......
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