Compare commits

...

4 Commits

Author SHA1 Message Date
2f9a8eb77f OdfFormatReader - pilots converting .. 2017-08-11 09:47:20 +03:00
a70087e1f2 no base 64 data 2017-08-09 19:44:57 +03:00
c3da9a66a1 OdfFormatReader - convert pilots ... 2017-08-09 18:23:25 +03:00
f907a90be7 . 2017-08-09 18:22:42 +03:00
18 changed files with 1665 additions and 1334 deletions

View File

@ -51,6 +51,7 @@ public:
// $Лист1.$A$1 -> Лист1!$A$1
std::wstring convert_named_ref(std::wstring const & expr, bool withTableName = true, std::wstring separator = L" ");
std::wstring get_table_name();
//a-la convert without check formula
std::wstring convert_named_expr(std::wstring const & expr, bool withTableName = true);
@ -90,7 +91,7 @@ public:
std::wstring convert_named_ref (std::wstring const & expr);
std::wstring convert_named_formula(std::wstring const & expr);
std::wstring get_base_cell_formula(std::wstring const & expr);
std::wstring get_table_name();
//Sheet2!C3:C19 -> Sheet2.C3:Sheet2.C19
std::wstring convert_chart_distance(std::wstring const & expr);

View File

@ -43,7 +43,6 @@ namespace formulasconvert {
class odf2oox_converter::Impl
{
public:
static bool convert_with_TableName;
std::wstring convert(const std::wstring& expr);
std::wstring convert_chart_distance(const std::wstring& expr);
@ -61,8 +60,12 @@ namespace formulasconvert {
void replace_named_ref(std::wstring & expr, bool w = true);
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);
static bool convert_with_TableName;
static std::wstring table_name_;
};
bool odf2oox_converter::Impl::convert_with_TableName = true;
bool odf2oox_converter::Impl::convert_with_TableName = true;
std::wstring odf2oox_converter::Impl::table_name_ = L"";
bool odf2oox_converter::Impl::find_first_last_ref(std::wstring const & expr, std::wstring & table,std::wstring & ref_first,std::wstring & ref_last)
{
@ -152,6 +155,8 @@ namespace formulasconvert {
std::wstring sheet1 = what[1].str();
XmlUtils::replace_all( sheet1, L"$", L"");
table_name_ = sheet1;
const std::wstring c1 = what[2].str();
const std::wstring c2 = what[3].str();
@ -180,6 +185,8 @@ namespace formulasconvert {
const std::wstring c2 = what[3].str(); //sheet name 2
const std::wstring c3 = what[4].str();
table_name_ = sheet1;
if (convert_with_TableName)
{
return (sheet1 + L"!") + c1 + (c2.empty() ? L"" : (L":" + c3) );
@ -559,6 +566,11 @@ namespace formulasconvert {
{
}
std::wstring odf2oox_converter::get_table_name()
{
return impl_->table_name_;
}
std::wstring odf2oox_converter::convert(const std::wstring& expr)
{
return impl_->convert(expr);
@ -590,6 +602,13 @@ namespace formulasconvert {
XmlUtils::replace_all( workstr, L"PROBEL" , L" ");
XmlUtils::replace_all( workstr, L"APOSTROF" , L"'");
XmlUtils::replace_all( workstr, L"TOCHKA" , L".");
if (impl_->table_name_.empty() == false)
{
XmlUtils::replace_all( impl_->table_name_, L"PROBEL" , L" ");
XmlUtils::replace_all( impl_->table_name_, L"APOSTROF" , L"'");
XmlUtils::replace_all( impl_->table_name_, L"TOCHKA" , L".");
}
return workstr;
}
std::wstring odf2oox_converter::convert_named_expr(const std::wstring& expr, bool withTableName)
@ -629,6 +648,13 @@ namespace formulasconvert {
XmlUtils::replace_all( workstr, L"PROBEL" , L" ");
XmlUtils::replace_all( workstr, L"APOSTROF" , L"'");
XmlUtils::replace_all( workstr, L"TOCHKA" , L".");
if (impl_->table_name_.empty() == false)
{
XmlUtils::replace_all( impl_->table_name_, L"PROBEL" , L" ");
XmlUtils::replace_all( impl_->table_name_, L"APOSTROF" , L"'");
XmlUtils::replace_all( impl_->table_name_, L"TOCHKA" , L".");
}
}
return workstr;
}

View File

@ -65,11 +65,11 @@ public:
static bool isFindBaseCell_;
static std::wstring base_cell_formula_;
static std::wstring table_name_;
};
bool oox2odf_converter::Impl::isFindBaseCell_ = false;
std::wstring oox2odf_converter::Impl::base_cell_formula_ = L"";
std::wstring oox2odf_converter::Impl::table_name_ = L"";
void oox2odf_converter::Impl::replace_cells_range(std::wstring& expr)
{
@ -117,9 +117,9 @@ std::wstring oox2odf_converter::Impl::replace_cells_range_formater1(boost::wsmat
{
XmlUtils::replace_all( sheet, L"!", L"");
if (isFindBaseCell_ && base_cell_formula_.empty() && !sheet.empty())
if (isFindBaseCell_ && table_name_.empty() && !sheet.empty())
{
base_cell_formula_ = sheet + L".$A$1";
table_name_ = sheet + L".$A$1";
}
if (!sheet.empty() && (std::wstring::npos != c1.find(L"$"))) sheet = L"$" + sheet;
@ -161,7 +161,7 @@ std::wstring oox2odf_converter::Impl::replace_cells_range_formater2(boost::wsmat
void oox2odf_converter::Impl::replace_named_formula(std::wstring & expr)
{
base_cell_formula_.clear();
table_name_.clear();
isFindBaseCell_ = true;
expr = convert_formula(expr);
@ -171,7 +171,7 @@ void oox2odf_converter::Impl::replace_named_formula(std::wstring & expr)
// Лист1!$A$1 -> $Лист1.$A$1
void oox2odf_converter::Impl::replace_named_ref(std::wstring & expr)
{
base_cell_formula_.clear();
table_name_.clear();
isFindBaseCell_ = true;
std::wstring workstr = expr, out;
@ -207,6 +207,15 @@ void oox2odf_converter::Impl::replace_named_ref(std::wstring & expr)
if (!out.empty()) expr = out.substr(0, out.length() - 1);
isFindBaseCell_ = false;
if (table_name_.empty() == false)
{
XmlUtils::replace_all( table_name_, L"SCOBCAIN", L"(");
XmlUtils::replace_all( table_name_, L"SCOBCAOUT", L")");
XmlUtils::replace_all( table_name_, L"PROBEL", L" ");
XmlUtils::replace_all( table_name_, L"APOSTROF", L"'");
XmlUtils::replace_all( table_name_, L"KAVYCHKA", L"\"");
}
}
@ -471,6 +480,21 @@ std::wstring oox2odf_converter::Impl::convert_formula(const std::wstring & expr)
XmlUtils::replace_all( res, L"PROBEL", L" ");
if (table_name_.empty() == false)
{
XmlUtils::replace_all( table_name_, L"SCOBCAIN", L"(");
XmlUtils::replace_all( table_name_, L"SCOBCAOUT", L")");
XmlUtils::replace_all( table_name_, L"KVADRATIN", L"[");
XmlUtils::replace_all( table_name_, L"KVADRATOUT", L"]");
XmlUtils::replace_all( table_name_, L"APOSTROF", L"'");
XmlUtils::replace_all( table_name_, L"KAVYCHKA", L"\"");
XmlUtils::replace_all( table_name_, L"PROBEL", L" ");
}
return std::wstring(L"of:=") + res;
}
@ -614,9 +638,9 @@ std::wstring oox2odf_converter::convert_named_formula(const std::wstring& expr)
impl_->replace_named_formula(workstr);
return workstr;
}
std::wstring oox2odf_converter::get_base_cell_formula(const std::wstring& expr)
std::wstring oox2odf_converter::get_table_name()
{
return impl_->base_cell_formula_;
return impl_->table_name_;
}

View File

@ -40,111 +40,68 @@ namespace oox {
class xlsx_pivots_context::Impl
{
public:
struct _pivot_cache
struct _pivot_xml
{
std::wstring definitionsData_;
std::wstring recordsData_;
};
struct _pivot_view
{
std::wstring data_;
int indexCache_;
};
struct _pivot_field
{
std::wstring view_;
std::wstring cache_;
std::wstring definitionsData_; //cacheData
std::wstring recordsData_; //cacheRecorda
std::wstring viewData_; //tableView
};
Impl() {}
std::vector<_pivot_cache> caches_;
std::vector<_pivot_view> views_;
std::vector<_pivot_xml> pivot_xmls_;
std::wstring connections_;
std::vector<_pivot_field> fields_;
std::wstringstream view_;
std::wstringstream cache_;
struct _field
{
std::wstring name;
int type = -1;
int function = -1;
std::wstring user_function;
std::vector<int> subtotals;
std::vector<std::wstring> caches;
};
struct _desc
{
void clear()
{
name.clear();
location_ref.clear();
source_ref.clear();
fields.clear();
row_fields.clear();
page_fields.clear();
col_fields.clear();
data_fields.clear();
}
std::wstring name;
std::wstring location_ref;
std::wstring source_ref;
std::vector<_field> fields;
std::vector<int> row_fields;
std::vector<int> page_fields;
std::vector<int> col_fields;
std::vector<int> data_fields;
}current_;
void serialize_view(std::wostream & strm);
};
xlsx_pivots_context::xlsx_pivots_context() : impl_(new xlsx_pivots_context::Impl())
{
}
void xlsx_pivots_context::add_cache(std::wstring definitions, std::wstring records)
void xlsx_pivots_context::Impl::serialize_view(std::wostream & strm)
{
Impl::_pivot_cache c = {definitions, records};
impl_->caches_.push_back(c);
}
int xlsx_pivots_context::get_cache_count()
{
return (int)impl_->caches_.size();
}
bool xlsx_pivots_context::is_connections()
{
return !impl_->connections_.empty();
}
void xlsx_pivots_context::dump_rels_cache(int index, rels & Rels)
{
if (impl_->caches_[index].recordsData_.empty() == false)
{
Rels.add(relationship(L"rId1",
L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheRecords",
L"pivotCacheRecords" + std::to_wstring(index + 1) + L".xml", L""));
}
}
void xlsx_pivots_context::dump_rels_view(int index, rels & Rels)
{
if (impl_->views_[index].indexCache_ >= 0)
{
Rels.add(relationship(L"rId1",
L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition",
L"../pivotCache/pivotCacheDefinition" + std::to_wstring(impl_->views_[index].indexCache_ + 1) + L".xml", L""));
}
}
void xlsx_pivots_context::write_cache_definitions_to(int index, std::wostream & strm)
{
strm << impl_->caches_[index].definitionsData_;
}
void xlsx_pivots_context::write_connections_to(std::wostream & strm)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE(L"connections")
{
CP_XML_ATTR(L"xmlns", L"http://schemas.openxmlformats.org/spreadsheetml/2006/main");
CP_XML_STREAM() << impl_->connections_;
}
}
}
void xlsx_pivots_context::write_cache_records_to(int index, std::wostream & strm)
{
strm << impl_->caches_[index].recordsData_;
}
void xlsx_pivots_context::write_table_view_to(int index, std::wostream & strm)
{
strm << impl_->views_[index].data_;
}
void xlsx_pivots_context::start_table()
{
impl_->fields_.clear();
}
int xlsx_pivots_context::end_table()
{
std::wstringstream strm;
CP_XML_WRITER(strm)
{
CP_XML_NODE(L"pivotTableDefinition")
{
CP_XML_ATTR(L"xmlns", L"http://schemas.openxmlformats.org/spreadsheetml/2006/main");
//CP_XML_ATTR(L"name", view->stTable.value());
//CP_XML_ATTR(L"cacheId", view->iCache);
CP_XML_ATTR(L"name", current_.name);
CP_XML_ATTR(L"cacheId", pivot_xmls_.size());
//CP_XML_ATTR(L"dataOnRows", view->sxaxis4Data.bRw);
//CP_XML_ATTR(L"applyNumberFormats", view->fAtrNum);
//CP_XML_ATTR(L"applyBorderFormats", view->fAtrBdr);
@ -168,7 +125,7 @@ int xlsx_pivots_context::end_table()
CP_XML_NODE(L"location")
{
//CP_XML_ATTR(L"ref", view->ref.toString());
CP_XML_ATTR(L"ref", current_.location_ref);
//CP_XML_ATTR(L"firstHeaderRow", view->rwFirstHead - view->ref.rowFirst );
//CP_XML_ATTR(L"firstDataRow", view->rwFirstData - view->ref.rowFirst);
//CP_XML_ATTR(L"firstDataCol", view->colFirstData - view->ref.columnFirst);
@ -177,36 +134,215 @@ int xlsx_pivots_context::end_table()
}
CP_XML_NODE(L"pivotFields")
{
CP_XML_ATTR(L"count", impl_->fields_.size());
for (size_t i = 0; i < impl_->fields_.size(); i++)
CP_XML_ATTR(L"count", current_.fields.size());
for (size_t i = 0; i < current_.fields.size(); i++)
{
impl_->fields_[i].view_;
CP_XML_NODE(L"pivotField")
{
switch(current_.fields[i].type)
{
case 0: CP_XML_ATTR(L"axis", L"axisCol"); break;
case 1: break;// data,
case 2: break;// hidden,
case 3: CP_XML_ATTR(L"axis", L"axisPage"); break;
case 4: CP_XML_ATTR(L"axis", L"axisRow"); break;
}
CP_XML_ATTR(L"defaultSubtotal", 0);
//compact="0" outline="0" subtotalTop="0" showAll="0" includeNewItemsInFilter="1" sortType="ascending"
CP_XML_NODE(L"items")
{
CP_XML_ATTR(L"count", current_.fields[i].caches.size());
for (size_t j = 0; j < current_.fields[i].caches.size(); j++)
{
CP_XML_NODE(L"item")
{
CP_XML_ATTR(L"x", j);
}
}
}
}
//CP_XML_STREAM() << fields_[i].view_;
}
}
CP_XML_NODE(L"rowFields")
{
CP_XML_ATTR(L"count", current_.row_fields.size());
for (size_t i = 0; i < current_.row_fields.size(); i++)
{
CP_XML_NODE(L"field")
{
CP_XML_ATTR(L"x", current_.row_fields[i]);
}
}
}
CP_XML_NODE(L"colFields")
{
CP_XML_ATTR(L"count", current_.col_fields.size());
for (size_t i = 0; i < current_.col_fields.size(); i++)
{
CP_XML_NODE(L"field")
{
CP_XML_ATTR(L"x", current_.col_fields[i]);
}
}
}
CP_XML_NODE(L"pageFields")
{
CP_XML_ATTR(L"count", current_.page_fields.size());
for (size_t i = 0; i < current_.page_fields.size(); i++)
{
CP_XML_NODE(L"pageField")
{
CP_XML_ATTR(L"fld", current_.page_fields[i]);
CP_XML_ATTR(L"item", 0);
CP_XML_ATTR(L"hier", -1);
}
}
}
CP_XML_NODE(L"dataFields")
{
CP_XML_ATTR(L"count", current_.data_fields.size());
for (size_t i = 0; i < current_.data_fields.size(); i++)
{
CP_XML_NODE(L"dataField")
{
CP_XML_ATTR(L"fld", current_.data_fields[i]);
CP_XML_ATTR(L"baseField", 0);
//CP_XML_ATTR(L"baseItem", -1);
//CP_XML_ATTR(L"name", L"");
}
}
}
}
}
Impl::_pivot_view v = {strm.str(), impl_->views_.size() + 1};
impl_->views_.push_back(v);
return impl_->views_.size();
}
int xlsx_pivots_context::get_count()
{
return (int)impl_->pivot_xmls_.size();
}
bool xlsx_pivots_context::is_connections()
{
return !impl_->connections_.empty();
}
void xlsx_pivots_context::dump_rels_cache(int index, rels & Rels)
{
if (impl_->pivot_xmls_[index].recordsData_.empty() == false)
{
Rels.add(relationship(L"rId1",
L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheRecords",
L"pivotCacheRecords" + std::to_wstring(index + 1) + L".xml", L""));
}
}
void xlsx_pivots_context::dump_rels_view(int index, rels & Rels)
{
Rels.add(relationship(L"rId1",
L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition",
L"../pivotCache/pivotCacheDefinition" + std::to_wstring(index + 1) + L".xml", L""));
}
void xlsx_pivots_context::write_cache_definitions_to(int index, std::wostream & strm)
{
strm << impl_->pivot_xmls_[index].definitionsData_;
}
void xlsx_pivots_context::write_connections_to(std::wostream & strm)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE(L"connections")
{
CP_XML_ATTR(L"xmlns", L"http://schemas.openxmlformats.org/spreadsheetml/2006/main");
CP_XML_STREAM() << impl_->connections_;
}
}
}
void xlsx_pivots_context::write_cache_records_to(int index, std::wostream & strm)
{
strm << impl_->pivot_xmls_[index].recordsData_;
}
void xlsx_pivots_context::write_table_view_to(int index, std::wostream & strm)
{
strm << impl_->pivot_xmls_[index].viewData_;
}
void xlsx_pivots_context::start_table()
{
impl_->current_.clear();
}
int xlsx_pivots_context::end_table()
{
std::wstringstream view_strm;
std::wstringstream cache_strm;
std::wstringstream rec_strm;
impl_->serialize_view(view_strm);
Impl::_pivot_xml v = {cache_strm.str(), rec_strm.str(), view_strm.str()};
impl_->pivot_xmls_.push_back(v);
return impl_->pivot_xmls_.size();
}
void xlsx_pivots_context::set_view_name(std::wstring name)
{
impl_->current_.name = name;
}
void xlsx_pivots_context::set_view_target_range(std::wstring ref)
{
impl_->current_.location_ref = ref;
}
void xlsx_pivots_context::start_field()
{
Impl::_field f;
impl_->current_.fields.push_back(f);
}
void xlsx_pivots_context::set_field_name(std::wstring name)
{
impl_->current_.fields.back().name = name;
}
void xlsx_pivots_context::set_field_type(int type)
{
impl_->current_.fields.back().type = type;
switch(type)
{
case 0: impl_->current_.col_fields.push_back(impl_->current_.fields.size() - 1); break;// column,
case 1: impl_->current_.data_fields.push_back(impl_->current_.fields.size() - 1); break;// data,
case 2: break;// hidden,
case 3: impl_->current_.page_fields.push_back(impl_->current_.fields.size() - 1); break;// page,
case 4: impl_->current_.row_fields.push_back(impl_->current_.fields.size() - 1); break;// row
}
}
void xlsx_pivots_context::set_field_function(int type)
{
impl_->current_.fields.back().function = type;
}
void xlsx_pivots_context::set_field_user_function(std::wstring f)
{
impl_->current_.fields.back().user_function = f;
}
void xlsx_pivots_context::add_field_subtotal(int function_type)
{
impl_->current_.fields.back().subtotals.push_back(function_type);
}
void xlsx_pivots_context::add_field_cache(int index, std::wstring value)
{
while (index > impl_->current_.fields.back().caches.size())
{
impl_->current_.fields.back().caches.push_back(L"");
}
impl_->current_.fields.back().caches.push_back(value);
}
void xlsx_pivots_context::end_field()
{
std::wstringstream strm;
CP_XML_WRITER(strm)
{
CP_XML_NODE(L"pivotField")
{
}
}
Impl::_pivot_field f = {strm.str(), L""};
impl_->fields_.push_back(f);
}
void xlsx_pivots_context::set_source_range(std::wstring ref)
{
impl_->current_.source_ref = ref;
}
void xlsx_pivots_context::add_connections(std::wstring connections)
@ -216,25 +352,10 @@ void xlsx_pivots_context::add_connections(std::wstring connections)
impl_->connections_ = connections;
}
int xlsx_pivots_context::get_view_count()
{
return (int)impl_->views_.size();
}
xlsx_pivots_context::~xlsx_pivots_context()
{
}
std::wostream & xlsx_pivots_context::stream_view()
{
return impl_->view_;
}
std::wostream & xlsx_pivots_context::stream_cache()
{
return impl_->cache_;
}
}
}

View File

@ -50,13 +50,20 @@ public:
int end_table();
void start_field();
void set_field_name(std::wstring name);
void set_field_type(int type);
void set_field_function(int type);
void set_field_user_function(std::wstring f);
void add_field_subtotal(int function_type);
void add_field_cache(int index, std::wstring value);
void end_field();
//int add_view(int indexCache);
int get_view_count();
int get_count();
void add_cache(std::wstring definitions, std::wstring records);
int get_cache_count();
void set_view_name(std::wstring name);
void set_view_target_range(std::wstring ref);
void set_source_range(std::wstring ref);
void write_cache_definitions_to (int index, std::wostream & strm);
void write_cache_records_to (int index, std::wostream & strm);
@ -70,9 +77,6 @@ public:
void add_connections(std::wstring connections);
bool is_connections();
std::wostream & stream_view();
std::wostream & stream_cache();
private:
class Impl;
_CP_PTR(Impl) impl_;

View File

@ -148,9 +148,9 @@ void xlsx_table_context::start_table(std::wstring tableName, std::wstring tableS
void xlsx_table_context::end_table()
{
xlsx_table_states_.pop_back();
//xlsx_table_states_.pop_back();
}
void xlsx_table_context::start_cell(const std::wstring & formula, size_t columnsSpanned, size_t rowsSpanned)
{
state()->start_cell(columnsSpanned, rowsSpanned);

View File

@ -48,7 +48,6 @@ class xlsx_table_context
public:
xlsx_table_context(xlsx_conversion_context * Context, xlsx_text_context & textCotnext);
public:
void start_table(std::wstring tableName, std::wstring tableStyleName, int id);
void end_table();

View File

@ -232,7 +232,7 @@ void xlsx_conversion_context::end_document()
get_xlsx_defined_names().xlsx_serialize(CP_XML_STREAM());
int pivot_cache_count = xlsx_pivots_context_.get_cache_count();
int pivot_cache_count = xlsx_pivots_context_.get_count();
if (pivot_cache_count > 0)
{
CP_XML_NODE(L"pivotCaches")
@ -259,7 +259,7 @@ void xlsx_conversion_context::end_document()
}
}
}
int pivot_view_count = xlsx_pivots_context_.get_view_count();
int pivot_view_count = xlsx_pivots_context_.get_count();
if (pivot_view_count > 0)
{
for (int i = 0; i < pivot_view_count; i++)
@ -363,17 +363,33 @@ oox_chart_context & xlsx_conversion_context::current_chart()
throw std::runtime_error("internal error");
}
}
xlsx_xml_worksheet & xlsx_conversion_context::current_sheet()
xlsx_xml_worksheet & xlsx_conversion_context::current_sheet(int index)
{
if (!sheets_.empty())
{
return *sheets_.back().get();
if (index < 0) return *sheets_.back().get();
else return *sheets_[index].get();
}
else
{
throw std::runtime_error("internal error");
}
}
int xlsx_conversion_context::find_sheet_by_name(std::wstring tableName)
{
if (tableName.empty()) return -1;
if (0 == tableName.find(L"'"))
{
tableName = tableName.substr(1, tableName.length() - 2);
}
for (size_t i = 0; i < sheets_.size(); i++)
{
if (sheets_[i]->name() == tableName)
return i;
}
return -1;
}
void xlsx_conversion_context::create_new_sheet(std::wstring const & name)
{
sheets_.push_back(xlsx_xml_worksheet::create(name));

View File

@ -102,7 +102,10 @@ public:
bool start_table (std::wstring tableName, std::wstring tableStyleName);
void end_table ();
void start_table_column (unsigned int repeated, const std::wstring & defaultCellStyleName, int & cMin, int & cMax);
int find_sheet_by_name(std::wstring tableName);
xlsx_xml_worksheet & current_sheet(int index = -1);
void start_table_column (unsigned int repeated, const std::wstring & defaultCellStyleName, int & cMin, int & cMax);
void table_column_last_width (double w);
double table_column_last_width ();
void end_table_column ();
@ -162,7 +165,6 @@ public:
xlsx_table_context & get_table_context() { return xlsx_table_context_; }
const xlsx_table_context & get_table_context() const { return xlsx_table_context_; }
xlsx_style_manager & get_style_manager() { return xlsx_style_; }
xlsx_xml_worksheet & current_sheet();
oox_chart_context & current_chart();
math_context & get_math_context() { return math_context_; }

View File

@ -31,6 +31,7 @@
*/
#include "table_data_pilot_tables.h"
#include "../formulasconvert/formulasconvert.h"
#include <cpdoccore/xml/xmlchar.h>
#include <cpdoccore/xml/attributes.h>
@ -72,7 +73,7 @@ void table_data_pilot_table::add_attributes( const xml::attributes_wc_ptr & Attr
CP_APPLY_ATTR(L"table:identify-categories" , table_identify_categories_);
CP_APPLY_ATTR(L"table:ignore-empty-rows" , table_ignore_empty_rows_);
CP_APPLY_ATTR(L"table:show-filter-button" , table_show_filter_button_);
CP_APPLY_ATTR(L"table:show-target-range-address", table_show_target_range_address_);
CP_APPLY_ATTR(L"table:target-range-address" , table_target_range_address_);
}
@ -88,8 +89,23 @@ void table_data_pilot_table::xlsx_convert(oox::xlsx_conversion_context & Context
{
if (!source_) return;
int table_index = -1;
Context.get_pivots_context().start_table();
if (table_name_) Context.get_pivots_context().set_view_name(*table_name_);
if (table_target_range_address_)
{
formulasconvert::odf2oox_converter formulas_converter;
std::wstring ref = formulas_converter.convert_named_ref(*table_target_range_address_, false);
std::wstring table_name = formulas_converter.get_table_name();
table_index = Context.find_sheet_by_name(table_name);
Context.get_pivots_context().set_view_target_range(ref);
//Context.get_pivots_context().set_view_target_table(table_index);
}
source_->xlsx_convert(Context);
for (size_t i = 0; i < fields_.size(); i++)
@ -101,7 +117,7 @@ void table_data_pilot_table::xlsx_convert(oox::xlsx_conversion_context & Context
if (index_view > 0)
{
Context.current_sheet().sheet_rels().add(oox::relationship(L"pvId" + std::to_wstring(index_view),
Context.current_sheet(table_index).sheet_rels().add(oox::relationship(L"pvId" + std::to_wstring(index_view),
L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotTable",
L"../pivotTables/pivotTable" + std::to_wstring(index_view) + L".xml"));
}
@ -123,16 +139,37 @@ void table_data_pilot_field::add_attributes( const xml::attributes_wc_ptr & Attr
void table_data_pilot_field::add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name)
{
CP_CREATE_ELEMENT (content_);
if (L"table" == Ns && L"data-pilot-field-reference" == Name)
CP_CREATE_ELEMENT (reference_);
else if (L"table" == Ns && L"data-pilot-level" == Name)
CP_CREATE_ELEMENT (level_);
else if (L"table" == Ns && L"data-pilot-groups" == Name)
CP_CREATE_ELEMENT (groups_);
}
void table_data_pilot_field::xlsx_convert(oox::xlsx_conversion_context & Context)
{
Context.get_pivots_context().start_field();
Context.get_pivots_context().set_field_name(table_source_field_name_.get_value_or(L""));
Context.get_pivots_context().set_field_type(table_orientation_.get_value_or(table_orientation::hidden).get_type());
for (size_t i = 0; i < content_.size(); i++)
if (table_function_)
{
content_[i]->xlsx_convert(Context);
}
table_function::type type = table_function_->get_type();
if (type == table_function::String)
{
Context.get_pivots_context().set_field_user_function(table_function_->get_string());
}
else
{
Context.get_pivots_context().set_field_function(type);
}
}
if (reference_) reference_->xlsx_convert(Context);
if (groups_) groups_->xlsx_convert(Context);
if (level_) level_->xlsx_convert(Context);
Context.get_pivots_context().end_field();
}
@ -211,9 +248,14 @@ void table_source_cell_range::add_child_element( xml::sax * Reader, const std::w
}
void table_source_cell_range::xlsx_convert(oox::xlsx_conversion_context & Context)
{
for (size_t i = 0; i < content_.size(); i++)
{
content_[i]->xlsx_convert(Context);
if (table_cellrange_address_)
{
formulasconvert::odf2oox_converter formulas_converter;
std::wstring ref = formulas_converter.convert_named_ref(*table_cellrange_address_, false);
std::wstring table_name = formulas_converter.get_table_name();
Context.get_pivots_context().set_source_range(ref);
}
}
//-------------------------------------------------------------------------------------------------
@ -242,15 +284,36 @@ void table_data_pilot_level::add_attributes( const xml::attributes_wc_ptr & Attr
}
void table_data_pilot_level::add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name)
{
CP_CREATE_ELEMENT (content_);
if (L"table" == Ns && L"data-pilot-members" == Name)
CP_CREATE_ELEMENT (members_);
else if (L"table" == Ns && L"data-pilot-subtotals" == Name)
CP_CREATE_ELEMENT (subtotals_);
else if (L"table" == Ns && L"data-pilot-display-info" == Name)
CP_CREATE_ELEMENT ( display_info_);
else if (L"table" == Ns && L"data-pilot-layout-info" == Name)
CP_CREATE_ELEMENT ( layout_info_);
else if (L"table" == Ns && L"data-pilot-sort-info" == Name)
CP_CREATE_ELEMENT (sort_info_);
}
void table_data_pilot_level::xlsx_convert(oox::xlsx_conversion_context & Context)
{
for (size_t i = 0; i < content_.size(); i++)
{
content_[i]->xlsx_convert(Context);
table_data_pilot_members* members = dynamic_cast<table_data_pilot_members*>(members_.get());
table_data_pilot_subtotals* subtotals = dynamic_cast<table_data_pilot_subtotals*>(subtotals_.get());
for (size_t i = 0; members && i < members->content_.size(); i++)
{
table_data_pilot_member* member = dynamic_cast<table_data_pilot_member*>(members->content_[i].get());
if (member)
Context.get_pivots_context().add_field_cache(i, member->table_name_.get_value_or(L""));
}
for (size_t i = 0; subtotals && i < subtotals->content_.size(); i++)
{
table_data_pilot_subtotal* subtotal = dynamic_cast<table_data_pilot_subtotal*>(subtotals->content_[i].get());
if (subtotal)
{
Context.get_pivots_context().add_field_subtotal(subtotal->table_function_.get_value_or(table_function::Auto).get_type());
}
}
}
//-------------------------------------------------------------------------------------------------
const wchar_t * table_data_pilot_groups::ns = L"table";

View File

@ -65,8 +65,8 @@ private:
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes ){}
virtual void add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name);
office_element_ptr_array content_;
public:
office_element_ptr_array content_;
};
CP_REGISTER_OFFICE_ELEMENT2(table_data_pilot_tables);
@ -87,7 +87,9 @@ private:
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes );
virtual void add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name);
public:
_CP_OPT(std::wstring) table_name_;
_CP_OPT(std::wstring) table_target_range_address_;
_CP_OPT(std::wstring) table_application_data_;
_CP_OPT(std::wstring) table_buttons_;
_CP_OPT(odf_types::Bool) table_drill_down_ondouble_click_;
@ -95,7 +97,6 @@ private:
_CP_OPT(odf_types::Bool) table_identify_categories_;
_CP_OPT(odf_types::Bool) table_ignore_empty_rows_;
_CP_OPT(odf_types::Bool) table_show_filter_button_;
_CP_OPT(odf_types::Bool) table_show_target_range_address_;
office_element_ptr source_;
office_element_ptr_array fields_;
@ -119,6 +120,7 @@ private:
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes );
virtual void add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name);
public:
_CP_OPT(std::wstring) table_source_field_name_;
_CP_OPT(odf_types::table_orientation) table_orientation_;
_CP_OPT(int) table_used_hierarchy_;
@ -127,7 +129,9 @@ private:
_CP_OPT(std::wstring) table_selected_page_;
_CP_OPT(odf_types::Bool) table_is_data_layout_field_;
office_element_ptr_array content_;
office_element_ptr reference_;
office_element_ptr level_;
office_element_ptr groups_;
};
CP_REGISTER_OFFICE_ELEMENT2(table_data_pilot_field);
@ -147,6 +151,7 @@ private:
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes );
virtual void add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name){}
public:
_CP_OPT(std::wstring) table_field_name_;
_CP_OPT(std::wstring) table_member_name_;
_CP_OPT(odf_types::member_type) table_member_type_;
@ -171,6 +176,7 @@ private:
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes );
virtual void add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name){}
public:
_CP_OPT(std::wstring) table_database_name_;
_CP_OPT(std::wstring) table_database_table_name_;
};
@ -193,6 +199,7 @@ private:
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes );
virtual void add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name){}
public:
_CP_OPT(std::wstring) table_database_name_;
_CP_OPT(std::wstring) table_query_name_;
};
@ -215,6 +222,7 @@ private:
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes );
virtual void add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name){}
public:
_CP_OPT(std::wstring) table_database_name_;
_CP_OPT(odf_types::Bool)table_parse_sql_statement_;
_CP_OPT(std::wstring) table_sql_statement_;
@ -238,8 +246,9 @@ private:
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes );
virtual void add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name);
public:
_CP_OPT(std::wstring) table_cellrange_address_;
office_element_ptr_array content_;
office_element_ptr_array content_; //filters
};
CP_REGISTER_OFFICE_ELEMENT2(table_source_cell_range);
@ -260,6 +269,7 @@ private:
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes );
virtual void add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name){}
public:
_CP_OPT(std::wstring) table_name_;
_CP_OPT(std::wstring) table_object_name_;
_CP_OPT(std::wstring) table_password_;
@ -285,8 +295,14 @@ private:
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes );
virtual void add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name);
public:
_CP_OPT(odf_types::Bool) table_show_empty_;
office_element_ptr_array content_;
office_element_ptr members_;
office_element_ptr subtotals_;
office_element_ptr display_info_;
office_element_ptr layout_info_;
office_element_ptr sort_info_;
};
CP_REGISTER_OFFICE_ELEMENT2(table_data_pilot_level);
//-------------------------------------------------------------------------------------
@ -306,6 +322,7 @@ private:
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes );
virtual void add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name);
public:
_CP_OPT(std::wstring) table_date_end_;
_CP_OPT(std::wstring) table_date_start_;
_CP_OPT(std::wstring) table_start; //double 18.2 or auto.
@ -334,6 +351,7 @@ private:
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes );
virtual void add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name);
public:
_CP_OPT(std::wstring) table_name_;
office_element_ptr_array content_;
};
@ -356,7 +374,8 @@ private:
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes ){}
virtual void add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name);
office_element_ptr_array content_;
public:
office_element_ptr_array content_;
};
CP_REGISTER_OFFICE_ELEMENT2(table_data_pilot_members);
@ -377,8 +396,9 @@ private:
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes );
virtual void add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name){}
_CP_OPT(odf_types::Bool) table_display_;
public:
_CP_OPT(std::wstring) table_name_;
_CP_OPT(odf_types::Bool) table_display_;
_CP_OPT(odf_types::Bool) table_show_details_;
};
CP_REGISTER_OFFICE_ELEMENT2(table_data_pilot_member);
@ -399,6 +419,7 @@ private:
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes );
virtual void add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name){}
public:
_CP_OPT(std::wstring) table_name_;
};
CP_REGISTER_OFFICE_ELEMENT2(table_data_pilot_group_member);
@ -419,6 +440,7 @@ private:
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes ){}
virtual void add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name);
public:
office_element_ptr_array content_;
};
@ -440,6 +462,7 @@ private:
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes );
virtual void add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name){}
public:
_CP_OPT(odf_types::table_function) table_function_;
};
@ -461,6 +484,7 @@ private:
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes );
virtual void add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name){}
public:
_CP_OPT(odf_types::Bool) table_add_empty_lines_;
_CP_OPT(std::wstring) table_layout_mode_; //tabular-layout, outlinesubtotals-top or outline-subtotals-bottom.
};
@ -482,6 +506,7 @@ private:
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes );
virtual void add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name){}
public:
_CP_OPT(std::wstring) table_data_field_;
_CP_OPT(odf_types::table_order) table_order_;
_CP_OPT(std::wstring) table_sort_mode_; //data, none, manual or name.
@ -504,6 +529,7 @@ private:
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes );
virtual void add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name){}
public:
_CP_OPT(std::wstring) table_data_field_;
_CP_OPT(std::wstring) table_display_member_mode_; //from-top or from-bottom.
_CP_OPT(odf_types::Bool) table_enabled_;
@ -512,6 +538,5 @@ private:
CP_REGISTER_OFFICE_ELEMENT2(table_data_pilot_display_info);
//-------------------------------------------------------------------------------------
}
}

