Commit 326c8f5d authored by ElenaSubbotina's avatar ElenaSubbotina Committed by Alexander Trofimov

OdfFormatReader - поправлена конвертация формул в Vehicle log book.ods

parent 15cf0894
...@@ -7,9 +7,9 @@ ...@@ -7,9 +7,9 @@
namespace cpdoccore { namespace cpdoccore {
namespace formulasconvert { namespace formulasconvert {
class odf2oox_converter::Impl class odf2oox_converter::Impl
{ {
public: public:
std::wstring convert(const std::wstring& expr); std::wstring convert(const std::wstring& expr);
std::wstring convert_chart_distance(const std::wstring& expr); std::wstring convert_chart_distance(const std::wstring& expr);
void replace_cells_range(std::wstring& expr); void replace_cells_range(std::wstring& expr);
...@@ -21,9 +21,9 @@ public: ...@@ -21,9 +21,9 @@ public:
void replace_named_ref(std::wstring & expr); void replace_named_ref(std::wstring & expr);
bool find_first_ref(std::wstring const & expr, std::wstring & table, std::wstring & ref); bool find_first_ref(std::wstring const & expr, std::wstring & table, std::wstring & ref);
bool find_first_last_ref(std::wstring const & expr, std::wstring & table, std::wstring & ref_first,std::wstring & ref_last); bool find_first_last_ref(std::wstring const & expr, std::wstring & table, std::wstring & ref_first,std::wstring & ref_last);
}; };
bool odf2oox_converter::Impl::find_first_last_ref(std::wstring const & expr, std::wstring & table,std::wstring & ref_first,std::wstring & ref_last) bool odf2oox_converter::Impl::find_first_last_ref(std::wstring const & expr, std::wstring & table,std::wstring & ref_first,std::wstring & ref_last)
{ {
std::vector< std::wstring > splitted; std::vector< std::wstring > splitted;
boost::algorithm::split(splitted, expr, boost::algorithm::is_any_of(L".:"), boost::algorithm::token_compress_on); boost::algorithm::split(splitted, expr, boost::algorithm::is_any_of(L".:"), boost::algorithm::token_compress_on);
...@@ -43,10 +43,10 @@ bool odf2oox_converter::Impl::find_first_last_ref(std::wstring const & expr, std ...@@ -43,10 +43,10 @@ bool odf2oox_converter::Impl::find_first_last_ref(std::wstring const & expr, std
return true; return true;
} }
return false; return false;
} }
bool odf2oox_converter::Impl::find_first_ref(std::wstring const & expr, std::wstring & table, std::wstring & ref) bool odf2oox_converter::Impl::find_first_ref(std::wstring const & expr, std::wstring & table, std::wstring & ref)
{ {
boost::wregex re(L"\\[(?:\\$)?([^\\.]+?){0,1}\\.([a-zA-Z\\$]+\\d+)(?::\\.([a-zA-Z]+\\d+)){0,1}\\]"); boost::wregex re(L"\\[(?:\\$)?([^\\.]+?){0,1}\\.([a-zA-Z\\$]+\\d+)(?::\\.([a-zA-Z]+\\d+)){0,1}\\]");
boost::wsmatch result; boost::wsmatch result;
bool b = boost::regex_search(expr, result, re); bool b = boost::regex_search(expr, result, re);
...@@ -67,14 +67,36 @@ bool odf2oox_converter::Impl::find_first_ref(std::wstring const & expr, std::wst ...@@ -67,14 +67,36 @@ bool odf2oox_converter::Impl::find_first_ref(std::wstring const & expr, std::wst
return true; return true;
} }
return false; return false;
} }
namespace std::wstring replace_cell_range_formater(boost::wsmatch const & what)
{ {
const size_t sz = what.size();
if (sz == 4 && !what[1].matched)
{
const std::wstring c1 = what[2].str();
const std::wstring c2 = what[3].str();
const std::wstring s = c1 + (c2.empty() ? L"" : (L":" + c2) );
return s;
}
else if (sz == 4 && what[1].matched)
{
std::wstring sheet1 = what[1].str();
boost::algorithm::replace_all(sheet1, L"$", L"");
std::wstring replace_cell_range_formater(boost::wsmatch const & what) const std::wstring c1 = what[2].str();
{ std::wstring c2 = what[3].str();
if (c2.empty()) c2 = what[4].str();
const std::wstring s = sheet1 + L"!" + c1 + (c2.empty() ? L"" : (L":" + c2) );
return s;
}
return L"";
}
std::wstring replace_named_ref_formater(boost::wsmatch const & what)
{
const size_t sz = what.size(); const size_t sz = what.size();
if (sz == 4 && !what[1].matched) if (sz == 4 && !what[1].matched)
{ {
const std::wstring c1 = what[2].str(); const std::wstring c1 = what[2].str();
...@@ -93,9 +115,21 @@ std::wstring replace_cell_range_formater(boost::wsmatch const & what) ...@@ -93,9 +115,21 @@ std::wstring replace_cell_range_formater(boost::wsmatch const & what)
return s; return s;
} }
return L""; return L"";
} }
std::wstring replace_named_ref_formater1(boost::wsmatch const & what)
{
boost::wregex complexRef(L"\\$([^\\.]+?){0,1}\\.(\\$[a-zA-Z]+\\$\\d+)(?::\\.(\\$[a-zA-Z]+\\$\\d+)){0,1}");
} std::wstring expr = what[1].str();
const std::wstring res = boost::regex_replace(
expr,
complexRef,
&replace_named_ref_formater,
boost::match_default | boost::format_all);
expr = res;
return expr;
}
// çàìåíÿåì ôîðìàò àäðåñàöèè ÿ÷ååê // çàìåíÿåì ôîðìàò àäðåñàöèè ÿ÷ååê
...@@ -107,7 +141,8 @@ std::wstring replace_cell_range_formater(boost::wsmatch const & what) ...@@ -107,7 +141,8 @@ std::wstring replace_cell_range_formater(boost::wsmatch const & what)
void odf2oox_converter::Impl::replace_cells_range(std::wstring& expr) void odf2oox_converter::Impl::replace_cells_range(std::wstring& expr)
{ {
//boost::wregex simpleRef(L"\\[\\.([a-zA-Z]+\\d+)(?::\\.([a-zA-Z]+\\d+)){0,1}\\]"); //boost::wregex simpleRef(L"\\[\\.([a-zA-Z]+\\d+)(?::\\.([a-zA-Z]+\\d+)){0,1}\\]");
boost::wregex complexRef(L"\\[(?:\\$)?([^\\.]+?){0,1}\\.([a-zA-Z\\$]+\\d+)(?::\\.([a-zA-Z]+\\d+)){0,1}\\]"); //boost::wregex complexRef(L"\\[(?:\\$)?([^\\.]+?){0,1}\\.([a-zA-Z\\$]+\\d+)(?::\\.([a-zA-Z]+\\d+)){0,1}\\]");
boost::wregex complexRef(L"\\[(.*?)\\]");
/* /*
[ $ Sheet2 . A1 : . B5 ] [ $ Sheet2 . A1 : . B5 ]
...@@ -116,38 +151,13 @@ void odf2oox_converter::Impl::replace_cells_range(std::wstring& expr) ...@@ -116,38 +151,13 @@ void odf2oox_converter::Impl::replace_cells_range(std::wstring& expr)
const std::wstring res = boost::regex_replace( const std::wstring res = boost::regex_replace(
expr, expr,
complexRef, complexRef,
&replace_cell_range_formater, &replace_named_ref_formater1,
boost::match_default | boost::format_all); boost::match_default | boost::format_all);
expr = res; expr = res;
} }
namespace {
std::wstring replace_named_ref_formater(boost::wsmatch const & what)
{
const size_t sz = what.size();
if (sz == 4 && !what[1].matched)
{
const std::wstring c1 = what[2].str();
const std::wstring c2 = what[3].str();
const std::wstring s = c1 + (c2.empty() ? L"" : (L":" + c2) );
return s;
}
else if (sz == 4 && what[1].matched)
{
std::wstring sheet1 = what[1].str();
boost::algorithm::replace_all(sheet1, L"$", L"");
const std::wstring c1 = what[2].str();
const std::wstring c2 = what[3].str();
const std::wstring s = sheet1 + L"!" + c1 + (c2.empty() ? L"" : (L":" + c2) );
return s;
}
return L"";
}
}
void odf2oox_converter::Impl::replace_named_ref(std::wstring & expr) void odf2oox_converter::Impl::replace_named_ref(std::wstring & expr)
{ {
boost::wregex complexRef(L"\\$([^\\.]+?){0,1}\\.(\\$[a-zA-Z]+\\$\\d+)(?::\\.(\\$[a-zA-Z]+\\$\\d+)){0,1}"); boost::wregex complexRef(L"\\$([^\\.]+?){0,1}\\.(\\$[a-zA-Z]+\\$\\d+)(?::\\.(\\$[a-zA-Z]+\\$\\d+)){0,1}");
...@@ -290,7 +300,12 @@ std::wstring odf2oox_converter::Impl::convert(const std::wstring& expr) ...@@ -290,7 +300,12 @@ std::wstring odf2oox_converter::Impl::convert(const std::wstring& expr)
if (is_forbidden(expr)) if (is_forbidden(expr))
return L"NULLFORMULA()"; return L"NULLFORMULA()";
std::wstring workstr = expr; std::wstring workstr = expr;
boost::algorithm::replace_all(workstr, L" ", L"PROBEL");
boost::algorithm::replace_all(workstr, L"'", L"APOSTROF");
check_formula(workstr); check_formula(workstr);
replace_cells_range(workstr); replace_cells_range(workstr);
replace_semicolons(workstr); replace_semicolons(workstr);
...@@ -303,6 +318,8 @@ std::wstring odf2oox_converter::Impl::convert(const std::wstring& expr) ...@@ -303,6 +318,8 @@ std::wstring odf2oox_converter::Impl::convert(const std::wstring& expr)
//todooo //todooo
} }
boost::algorithm::replace_all(workstr, L"PROBEL", L" ");
boost::algorithm::replace_all(workstr, L"APOSTROF", L"'");
return workstr; return workstr;
} }
......
...@@ -285,6 +285,8 @@ void oox_doughnut_chart::set_properties(std::vector<odf_reader::_property> g) ...@@ -285,6 +285,8 @@ void oox_doughnut_chart::set_properties(std::vector<odf_reader::_property> g)
} }
void oox_doughnut_chart::oox_serialize(std::wostream & _Wostream) void oox_doughnut_chart::oox_serialize(std::wostream & _Wostream)
{ {
grouping_.clear();
CP_XML_WRITER(_Wostream) CP_XML_WRITER(_Wostream)
{ {
CP_XML_NODE(L"c:doughnutChart") CP_XML_NODE(L"c:doughnutChart")
......
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