Commit bf0b5a4b authored by ElenaSubbotina's avatar ElenaSubbotina

OdfFormat - fix formulas

parent 4f92ab53
......@@ -242,6 +242,10 @@ namespace formulasconvert {
if (boost::regex_search(expr, res, boost::wregex(L"(?:[\\w]+:)?=(.+)"), boost::match_default))
{
expr = res[1].str();
while (expr.find(L"=") == 0)
{
expr.erase(expr.begin(), expr.begin() + 1);
}
return true;
}
else
......@@ -305,6 +309,37 @@ namespace formulasconvert {
else if (what[3].matched)
return what[3].str();
}
std::wstring convert_scobci(boost::wsmatch const & what)
{
if (what[1].matched)
{
std::wstring inner = what[1].str();
boost::algorithm::replace_all(inner, L"(", L"SCOBCAIN");
boost::algorithm::replace_all(inner, L")", L"SCOBCAOUT");
boost::algorithm::replace_all(inner, L"[", L"KVADRATIN");
boost::algorithm::replace_all(inner, L"]", L"KVADRATOUT");
boost::algorithm::replace_all(inner, L" ", L"PROBEL");
boost::algorithm::replace_all(inner, L"'", L"APOSTROF");
return inner;
}
else if (what[2].matched)
{
std::wstring inner = what[2].str();
boost::algorithm::replace_all(inner, L"(", L"SCOBCAIN");
boost::algorithm::replace_all(inner, L")", L"SCOBCAOUT");
boost::algorithm::replace_all(inner, L"[", L"KVADRATIN");
boost::algorithm::replace_all(inner, L"]", L"KVADRATOUT");
boost::algorithm::replace_all(inner, L" ", L"PROBEL");
boost::algorithm::replace_all(inner, L"\"", L"KAVYCHKA");
return inner;
}
else if (what[3].matched)
return what[3].str();
}
std::wstring replace_space_formater(boost::wsmatch const & what)
{
if (what[1].matched)
......@@ -380,12 +415,19 @@ namespace formulasconvert {
&replace_point_space,
boost::match_default | boost::format_all);
boost::algorithm::replace_all(workstr, L"'", L"APOSTROF");
check_formula(workstr);
replace_cells_range(workstr, true);
replace_semicolons(workstr);
replace_vertical(workstr);
workstr = 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);
int res_find=0;
if ((res_find = workstr.find(L"CONCATINATE")) > 0)
......@@ -397,6 +439,15 @@ namespace formulasconvert {
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"SCOBCAIN", L"(");
boost::algorithm::replace_all(workstr, L"SCOBCAOUT", 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"\"");
return workstr;
}
......@@ -495,6 +546,7 @@ namespace formulasconvert {
boost::match_default | boost::format_all);
boost::algorithm::replace_all(workstr, L"'", L"APOSTROF");
//boost::algorithm::replace_all(workstr, L"", L"APOSTROF");
impl_->replace_named_ref(workstr, withTableName);
......
......@@ -468,7 +468,10 @@ std::wstring oox2odf_converter::Impl::convert_scobci(boost::wsmatch const & what
boost::algorithm::replace_all(inner, L"(", L"SCOBCAIN");
boost::algorithm::replace_all(inner, L")", L"SCOBCAOUT");
boost::algorithm::replace_all(inner, L" ", L"PROBEL");
boost::algorithm::replace_all(inner, L"[", L"KVADRATIN");
boost::algorithm::replace_all(inner, L"]", L"KVADRATOUT");
boost::algorithm::replace_all(inner, L" ", L"PROBEL");
boost::algorithm::replace_all(inner, L"'", L"APOSTROF");
return inner;
}
......@@ -478,7 +481,10 @@ std::wstring oox2odf_converter::Impl::convert_scobci(boost::wsmatch const & what
boost::algorithm::replace_all(inner, L"(", L"SCOBCAIN");
boost::algorithm::replace_all(inner, L")", L"SCOBCAOUT");
boost::algorithm::replace_all(inner, L" ", L"PROBEL");
boost::algorithm::replace_all(inner, L"[", L"KVADRATIN");
boost::algorithm::replace_all(inner, L"]", L"KVADRATOUT");
boost::algorithm::replace_all(inner, L" ", L"PROBEL");
boost::algorithm::replace_all(inner, L"\"", L"KAVYCHKA");
return inner;
}
......@@ -567,7 +573,10 @@ std::wstring oox2odf_converter::Impl::convert_formula(const std::wstring & expr)
boost::algorithm::replace_all(res, L"SCOBCAIN", L"(");
boost::algorithm::replace_all(res, L"SCOBCAOUT", L")");
boost::algorithm::replace_all(res, L"PROBEL", L" ");
boost::algorithm::replace_all(res, L"KVADRATIN", L"[");
boost::algorithm::replace_all(res, L"KVADRATOUT", L"]");
boost::algorithm::replace_all(res, L"PROBEL", L" ");
boost::algorithm::replace_all(res, L"APOSTROF", L"'");
......
......@@ -64,6 +64,8 @@ void xlsx_data_range::serialize_sort (std::wostream & _Wostream)
{
if (bySort.empty()) return;
if (byRow) return;
CP_XML_WRITER(_Wostream)
{
CP_XML_NODE(L"sortState")
......
......@@ -133,7 +133,7 @@ public:
virtual void visit(const table_table_column& val)
{
const unsigned int columnsRepeated = val.table_table_column_attlist_.table_number_columns_repeated_;
const std::wstring defaultCellStyleName = val.table_table_column_attlist_.table_default_cell_style_name_.get_value_or(style_ref(L"")).style_name();
const std::wstring defaultCellStyleName = val.table_table_column_attlist_.table_default_cell_style_name_.get_value_or(L"");
visit_column(columnsRepeated, defaultCellStyleName);
}
virtual void visit(const table_calculation_settings & val)
......@@ -202,9 +202,7 @@ public:
virtual void visit(const table_table_row& val)
{
unsigned int repeated = val.table_table_row_attlist_.table_number_rows_repeated_;
std::wstring defaultCellStyle = val.
table_table_row_attlist_.
table_default_cell_style_name_.get_value_or(style_ref(L"")).style_name();
std::wstring defaultCellStyle = val.table_table_row_attlist_.table_default_cell_style_name_.get_value_or(L"");
if (visit_rows(repeated, defaultCellStyle))
{
......
......@@ -583,9 +583,24 @@ void table_rows_and_groups::add_child_element( xml::sax * Reader, const std::wst
}
else if (L"table" == Ns && (L"table-rows" == Name || L"table-row" == Name || L"table-header-rows" == Name) )
{
_CP_PTR(table_rows_no_group) elm = table_rows_no_group::create();
elm->add_child_element(Reader, Ns, Name, Context);
content_.push_back(elm);
bool add_new_no_group = false;
if (content_.empty()) add_new_no_group = true;
else
{
if (content_.back()->get_type() != typeTableTableRowNoGroup)
add_new_no_group = true;
}
if (add_new_no_group)
{
_CP_PTR(table_rows_no_group) elm = table_rows_no_group::create();
elm->add_child_element(Reader, Ns, Name, Context);
content_.push_back(elm);
}
else
{
table_rows_no_group* rows_no_group = static_cast<table_rows_no_group*>(content_.back().get());
rows_no_group->add_child_element(Reader, Ns, Name, Context);
}
}
else
not_applicable_element(L"table-rows-and-groups", Reader, Ns, Name);
......
......@@ -44,8 +44,8 @@
#include "datatypes/tablemode.h"
#include "datatypes/common_attlists.h"
#include "datatypes/style_ref.h"
#include "datatypes/tablevisibility.h"
namespace cpdoccore {
namespace odf_reader {
......@@ -56,20 +56,20 @@ public:
void add_attributes( const xml::attributes_wc_ptr & Attributes );
public:
_CP_OPT(bool) table_is_sub_table_;
_CP_OPT(std::wstring) table_name_;
_CP_OPT(odf_types::style_ref) table_style_name_;
_CP_OPT(std::wstring) table_template_name_;
_CP_OPT(bool) table_is_sub_table_;
_CP_OPT(std::wstring) table_name_;
_CP_OPT(std::wstring) table_style_name_;
_CP_OPT(std::wstring) table_template_name_;
bool table_protected_; // default false
_CP_OPT(std::wstring) table_protection_key_;
bool table_print_; // default true
_CP_OPT(std::wstring) table_print_ranges_;
bool table_protected_; // default false
_CP_OPT(std::wstring) table_protection_key_;
bool table_print_; // default true
_CP_OPT(std::wstring) table_print_ranges_;
bool table_use_first_row_styles_; // default false;
bool table_use_banding_rows_styles_; //defualt false;
bool table_use_first_column_styles_; //defualt false;
bool table_use_banding_columns_styles_; //defualt false;
bool table_use_first_row_styles_; // default false;
bool table_use_banding_rows_styles_; //defualt false;
bool table_use_first_column_styles_; //defualt false;
bool table_use_banding_columns_styles_; //defualt false;
friend class table_table;
};
......@@ -82,9 +82,9 @@ public:
public:
unsigned int table_number_rows_repeated_; // default 1
_CP_OPT(odf_types::style_ref) table_style_name_;
_CP_OPT(odf_types::style_ref) table_default_cell_style_name_;
odf_types::table_visibility table_visibility_; // default Visible
_CP_OPT(std::wstring) table_style_name_;
_CP_OPT(std::wstring) table_default_cell_style_name_;
odf_types::table_visibility table_visibility_; // default Visible
};
......@@ -95,10 +95,10 @@ public:
void add_attributes( const xml::attributes_wc_ptr & Attributes );
public:
unsigned int table_number_columns_repeated_; // default 1
_CP_OPT(odf_types::style_ref) table_style_name_;
_CP_OPT(std::wstring) table_content_validation_name_;
_CP_OPT(std::wstring) table_formula_;
unsigned int table_number_columns_repeated_; // default 1
_CP_OPT(std::wstring) table_style_name_;
_CP_OPT(std::wstring) table_content_validation_name_;
_CP_OPT(std::wstring) table_formula_;
odf_types::common_value_and_type_attlist common_value_and_type_attlist_;
......@@ -247,10 +247,10 @@ public:
void add_attributes( const xml::attributes_wc_ptr & Attributes );
public:
unsigned int table_number_columns_repeated_; // default 1
_CP_OPT(odf_types::style_ref) table_style_name_;
odf_types::table_visibility table_visibility_; // default Visible
_CP_OPT(odf_types::style_ref) table_default_cell_style_name_;
unsigned int table_number_columns_repeated_; // default 1
_CP_OPT(std::wstring) table_style_name_;
odf_types::table_visibility table_visibility_; // default Visible
_CP_OPT(std::wstring) table_default_cell_style_name_;
};
......
......@@ -67,8 +67,8 @@ void table_table_row::docx_convert(oox::docx_conversion_context & Context)
{
std::wostream & _Wostream = Context.output_stream();
const std::wstring styleName = table_table_row_attlist_.table_style_name_.get_value_or( style_ref(L"") ).style_name();
const std::wstring defaultCellStyle = table_table_row_attlist_.table_default_cell_style_name_.get_value_or( style_ref(L"") ).style_name();
const std::wstring styleName = table_table_row_attlist_.table_style_name_.get_value_or(L"");
const std::wstring defaultCellStyle = table_table_row_attlist_.table_default_cell_style_name_.get_value_or(L"");
for (unsigned int i = 0; i < table_table_row_attlist_.table_number_rows_repeated_; ++i)
{
......@@ -148,9 +148,7 @@ void table_table::docx_convert(oox::docx_conversion_context & Context)
bool sub_table = table_table_attlist_.table_is_sub_table_.get_value_or(false);
//todooo придумать как сделать внешние границы sub-таблицы границами внешней ячейки (чтоб слияние произошло)
std::wstring tableStyleName = L"";
if (table_table_attlist_.table_style_name_)
tableStyleName = table_table_attlist_.table_style_name_->style_name() ;
std::wstring tableStyleName = table_table_attlist_.table_style_name_.get_value_or(L"");
_Wostream << L"<w:tbl>";
......@@ -249,14 +247,14 @@ void table_table_column::docx_convert(oox::docx_conversion_context & Context)
{
std::wostream & _Wostream = Context.output_stream();
const unsigned int columnsRepeated = table_table_column_attlist_.table_number_columns_repeated_;
const std::wstring defaultCellStyle = table_table_column_attlist_.table_default_cell_style_name_.get_value_or(style_ref(L"")).style_name();
const std::wstring defaultCellStyle = table_table_column_attlist_.table_default_cell_style_name_.get_value_or(L"");
Context.get_table_context().start_column(columnsRepeated, defaultCellStyle);
for (unsigned int i = 0; i < columnsRepeated; ++i)
{
if (table_table_column_attlist_.table_style_name_)
{
const std::wstring colStyleName = table_table_column_attlist_.table_style_name_->style_name();
const std::wstring colStyleName = table_table_column_attlist_.table_style_name_.get();
if (style_instance * inst =
Context.root()->odf_context().styleContainer().style_by_name( colStyleName , style_family::TableColumn,Context.process_headers_footers_ ))
{
......@@ -281,8 +279,7 @@ void table_table_cell::docx_convert(oox::docx_conversion_context & Context)
_Wostream << L"<w:tc>";
_Wostream << L"<w:tcPr>";
const std::wstring styleName = table_table_cell_attlist_.table_style_name_ ?
table_table_cell_attlist_.table_style_name_->style_name() : L"";
const std::wstring styleName = table_table_cell_attlist_.table_style_name_.get_value_or(L"");
//_Wostream << L"<w:tcW w:w=\"0\" w:type=\"auto\" />";
......
......@@ -70,8 +70,8 @@ void table_table_row::pptx_convert(oox::pptx_conversion_context & Context)
{
std::wostream & _Wostream = Context.get_table_context().tableData();
const std::wstring styleName = table_table_row_attlist_.table_style_name_.get_value_or( style_ref(L"") ).style_name();
const std::wstring defaultCellStyle = table_table_row_attlist_.table_default_cell_style_name_.get_value_or( style_ref(L"") ).style_name();
const std::wstring styleName = table_table_row_attlist_.table_style_name_.get_value_or(L"");
const std::wstring defaultCellStyle = table_table_row_attlist_.table_default_cell_style_name_.get_value_or(L"");
for (unsigned int i = 0; i < table_table_row_attlist_.table_number_rows_repeated_; ++i)
{
......@@ -160,9 +160,7 @@ void table_table::pptx_convert(oox::pptx_conversion_context & Context)
Context.get_slide_context().start_table();
//////////////////////////////////////////////////////////////////
std::wstring tableStyleName = L"";
if (table_table_attlist_.table_style_name_)
tableStyleName = table_table_attlist_.table_style_name_->style_name() ;
std::wstring tableStyleName = table_table_attlist_.table_style_name_.get_value_or(L"");
Context.get_table_context().start_table(tableStyleName);
......@@ -295,7 +293,7 @@ void table_table_column::pptx_convert(oox::pptx_conversion_context & Context)
std::wostream & _Wostream = Context.get_table_context().tableData();
const unsigned int columnsRepeated = table_table_column_attlist_.table_number_columns_repeated_;
const std::wstring defaultCellStyle = table_table_column_attlist_.table_default_cell_style_name_.get_value_or(style_ref(L"")).style_name();
const std::wstring defaultCellStyle = table_table_column_attlist_.table_default_cell_style_name_.get_value_or(L"");
Context.get_table_context().start_column(columnsRepeated, defaultCellStyle);
......@@ -303,7 +301,7 @@ void table_table_column::pptx_convert(oox::pptx_conversion_context & Context)
{
if (table_table_column_attlist_.table_style_name_)
{
const std::wstring colStyleName = table_table_column_attlist_.table_style_name_->style_name();
const std::wstring colStyleName = table_table_column_attlist_.table_style_name_.get();
style_instance * inst = Context.root()->odf_context().styleContainer().style_by_name( colStyleName , style_family::TableColumn,false );
if ((inst) && (inst->content()))
......@@ -353,7 +351,7 @@ void table_table_cell::pptx_convert(oox::pptx_conversion_context & Context)
style_inst = Context.root()->odf_context().styleContainer().style_by_name(style_name, style_family::TableCell,false);
if (style_inst) style_instances.push_back(style_inst);
}
style_name = table_table_cell_attlist_.table_style_name_ ? table_table_cell_attlist_.table_style_name_->style_name() : L"";
style_name = table_table_cell_attlist_.table_style_name_.get_value_or(L"");
if (!style_name.empty())
{
style_inst = Context.root()->odf_context().styleContainer().style_by_name(style_name, style_family::TableCell,false);
......
......@@ -80,8 +80,8 @@ void table_table_row::xlsx_convert(oox::xlsx_conversion_context & Context)
///обработка чтилей для роу -
size_t Default_Cell_style_in_row_ = 0;
const std::wstring rowStyleName = table_table_row_attlist_.table_style_name_.get_value_or( style_ref(L"") ).style_name();
const std::wstring defaultCellStyleName = table_table_row_attlist_.table_default_cell_style_name_.get_value_or( style_ref(L"") ).style_name();
const std::wstring rowStyleName = table_table_row_attlist_.table_style_name_.get_value_or(L"");
const std::wstring defaultCellStyleName = table_table_row_attlist_.table_default_cell_style_name_.get_value_or( L"");
style_instance * instStyle_CellDefault =
Context.root()->odf_context().styleContainer().style_by_name(defaultCellStyleName, style_family::TableCell,false/*false*/);
......@@ -109,8 +109,8 @@ void table_table_row::xlsx_convert(oox::xlsx_conversion_context & Context)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool skip_next_row = false;
std::wstring ht = L"";
double row_height = 0.0;
std::wstring ht = L"";
double row_height = 0.0;
odf_read_context & odfContext = Context.root()->odf_context();
......@@ -211,10 +211,10 @@ void table_table_row::xlsx_convert(oox::xlsx_conversion_context & Context)
if (Context.is_empty_row())
{
skip_next_row = true;
if (table_table_row_attlist_.table_number_rows_repeated_ > 0xff00)
if (table_table_row_attlist_.table_number_rows_repeated_ > 0xf000)
break;//Уведомление_о_вручении.ods (1 лист)
}
if (content_.size() > 0 && table_table_row_attlist_.table_number_rows_repeated_ > 0xff00)
if (content_.size() > 0 && table_table_row_attlist_.table_number_rows_repeated_ > 1000)
{
table_table_cell * table_cell = dynamic_cast<table_table_cell *>(content_[0].get());
if ((table_cell) && (table_cell->table_table_cell_attlist_.table_number_columns_repeated_ > 1000))
......@@ -250,6 +250,27 @@ void table_rows::xlsx_convert(oox::xlsx_conversion_context & Context)
table_table_rows_->xlsx_convert(Context);
else
{
if (table_table_row_.size() > 1)
{
//check 2 last rows for repeate > 65000 & 1024
table_table_row* row_last = dynamic_cast<table_table_row*>(table_table_row_[table_table_row_.size() - 1].get());
table_table_row* row_last_1 = dynamic_cast<table_table_row*>(table_table_row_[table_table_row_.size() - 2].get());
if (row_last->table_table_row_attlist_.table_number_rows_repeated_ > 1000 &&
row_last_1->table_table_row_attlist_.table_number_rows_repeated_ > 1000 ||
row_last_1->table_table_row_attlist_.table_number_rows_repeated_ > 0xf000)
{
std::wstring style = row_last->table_table_row_attlist_.table_style_name_.get_value_or(L"");
std::wstring style_1 = row_last->table_table_row_attlist_.table_style_name_.get_value_or(L"");
if (style == style_1)//check for empty also ????
{
row_last_1->table_table_row_attlist_.table_number_rows_repeated_ = 1024;
table_table_row_.pop_back();
}
}
}
for (int i = 0; i < table_table_row_.size(); i++)
{
table_table_row_[i]->xlsx_convert(Context);
......@@ -287,7 +308,7 @@ void table_table_row_group::xlsx_convert(oox::xlsx_conversion_context & Context)
void table_table::xlsx_convert(oox::xlsx_conversion_context & Context)
{
const std::wstring tableStyleName = table_table_attlist_.table_style_name_ ? table_table_attlist_.table_style_name_->style_name() : L"";
const std::wstring tableStyleName = table_table_attlist_.table_style_name_.get_value_or(L"");
const std::wstring tableName = table_table_attlist_.table_name_.get_value_or(L"");
_CP_LOG << L"[info][xlsx] process table \"" << tableName << L"\"\n" << std::endl;
......@@ -389,8 +410,8 @@ void table_table_column::xlsx_convert(oox::xlsx_conversion_context & Context)
std::wostream & strm = Context.current_sheet().cols();
const unsigned int columnsRepeated = table_table_column_attlist_.table_number_columns_repeated_;
const std::wstring styleName = table_table_column_attlist_.table_style_name_.get_value_or(style_ref(L"")).style_name();
const std::wstring defaultCellStyleName = table_table_column_attlist_.table_default_cell_style_name_.get_value_or(style_ref(L"")).style_name();
const std::wstring styleName = table_table_column_attlist_.table_style_name_.get_value_or(L"");
const std::wstring defaultCellStyleName = table_table_column_attlist_.table_default_cell_style_name_.get_value_or(L"");
int cMin = 0, cMax = 0;
......@@ -447,7 +468,7 @@ void table_table_column::xlsx_convert(oox::xlsx_conversion_context & Context)
}
}
_CP_OPT(double) width;
const std::wstring colStyleName = table_table_column_attlist_.table_style_name_->style_name();
const std::wstring colStyleName = table_table_column_attlist_.table_style_name_.get_value_or(L"");
if (style_instance * inst = Context.root()->odf_context().styleContainer().style_by_name(colStyleName, style_family::TableColumn,false))
{
if (inst->content())
......@@ -471,7 +492,9 @@ void table_table_column::xlsx_convert(oox::xlsx_conversion_context & Context)
//const double width = cmToChars(prop->style_table_column_properties_attlist_.style_column_width_->get_value_unit(length::cm));
// see ECMA-376 page 1768
CP_XML_ATTR(L"width", *width);
if (in_width > 0)
CP_XML_ATTR(L"width", *width);
CP_XML_ATTR(L"customWidth", true);
Context.table_column_last_width(*width);
}
......@@ -582,7 +605,7 @@ void table_table_cell::xlsx_convert(oox::xlsx_conversion_context & Context)
std::wostream & strm = Context.current_sheet().sheetData();
const std::wstring formula = table_table_cell_attlist_.table_formula_.get_value_or(L"");
const std::wstring styleName = table_table_cell_attlist_.table_style_name_.get_value_or(style_ref(L"")).style_name();
const std::wstring styleName = table_table_cell_attlist_.table_style_name_.get_value_or(L"");
const common_value_and_type_attlist & attr = table_table_cell_attlist_.common_value_and_type_attlist_;
office_value_type::type odf_value_type = office_value_type::Custom;
......
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