View File

@ -138,7 +138,7 @@ void ods_table_context::add_defined_range(const std::wstring & name, const std::
XmlUtils::replace_all( odf_range, L"[", L"");
XmlUtils::replace_all( odf_range, L"]", L"");
std::wstring odf_base_cell = formulas_converter.get_base_cell_formula(cell_range);
std::wstring odf_base_cell = formulas_converter.get_table_name() + L".$A$1";
named_range->table_name_ = name;
named_range->table_cell_range_address_ = odf_range;
@ -182,7 +182,7 @@ void ods_table_context::add_defined_expression(const std::wstring & name, const
formulasconvert::oox2odf_converter formulas_converter;
std::wstring odf_value = formulas_converter.convert_named_formula(value);
std::wstring odf_base_cell = formulas_converter.get_base_cell_formula(value);
std::wstring odf_base_cell = formulas_converter.get_table_name() + L".$A$1";
named_expression->table_name_ = name;
named_expression->table_expression_ = odf_value;

View File

@ -219,6 +219,8 @@ void XlsxConverter::convert(OOX::Spreadsheet::CDefinedName *oox_defined)
bool printable = false;
if (name == L"_xlnm.Print_Area")printable = true;
//todoooo !!!! сделать анализ на функцию, диапазон, константы .... !!!
if (false)//если простой - range, составной - выражение
ods_context->add_defined_range (name, oox_defined->m_oRef.get2(), sheet_id, printable);
else

View File

@ -118,6 +118,8 @@ namespace PPTX
return parentFileAs<SlideMaster>().GetMediaFullPathNameFromRId(*embed);
else if(parentFileIs<Theme>())
return parentFileAs<Theme>().GetMediaFullPathNameFromRId(*embed);
else if(parentFileIs<NotesSlide>())
return parentFileAs<NotesSlide>().GetMediaFullPathNameFromRId(*embed);
return _T("");
}
else if(link.IsInit())
@ -137,6 +139,8 @@ namespace PPTX
return parentFileAs<SlideMaster>().GetMediaFullPathNameFromRId(*link);
else if(parentFileIs<Theme>())
return parentFileAs<Theme>().GetMediaFullPathNameFromRId(*link);
else if(parentFileIs<NotesSlide>())
return parentFileAs<NotesSlide>().GetMediaFullPathNameFromRId(*link);
return _T("");
}
return _T("");
@ -150,6 +154,7 @@ namespace PPTX
else if(parentFileIs<SlideLayout>()) pOleObject = parentFileAs<SlideLayout>().GetOleObject(oRId);
else if(parentFileIs<SlideMaster>()) pOleObject = parentFileAs<SlideMaster>().GetOleObject(oRId);
else if(parentFileIs<Theme>()) pOleObject = parentFileAs<Theme>().GetOleObject(oRId);
else if(parentFileIs<NotesSlide>()) pOleObject = parentFileAs<NotesSlide>().GetOleObject(oRId);
if (pOleObject.IsInit())
return pOleObject->filename().m_strFilename;

View File

@ -64,6 +64,8 @@ namespace PPTX
sLink = parentFileAs<SlideMaster>().GetFullHyperlinkNameFromRId(rid);
else if(parentFileIs<Theme>())
sLink = parentFileAs<Theme>().GetFullHyperlinkNameFromRId(rid);
else if(parentFileIs<NotesSlide>())
sLink = parentFileAs<NotesSlide>().GetFullHyperlinkNameFromRId(rid);
}
XmlUtils::replace_all(sLink, L"\\", L"/");

View File

@ -88,7 +88,33 @@ namespace PPTX
{
return type().DefaultFileName();
}
virtual std::wstring GetMediaFullPathNameFromRId(const OOX::RId& rid)const
{
smart_ptr<OOX::Image> p = GetImage(rid);
if (!p.is_init())
return _T("");
return p->filename().m_strFilename;
}
virtual std::wstring GetFullHyperlinkNameFromRId(const OOX::RId& rid)const
{
smart_ptr<OOX::HyperLink> p = GetHyperlink(rid);
if (!p.is_init())
return _T("");
return p->Uri().m_strFilename;
}
virtual std::wstring GetLinkFromRId(const OOX::RId& rid)const
{
//return relsTable.Links.GetTargetById(rid);
smart_ptr<OOX::External> pExt = Find(rid).smart_dynamic_cast<OOX::External>();
if (pExt.IsInit())
return pExt->Uri().m_strFilename;
smart_ptr<OOX::Media> pMedia = Find(rid).smart_dynamic_cast<OOX::Media>();
if (pMedia.IsInit())
return pMedia->filename().m_strFilename;
return _T("");
}
virtual void toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const
{
pWriter->StartRecord(NSBinPptxRW::NSMainTables::NotesSlides);

File diff suppressed because it is too large Load Diff

View File

@ -674,12 +674,20 @@ public:
m_nLen = read_int2(pData, nCur, nLen);
m_pData = new BYTE[m_nLen];
m_pDataCur = m_pData;
if (nVersion < 10)
{
m_pData = new BYTE[m_nLen];
m_pDataCur = m_pData;
read_base64_2(pData, nCur, nLen);
read_base64_2(pData, nCur, nLen);
delete[]pData;
delete[]pData;
}
else
{
m_nLen = nLen;
m_pData = (BYTE*)pData;
m_pDataCur = m_pData + m_nLen;
}
return nVersion;
}