Commit 691042c5 authored by ElenaSubbotina's avatar ElenaSubbotina

OdfFormatReader - convert pilot tables

parent d8f34224
...@@ -286,6 +286,7 @@ SOURCES += \ ...@@ -286,6 +286,7 @@ SOURCES += \
../src/docx/xlsx_table_metrics.cpp \ ../src/docx/xlsx_table_metrics.cpp \
../src/docx/xlsx_table_state.cpp \ ../src/docx/xlsx_table_state.cpp \
../src/docx/xlsx_textcontext.cpp \ ../src/docx/xlsx_textcontext.cpp \
../src/docx/xlsx_pivots_context.cpp \
../src/docx/xlsx_utils.cpp \ ../src/docx/xlsx_utils.cpp \
../src/docx/xlsx_xf.cpp ../src/docx/xlsx_xf.cpp
} }
......
...@@ -100,3 +100,4 @@ ...@@ -100,3 +100,4 @@
#include "../src/docx/xlsx_textcontext.cpp" #include "../src/docx/xlsx_textcontext.cpp"
#include "../src/docx/xlsx_utils.cpp" #include "../src/docx/xlsx_utils.cpp"
#include "../src/docx/xlsx_xf.cpp" #include "../src/docx/xlsx_xf.cpp"
#include "../src/docx/xlsx_pivots_context.cpp"
...@@ -57,8 +57,7 @@ public: ...@@ -57,8 +57,7 @@ public:
std::wstringstream ole_objects_; std::wstringstream ole_objects_;
std::wstringstream page_props_; std::wstringstream page_props_;
rels hyperlinks_rels_; rels sheet_rels_;
rels ole_objects_rels_;
std::wstring drawingName_; std::wstring drawingName_;
std::wstring drawingId_; std::wstring drawingId_;
...@@ -141,14 +140,11 @@ std::wostream & xlsx_xml_worksheet::page_properties() ...@@ -141,14 +140,11 @@ std::wostream & xlsx_xml_worksheet::page_properties()
} }
//--------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------
rels & xlsx_xml_worksheet::hyperlinks_rels() rels & xlsx_xml_worksheet::sheet_rels()
{ {
return impl_->hyperlinks_rels_; return impl_->sheet_rels_;
}
rels & xlsx_xml_worksheet::ole_objects_rels()
{
return impl_->ole_objects_rels_;
} }
void xlsx_xml_worksheet::write_to(std::wostream & strm) void xlsx_xml_worksheet::write_to(std::wostream & strm)
{ {
CP_XML_WRITER(strm) CP_XML_WRITER(strm)
......
...@@ -49,7 +49,7 @@ class xlsx_xml_worksheet: noncopyable ...@@ -49,7 +49,7 @@ class xlsx_xml_worksheet: noncopyable
public: public:
xlsx_xml_worksheet(std::wstring const & name); xlsx_xml_worksheet(std::wstring const & name);
~xlsx_xml_worksheet(); ~xlsx_xml_worksheet();
public:
std::wstring name() const; std::wstring name() const;
std::wostream & cols(); std::wostream & cols();
...@@ -65,8 +65,7 @@ public: ...@@ -65,8 +65,7 @@ public:
std::wostream & ole_objects(); std::wostream & ole_objects();
std::wostream & page_properties(); std::wostream & page_properties();
rels & hyperlinks_rels(); rels & sheet_rels(); //hyperlink, background image, external, media ...
rels & ole_objects_rels();
void write_to(std::wostream & strm); void write_to(std::wostream & strm);
......
...@@ -32,8 +32,6 @@ ...@@ -32,8 +32,6 @@
#include "xlsx_package.h" #include "xlsx_package.h"
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/ref.hpp> #include <boost/ref.hpp>
#include <cpdoccore/utf8cpp/utf8.h> #include <cpdoccore/utf8cpp/utf8.h>
...@@ -82,8 +80,25 @@ void xlsx_document::write(const std::wstring & RootPath) ...@@ -82,8 +80,25 @@ void xlsx_document::write(const std::wstring & RootPath)
content_type_file_.write(RootPath); content_type_file_.write(RootPath);
} }
//////////////////////////////////////////// //--------------------------------------------------------------------------------------------
pivot_cache_content::pivot_cache_content() : definitions_rels_file_(rels_file::create(L""))
{
}
_CP_PTR(pivot_cache_content) pivot_cache_content::create()
{
return boost::make_shared<pivot_cache_content>();
}
//--------------------------------------------------------------------------------------------
pivot_table_content::pivot_table_content() : rels_file_(rels_file::create(L""))
{
}
_CP_PTR(pivot_table_content) pivot_table_content::create()
{
return boost::make_shared<pivot_table_content>();
}
//--------------------------------------------------------------------------------------------
sheet_content::sheet_content() : rels_(rels_file::create(L"")) sheet_content::sheet_content() : rels_(rels_file::create(L""))
{ {
...@@ -101,13 +116,13 @@ void sheet_content::add_rel(relationship const & r) ...@@ -101,13 +116,13 @@ void sheet_content::add_rel(relationship const & r)
void sheet_content::add_rels(rels & r) void sheet_content::add_rels(rels & r)
{ {
BOOST_FOREACH(relationship & item, r.relationships()) std::vector<relationship> & items = r.relationships();
for (size_t i = 0; i < items.size(); i++)
{ {
rels_->get_rels().add(item); rels_->get_rels().add(items[i]);
} }
} }
//////////// //--------------------------------------------------------------------------------------------
sheets_files::sheets_files() sheets_files::sheets_files()
{} {}
...@@ -121,14 +136,12 @@ void sheets_files::write(const std::wstring & RootPath) ...@@ -121,14 +136,12 @@ void sheets_files::write(const std::wstring & RootPath)
std::wstring path = RootPath + FILE_SEPARATOR_STR + L"worksheets"; std::wstring path = RootPath + FILE_SEPARATOR_STR + L"worksheets";
NSDirectory::CreateDirectory(path.c_str()); NSDirectory::CreateDirectory(path.c_str());
size_t count = 0; for (size_t i = 0; i < sheets_.size(); i++)
BOOST_FOREACH(const sheet_content_ptr & item, sheets_)
{ {
if (item) sheet_content_ptr & item = sheets_[i];
{ if (!item) continue;
count++;
const std::wstring fileName = std::wstring(L"sheet") + std::to_wstring(count) + L".xml"; const std::wstring fileName = std::wstring(L"sheet") + std::to_wstring(i + 1) + L".xml";
const std::wstring kWSConType = L"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"; const std::wstring kWSConType = L"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml";
content_type_content * contentTypes = this->get_main_document()->get_content_types_file().content(); content_type_content * contentTypes = this->get_main_document()->get_content_types_file().content();
...@@ -136,7 +149,7 @@ void sheets_files::write(const std::wstring & RootPath) ...@@ -136,7 +149,7 @@ void sheets_files::write(const std::wstring & RootPath)
if (rels_) if (rels_)
{ {
const std::wstring id = std::wstring(L"sId") + std::to_wstring(count); const std::wstring id = std::wstring(L"sId") + std::to_wstring(i + 1);
static const std::wstring kWSRel = L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"; static const std::wstring kWSRel = L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet";
const std::wstring fileRef = std::wstring(L"worksheets/") + fileName; const std::wstring fileRef = std::wstring(L"worksheets/") + fileName;
rels_->add(id, kWSRel, fileRef); rels_->add(id, kWSRel, fileRef);
...@@ -151,11 +164,8 @@ void sheets_files::write(const std::wstring & RootPath) ...@@ -151,11 +164,8 @@ void sheets_files::write(const std::wstring & RootPath)
package::simple_element(fileName, item->str()).write(path); package::simple_element(fileName, item->str()).write(path);
} }
}
} }
//--------------------------------------------------------------------------------------------
////////////////////////////////////////////
xl_files::xl_files() xl_files::xl_files()
{ {
rels_files_.add_rel_file(rels_file::create(L"workbook.xml.rels")); rels_files_.add_rel_file(rels_file::create(L"workbook.xml.rels"));
...@@ -166,10 +176,20 @@ void xl_files::write(const std::wstring & RootPath) ...@@ -166,10 +176,20 @@ void xl_files::write(const std::wstring & RootPath)
std::wstring path = RootPath + FILE_SEPARATOR_STR + L"xl"; std::wstring path = RootPath + FILE_SEPARATOR_STR + L"xl";
NSDirectory::CreateDirectory(path.c_str()); NSDirectory::CreateDirectory(path.c_str());
{
pivot_cache_files_.set_rels(&rels_files_);
pivot_cache_files_.set_main_document(get_main_document());
pivot_cache_files_.write(path);
}
{
pivot_table_files_.set_main_document(get_main_document());
pivot_table_files_.write(path);
}
{
sheets_files_.set_rels(&rels_files_); sheets_files_.set_rels(&rels_files_);
sheets_files_.set_main_document( this->get_main_document() ); sheets_files_.set_main_document( this->get_main_document() );
sheets_files_.write(path); sheets_files_.write(path);
}
int index = 1; int index = 1;
if (true) if (true)
{ {
...@@ -181,6 +201,15 @@ void xl_files::write(const std::wstring & RootPath) ...@@ -181,6 +201,15 @@ void xl_files::write(const std::wstring & RootPath)
sharedStrings_->write(path); sharedStrings_->write(path);
rels_files_.add( relationship( L"shId1", L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings", L"sharedStrings.xml" ) ); rels_files_.add( relationship( L"shId1", L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings", L"sharedStrings.xml" ) );
} }
if (connections_)
{
connections_->write(path);
rels_files_.add( relationship( L"cnId1", L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/connections", L"connections.xml" ) );
content_type_content * contentTypes = this->get_main_document()->get_content_types_file().content();
contentTypes->add_override(L"/xl/connections.xml", L"application/vnd.openxmlformats-officedocument.spreadsheetml.connections+xml");
}
if (styles_) if (styles_)
{ {
styles_->write(path); styles_->write(path);
...@@ -235,7 +264,10 @@ void xl_files::set_sharedStrings(element_ptr Element) ...@@ -235,7 +264,10 @@ void xl_files::set_sharedStrings(element_ptr Element)
{ {
sharedStrings_ = Element; sharedStrings_ = Element;
} }
void xl_files::set_connections(element_ptr Element)
{
connections_ = Element;
}
void xl_files::add_sheet(sheet_content_ptr sheet) void xl_files::add_sheet(sheet_content_ptr sheet)
{ {
sheets_files_.add_sheet(sheet); sheets_files_.add_sheet(sheet);
...@@ -269,7 +301,102 @@ void xl_files::add_charts(chart_content_ptr chart) ...@@ -269,7 +301,102 @@ void xl_files::add_charts(chart_content_ptr chart)
{ {
charts_files_.add_chart(chart); charts_files_.add_chart(chart);
} }
//////////////////////////// void xl_files::add_pivot_cache(pivot_cache_content_ptr pivot_cache)
{
pivot_cache_files_.add_pivot_cache(pivot_cache);
}
void xl_files::add_pivot_table(pivot_table_content_ptr pivot_table)
{
pivot_table_files_.add_pivot_table(pivot_table);
}
//----------------------------------------------------------------------------------------
void xl_pivot_cache_files::add_pivot_cache(pivot_cache_content_ptr pivot_cache)
{
pivot_caches_.push_back(pivot_cache);
}
void xl_pivot_cache_files::write(const std::wstring & RootPath)
{
std::wstring path = RootPath + FILE_SEPARATOR_STR + L"pivotCache";
NSDirectory::CreateDirectory(path.c_str());
content_type_content * contentTypes = this->get_main_document()->get_content_types_file().content();
static const std::wstring kWSConTypeD = L"application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml";
static const std::wstring kWSConTypeR = L"application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheRecords+xml";
for (size_t i = 0; i < pivot_caches_.size(); i++)
{
if (pivot_caches_[i])
{
const std::wstring fileNameD = std::wstring(L"pivotCacheDefinition") + std::to_wstring(i + 1) + L".xml";
contentTypes->add_override(std::wstring(L"/xl/pivotCache/") + fileNameD, kWSConTypeD);
package::simple_element(fileNameD, pivot_caches_[i]->str_d()).write(path);
if (pivot_caches_[i]->get_rels().empty() == false)
{
rels_files relFiles;
pivot_caches_[i]->definitions_rels_file_->set_file_name(fileNameD + L".rels");
relFiles.add_rel_file(pivot_caches_[i]->definitions_rels_file_);
relFiles.write(path);
}
if (rels_) //for workbook
{
const std::wstring id = std::wstring(L"pcId") + std::to_wstring(i + 1);
static const std::wstring kWSRel = L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition";
const std::wstring fileRef = std::wstring(L"pivotCache/") + fileNameD;
rels_->add(id, kWSRel, fileRef);
}
std::wstring content_records = pivot_caches_[i]->str_r();
if (!content_records.empty())
{
const std::wstring fileNameR = std::wstring(L"pivotCacheRecords") + std::to_wstring(i + 1) + L".xml";
contentTypes->add_override(std::wstring(L"/xl/pivotCache/") + fileNameR, kWSConTypeR);
package::simple_element(fileNameR, content_records).write(path);
}
}
}
}
//----------------------------------------------------------------------------------------
void xl_pivot_table_files::add_pivot_table(pivot_table_content_ptr pivot_table)
{
pivot_tables_.push_back(pivot_table);
}
void xl_pivot_table_files::write(const std::wstring & RootPath)
{
std::wstring path = RootPath + FILE_SEPARATOR_STR + L"pivotTables";
NSDirectory::CreateDirectory(path.c_str());
content_type_content * contentTypes = this->get_main_document()->get_content_types_file().content();
static const std::wstring kWSConType = L"application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml";
for (size_t i = 0; i < pivot_tables_.size(); i++)
{
if (pivot_tables_[i])
{
const std::wstring fileName = std::wstring(L"pivotTable") + std::to_wstring(i + 1) + L".xml";
contentTypes->add_override(std::wstring(L"/xl/pivotTables/") + fileName, kWSConType);
package::simple_element(fileName, pivot_tables_[i]->str()).write(path);
if (pivot_tables_[i]->get_rels().empty() == false)
{
rels_files relFiles;
pivot_tables_[i]->rels_file_->set_file_name(fileName + L".rels");
relFiles.add_rel_file(pivot_tables_[i]->rels_file_);
relFiles.write(path);
}
}
}
}
//------------------------------------------------------------------------------------------------------
void xl_charts_files::add_chart(chart_content_ptr chart) void xl_charts_files::add_chart(chart_content_ptr chart)
{ {
charts_.push_back(chart); charts_.push_back(chart);
...@@ -281,29 +408,26 @@ void xl_charts_files::write(const std::wstring & RootPath) ...@@ -281,29 +408,26 @@ void xl_charts_files::write(const std::wstring & RootPath)
size_t count = 0; size_t count = 0;
BOOST_FOREACH(const chart_content_ptr & item, charts_) for (size_t i = 0; i < charts_.size(); i++)
{
if (item)
{ {
count++; count++;
const std::wstring fileName = std::wstring(L"chart") + std::to_wstring(count) + L".xml"; const std::wstring fileName = std::wstring(L"chart") + std::to_wstring(i + 1) + L".xml";
content_type_content * contentTypes = this->get_main_document()->get_content_types_file().content(); content_type_content * contentTypes = this->get_main_document()->get_content_types_file().content();
static const std::wstring kWSConType = L"application/vnd.openxmlformats-officedocument.drawingml.chart+xml"; static const std::wstring kWSConType = L"application/vnd.openxmlformats-officedocument.drawingml.chart+xml";
contentTypes->add_override(std::wstring(L"/xl/charts/") + fileName, kWSConType); contentTypes->add_override(std::wstring(L"/xl/charts/") + fileName, kWSConType);
package::simple_element(fileName, item->str()).write(path); package::simple_element(fileName, charts_[i]->str()).write(path);
rels_files relFiles; rels_files relFiles;
item->get_rel_file()->set_file_name(fileName + L".rels"); charts_[i]->get_rel_file()->set_file_name(fileName + L".rels");
relFiles.add_rel_file(item->get_rel_file()); relFiles.add_rel_file(charts_[i]->get_rel_file());
relFiles.write(path); relFiles.write(path);
} }
}
} }
////////////////////////// //------------------------------------------------------------------------------------------------------
xl_drawings_ptr xl_drawings::create(const std::vector<drawing_elm> & elms) xl_drawings_ptr xl_drawings::create(const std::vector<drawing_elm> & elms)
{ {
return boost::make_shared<xl_drawings>(boost::ref(elms)); return boost::make_shared<xl_drawings>(boost::ref(elms));
...@@ -314,14 +438,14 @@ void xl_drawings::write(const std::wstring & RootPath) ...@@ -314,14 +438,14 @@ void xl_drawings::write(const std::wstring & RootPath)
std::wstring path = RootPath + FILE_SEPARATOR_STR + L"drawings"; std::wstring path = RootPath + FILE_SEPARATOR_STR + L"drawings";
NSDirectory::CreateDirectory(path.c_str()); NSDirectory::CreateDirectory(path.c_str());
BOOST_FOREACH(drawing_elm const & e, drawings_) for (size_t i = 0; i < drawings_.size(); i++)
{ {
package::simple_element(e.filename, e.content).write(path); package::simple_element(drawings_[i].filename, drawings_[i].content).write(path);
rels_files relFiles; rels_files relFiles;
rels_file_ptr r = rels_file::create(e.filename + L".rels"); rels_file_ptr r = rels_file::create(drawings_[i].filename + L".rels");
e.drawings->dump_rels_drawing(r->get_rels()); drawings_[i].drawings->dump_rels_drawing(r->get_rels());
relFiles.add_rel_file(r); relFiles.add_rel_file(r);
relFiles.write(path); relFiles.write(path);
...@@ -329,7 +453,7 @@ void xl_drawings::write(const std::wstring & RootPath) ...@@ -329,7 +453,7 @@ void xl_drawings::write(const std::wstring & RootPath)
content_type_content * contentTypes = this->get_main_document()->get_content_types_file().content(); content_type_content * contentTypes = this->get_main_document()->get_content_types_file().content();
const std::wstring kDrawingCT = L"application/vnd.openxmlformats-officedocument.drawing+xml"; const std::wstring kDrawingCT = L"application/vnd.openxmlformats-officedocument.drawing+xml";
contentTypes->add_override(L"/xl/drawings/" + e.filename, kDrawingCT); contentTypes->add_override(L"/xl/drawings/" + drawings_[i].filename, kDrawingCT);
} }
} }
...@@ -344,15 +468,15 @@ void xl_comments::write(const std::wstring & RootPath) ...@@ -344,15 +468,15 @@ void xl_comments::write(const std::wstring & RootPath)
std::wstring vml_path = RootPath + FILE_SEPARATOR_STR + L"drawings"; std::wstring vml_path = RootPath + FILE_SEPARATOR_STR + L"drawings";
NSDirectory::CreateDirectory(vml_path.c_str()); NSDirectory::CreateDirectory(vml_path.c_str());
BOOST_FOREACH(comment_elm const & e, comments_) for (size_t i = 0; i < comments_.size(); i++)
{ {
content_type_content * contentTypes = this->get_main_document()->get_content_types_file().content(); content_type_content * contentTypes = this->get_main_document()->get_content_types_file().content();
static const std::wstring kWSConType = L"application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml"; static const std::wstring kWSConType = L"application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml";
contentTypes->add_override(std::wstring(L"/xl/") + e.filename, kWSConType); contentTypes->add_override(std::wstring(L"/xl/") + comments_[i].filename, kWSConType);
package::simple_element(e.filename, e.content).write(RootPath); package::simple_element(comments_[i].filename, comments_[i].content).write(RootPath);
package::simple_element(e.vml_filename, e.vml_content).write(vml_path); package::simple_element(comments_[i].vml_filename, comments_[i].vml_content).write(vml_path);
} }
} }
......
...@@ -50,9 +50,6 @@ public: ...@@ -50,9 +50,6 @@ public:
xlsx_content_types_file(); xlsx_content_types_file();
}; };
class sheet_content;
typedef _CP_PTR(sheet_content) sheet_content_ptr;
class sheet_content : noncopyable class sheet_content : noncopyable
{ {
public: public:
...@@ -68,8 +65,49 @@ private: ...@@ -68,8 +65,49 @@ private:
std::wstringstream content_; std::wstringstream content_;
rels_file_ptr rels_; rels_file_ptr rels_;
}; };
typedef _CP_PTR(sheet_content) sheet_content_ptr;
//------------------------------------------------------------------------
class pivot_cache_content;
typedef _CP_PTR(pivot_cache_content) pivot_cache_content_ptr;
class pivot_cache_content : boost::noncopyable
{
public:
pivot_cache_content();
static _CP_PTR(pivot_cache_content) create();
std::wostream & definitions() { return definitions_; }
std::wostream & records() { return records_; }
rels & get_rels() { return definitions_rels_file_->get_rels(); }
std::wstring str_d() { return definitions_.str(); }
std::wstring str_r() { return records_.str(); }
friend class xl_pivot_cache_files;
private:
std::wstringstream records_;
std::wstringstream definitions_;
rels_file_ptr definitions_rels_file_;
};
//------------------------------------------------------------------------
class pivot_table_content;
typedef _CP_PTR(pivot_table_content) pivot_table_content_ptr;
class pivot_table_content : boost::noncopyable
{
public:
pivot_table_content();
static _CP_PTR(pivot_table_content) create();
// sheets_files std::wostream & content() { return content_; }
rels & get_rels() { return rels_file_->get_rels(); }
std::wstring str() { return content_.str(); }
friend class xl_pivot_table_files;
private:
std::wstringstream content_;
rels_file_ptr rels_file_;
};
//------------------------------------------------------------------------
class sheets_files : public element class sheets_files : public element
{ {
public: public:
...@@ -90,7 +128,7 @@ public: ...@@ -90,7 +128,7 @@ public:
}; };
// xl_charts_files
class xl_charts_files : public element class xl_charts_files : public element
{ {
public: public:
...@@ -102,12 +140,37 @@ public: ...@@ -102,12 +140,37 @@ public:
std::vector<chart_content_ptr> charts_; std::vector<chart_content_ptr> charts_;
}; };
///////////////////////////////////////////////////////////
class xl_pivot_table_files : public element
{
public:
xl_pivot_table_files(){}
void add_pivot_table(pivot_table_content_ptr pivot_table);
virtual void write(const std::wstring & RootPath);
std::vector<pivot_table_content_ptr> pivot_tables_;
};
class xl_pivot_cache_files : public element
{
public:
xl_pivot_cache_files(){}
void set_rels(rels_files * rels)
{
rels_ = rels;
}
void add_pivot_cache(pivot_cache_content_ptr pivot_cache);
virtual void write(const std::wstring & RootPath);
std::vector<pivot_cache_content_ptr> pivot_caches_;
rels_files * rels_;
};
//-------------------------------------------------------------------------------------------------------------
class xl_comments; class xl_comments;
typedef _CP_PTR(xl_comments) xl_comments_ptr; typedef _CP_PTR(xl_comments) xl_comments_ptr;
// xl_comments
class xl_comments: public element class xl_comments: public element
{ {
public: public:
...@@ -121,13 +184,10 @@ public: ...@@ -121,13 +184,10 @@ public:
private: private:
const std::vector<comment_elm> & comments_; const std::vector<comment_elm> & comments_;
}; };
//-----------------------------------------------------------------------------------------------------
class xl_drawings; class xl_drawings;
typedef _CP_PTR(xl_drawings) xl_drawings_ptr; typedef _CP_PTR(xl_drawings) xl_drawings_ptr;
// xl_drawings
class xl_drawings: public element class xl_drawings: public element
{ {
public: public:
...@@ -146,10 +206,9 @@ public: ...@@ -146,10 +206,9 @@ public:
private: private:
const std::vector<drawing_elm> & drawings_; const std::vector<drawing_elm> & drawings_;
rels_files * rels_; rels_files * rels_;
}; };
//----------------------------------------------------------------------------------------------------------
// xl_files
class xl_files : public element class xl_files : public element
{ {
public: public:
...@@ -158,20 +217,25 @@ public: ...@@ -158,20 +217,25 @@ public:
public: public:
virtual void write(const std::wstring & RootPath); virtual void write(const std::wstring & RootPath);
void set_workbook(element_ptr Element); void set_workbook (element_ptr Element);
void set_styles(element_ptr Element); void set_styles (element_ptr Element);
void set_sharedStrings(element_ptr Element); void set_sharedStrings (element_ptr Element);
void add_sheet(sheet_content_ptr sheet); void set_connections (element_ptr Element);
void set_media(mediaitems & _Mediaitems, CApplicationFonts *pAppFonts); void add_sheet (sheet_content_ptr sheet);
void set_drawings(element_ptr Element); void set_media (mediaitems & _Mediaitems, CApplicationFonts *pAppFonts);
void set_vml_drawings(element_ptr Element); void set_drawings (element_ptr Element);
void set_comments(element_ptr Element); void set_vml_drawings (element_ptr Element);
void add_charts(chart_content_ptr chart); void set_comments (element_ptr Element);
void add_charts (chart_content_ptr chart);
void add_pivot_cache (pivot_cache_content_ptr cache);
void add_pivot_table (pivot_table_content_ptr table);
private: private:
rels_files rels_files_; rels_files rels_files_;
sheets_files sheets_files_; sheets_files sheets_files_;
xl_charts_files charts_files_; xl_charts_files charts_files_;
xl_pivot_cache_files pivot_cache_files_;
xl_pivot_table_files pivot_table_files_;
element_ptr theme_; element_ptr theme_;
element_ptr workbook_; element_ptr workbook_;
...@@ -183,10 +247,9 @@ private: ...@@ -183,10 +247,9 @@ private:
element_ptr drawings_; element_ptr drawings_;
element_ptr vml_drawings_; element_ptr vml_drawings_;
element_ptr comments_; element_ptr comments_;
element_ptr connections_;
}; };
// xlsx_document
class xlsx_document : public document class xlsx_document : public document
{ {
public: public:
......
/*
* (c) Copyright Ascensio System SIA 2010-2017
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#include "xlsx_pivots_context.h"
#include <boost/make_shared.hpp>
#include <cpdoccore/xml/simple_xml_writer.h>
namespace cpdoccore {
namespace oox {
class xlsx_pivots_context::Impl
{
public:
struct _pivot_cache
{
std::wstring definitionsData_;
std::wstring recordsData_;
};
struct _pivot_view
{
std::wstring data_;
int indexCache_;
};
struct _pivot_field
{
std::wstring view_;
std::wstring cache_;
};
Impl() {}
std::vector<_pivot_cache> caches_;
std::vector<_pivot_view> views_;
std::wstring connections_;
std::vector<_pivot_field> fields_;
std::wstringstream view_;
std::wstringstream cache_;
};
xlsx_pivots_context::xlsx_pivots_context() : impl_(new xlsx_pivots_context::Impl())
{
}
void xlsx_pivots_context::add_cache(std::wstring definitions, std::wstring records)
{
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"dataOnRows", view->sxaxis4Data.bRw);
//CP_XML_ATTR(L"applyNumberFormats", view->fAtrNum);
//CP_XML_ATTR(L"applyBorderFormats", view->fAtrBdr);
//CP_XML_ATTR(L"applyFontFormats", view->fAtrFnt);
//CP_XML_ATTR(L"applyPatternFormats", view->fAtrPat);
//CP_XML_ATTR(L"applyAlignmentFormats", view->fAtrAlc);
//CP_XML_ATTR(L"applyWidthHeightFormats", view->fAtrProc);
//if (!view->stData.value().empty())
//{
// CP_XML_ATTR(L"dataCaption", view->stData.value());
//}
//CP_XML_ATTR(L"asteriskTotals", 1);
//CP_XML_ATTR(L"showMemberPropertyTips", 0);
//CP_XML_ATTR(L"useAutoFormatting", view->fAutoFormat);
//CP_XML_ATTR(L"autoFormatId", view->itblAutoFmt);
CP_XML_ATTR(L"itemPrintTitles", 1);
CP_XML_ATTR(L"indent", 0);
CP_XML_ATTR(L"compact", 0);
CP_XML_ATTR(L"compactData", 0);
CP_XML_ATTR(L"gridDropZones", 1);
CP_XML_NODE(L"location")
{
//CP_XML_ATTR(L"ref", view->ref.toString());
//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);
CP_XML_ATTR(L"rowPageCount", 1);
CP_XML_ATTR(L"colPageCount", 1);
}
CP_XML_NODE(L"pivotFields")
{
CP_XML_ATTR(L"count", impl_->fields_.size());
for (size_t i = 0; i < impl_->fields_.size(); i++)
{
impl_->fields_[i].view_;
}
}
}
}
Impl::_pivot_view v = {strm.str(), impl_->views_.size() + 1};
impl_->views_.push_back(v);
return impl_->views_.size();
}
void xlsx_pivots_context::start_field()
{
}
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::add_connections(std::wstring connections)
{
if (connections.empty()) return;
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_;
}
}
}
\ No newline at end of file
/*
* (c) Copyright Ascensio System SIA 2010-2017
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#pragma once
#include "oox_package.h"
#include <cpdoccore/CPScopedPtr.h>
#include <cpdoccore/CPOptional.h>
namespace cpdoccore {
namespace oox {
class xlsx_pivot_cache_context;
typedef _CP_PTR(xlsx_pivot_cache_context) xlsx_pivot_cache_context_ptr;
class xlsx_pivots_context
{
public:
xlsx_pivots_context();
~xlsx_pivots_context();
void start_table();
int end_table();
void start_field();
void end_field();
//int add_view(int indexCache);
int get_view_count();
void add_cache(std::wstring definitions, std::wstring records);
int get_cache_count();
void write_cache_definitions_to (int index, std::wostream & strm);
void write_cache_records_to (int index, std::wostream & strm);
void write_connections_to (std::wostream & strm);
void write_table_view_to (int index, std::wostream & strm);
void dump_rels_cache(int index, rels & Rels);
void dump_rels_view (int index, rels & Rels);
void add_connections(std::wstring connections);
bool is_connections();
std::wostream & stream_view();
std::wostream & stream_cache();
private:
class Impl;
_CP_PTR(Impl) impl_;
};
}
}
\ No newline at end of file
...@@ -152,8 +152,7 @@ void xlsx_conversion_context::end_document() ...@@ -152,8 +152,7 @@ void xlsx_conversion_context::end_document()
content->add_rel(relationship(dId, kType, dName)); content->add_rel(relationship(dId, kType, dName));
} }
////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////
content->add_rels(sheet->hyperlinks_rels()); content->add_rels(sheet->sheet_rels());
content->add_rels(sheet->ole_objects_rels());
///////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////
const std::pair<std::wstring, std::wstring> p2 = sheet->get_comments_link(); const std::pair<std::wstring, std::wstring> p2 = sheet->get_comments_link();
if (!p2.first.empty()) if (!p2.first.empty())
...@@ -232,6 +231,54 @@ void xlsx_conversion_context::end_document() ...@@ -232,6 +231,54 @@ void xlsx_conversion_context::end_document()
} }
get_xlsx_defined_names().xlsx_serialize(CP_XML_STREAM()); get_xlsx_defined_names().xlsx_serialize(CP_XML_STREAM());
int pivot_cache_count = xlsx_pivots_context_.get_cache_count();
if (pivot_cache_count > 0)
{
CP_XML_NODE(L"pivotCaches")
{
for (int i = 0; i < pivot_cache_count; i++)
{
std::wstring rId = L"pcId" + std::to_wstring(i+1);
static const std::wstring sType = L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition";
const std::wstring sName = std::wstring(L"../pivotCache/pivotCacheDefinition" + std::to_wstring(i + 1) + L".xml");
package::pivot_cache_content_ptr content = package::pivot_cache_content::create();
CP_XML_NODE(L"pivotCache")
{
CP_XML_ATTR(L"cacheId", std::to_wstring(i));
CP_XML_ATTR(L"r:id", rId);
}
xlsx_pivots_context_.dump_rels_cache(i, content->get_rels());
xlsx_pivots_context_.write_cache_definitions_to(i, content->definitions());
xlsx_pivots_context_.write_cache_records_to(i, content->records());
output_document_->get_xl_files().add_pivot_cache(content);
}
}
}
int pivot_view_count = xlsx_pivots_context_.get_view_count();
if (pivot_view_count > 0)
{
for (int i = 0; i < pivot_view_count; i++)
{
package::pivot_table_content_ptr content = package::pivot_table_content::create();
xlsx_pivots_context_.dump_rels_view(i, content->get_rels());
xlsx_pivots_context_.write_table_view_to(i, content->content());
output_document_->get_xl_files().add_pivot_table(content);
}
}
if (xlsx_pivots_context_.is_connections())
{
std::wstringstream strm;
xlsx_pivots_context_.write_connections_to(strm);
output_document_->get_xl_files().set_connections( package::simple_element::create(L"connections.xml", strm.str()) );
}
} }
} }
...@@ -381,9 +428,8 @@ void xlsx_conversion_context::end_table() ...@@ -381,9 +428,8 @@ void xlsx_conversion_context::end_table()
get_table_context().serialize_hyperlinks (current_sheet().hyperlinks()); get_table_context().serialize_hyperlinks (current_sheet().hyperlinks());
get_table_context().serialize_ole_objects (current_sheet().ole_objects()); get_table_context().serialize_ole_objects (current_sheet().ole_objects());
get_table_context().dump_rels_hyperlinks (current_sheet().hyperlinks_rels()); get_table_context().dump_rels_hyperlinks (current_sheet().sheet_rels());
get_table_context().dump_rels_ole_objects (current_sheet().ole_objects_rels()); get_table_context().dump_rels_ole_objects (current_sheet().sheet_rels());
if (!get_drawing_context().empty()) if (!get_drawing_context().empty())
{ {
......
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#include "xlsx_comments_context.h" #include "xlsx_comments_context.h"
#include "xlsx_defined_names.h" #include "xlsx_defined_names.h"
#include "xlsx_table_metrics.h" #include "xlsx_table_metrics.h"
#include "xlsx_pivots_context.h"
#include "oox_chart_context.h" #include "oox_chart_context.h"
#include "mediaitems.h" #include "mediaitems.h"
...@@ -168,6 +169,7 @@ public: ...@@ -168,6 +169,7 @@ public:
num_format_context & get_num_format_context() { return num_format_context_; } num_format_context & get_num_format_context() { return num_format_context_; }
size_t get_default_cell_style() const { return default_style_; } size_t get_default_cell_style() const { return default_style_; }
xlsx_defined_names & get_xlsx_defined_names() { return xlsx_defined_names_; } xlsx_defined_names & get_xlsx_defined_names() { return xlsx_defined_names_; }
xlsx_pivots_context & get_pivots_context() { return xlsx_pivots_context_;}
xlsx_table_metrics & get_table_metrics(); xlsx_table_metrics & get_table_metrics();
xlsx_drawing_context & get_drawing_context(); xlsx_drawing_context & get_drawing_context();
xlsx_drawing_context_handle & get_drawing_context_handle(); xlsx_drawing_context_handle & get_drawing_context_handle();
...@@ -202,6 +204,7 @@ private: ...@@ -202,6 +204,7 @@ private:
xlsx_table_context xlsx_table_context_; xlsx_table_context xlsx_table_context_;
xlsx_text_context xlsx_text_context_; xlsx_text_context xlsx_text_context_;
math_context math_context_; math_context math_context_;
xlsx_pivots_context xlsx_pivots_context_;
xlsx_drawing_context_handle xlsx_drawing_context_handle_; xlsx_drawing_context_handle xlsx_drawing_context_handle_;
xlsx_comments_context_handle xlsx_comments_context_handle_; xlsx_comments_context_handle xlsx_comments_context_handle_;
}; };
......
...@@ -49,25 +49,24 @@ void office_spreadsheet::add_child_element( xml::sax * Reader, const std::wstrin ...@@ -49,25 +49,24 @@ void office_spreadsheet::add_child_element( xml::sax * Reader, const std::wstrin
{ {
if CP_CHECK_NAME(L"table", L"database-ranges") if CP_CHECK_NAME(L"table", L"database-ranges")
{ {
CP_CREATE_ELEMENT(table_database_ranges_); CP_CREATE_ELEMENT(database_ranges_);
}
else if CP_CHECK_NAME(L"table", L"named-expressions")
{
CP_CREATE_ELEMENT(named_expressions_);
} }
else if CP_CHECK_NAME(L"table", L"data-pilot-tables") else if CP_CHECK_NAME(L"table", L"data-pilot-tables")
{ {
CP_CREATE_ELEMENT(table_data_pilot_tables_); CP_CREATE_ELEMENT(data_pilot_tables_);
}
else if CP_CHECK_NAME(L"table", L"tracked-changes")
{
CP_CREATE_ELEMENT(tracked_changes_);
} }
else else
CP_CREATE_ELEMENT(content_); CP_CREATE_ELEMENT(content_);
} }
void office_spreadsheet::add_text(const std::wstring & Text)
{
// TODO : error
}
void office_spreadsheet::add_attributes( const xml::attributes_wc_ptr & Attributes )
{
}
void office_spreadsheet::docx_convert(oox::docx_conversion_context & Context) void office_spreadsheet::docx_convert(oox::docx_conversion_context & Context)
{ {
Context.start_office_text(); Context.start_office_text();
...@@ -81,20 +80,22 @@ void office_spreadsheet::docx_convert(oox::docx_conversion_context & Context) ...@@ -81,20 +80,22 @@ void office_spreadsheet::docx_convert(oox::docx_conversion_context & Context)
void office_spreadsheet::xlsx_convert(oox::xlsx_conversion_context & Context) void office_spreadsheet::xlsx_convert(oox::xlsx_conversion_context & Context)
{ {
Context.start_office_spreadsheet(this); Context.start_office_spreadsheet(this);
_CP_LOG << L"[info][xlsx] process spreadsheet (" << content_.size() << L" elmements)" << std::endl; _CP_LOG << L"[info][xlsx] process spreadsheet (" << content_.size() << L" tables)" << std::endl;
if (named_expressions_)
named_expressions_->xlsx_convert(Context);
if (database_ranges_)
database_ranges_->xlsx_convert(Context);
for (size_t i = 0; i < table_database_ranges_.size(); i++)
{
table_database_ranges_[i]->xlsx_convert(Context);
}
for (size_t i = 0; i < content_.size(); i++) for (size_t i = 0; i < content_.size(); i++)
{ {
content_[i]->xlsx_convert(Context); content_[i]->xlsx_convert(Context);
} }
for (size_t i = 0; i < table_data_pilot_tables_.size(); i++)
{ if (data_pilot_tables_)
table_data_pilot_tables_[i]->xlsx_convert(Context); data_pilot_tables_->xlsx_convert(Context);
}
Context.end_office_spreadsheet(); Context.end_office_spreadsheet();
} }
......
...@@ -41,7 +41,6 @@ ...@@ -41,7 +41,6 @@
namespace cpdoccore { namespace cpdoccore {
namespace odf_reader { namespace odf_reader {
// office:spreadsheet
class office_spreadsheet : public office_element_impl<office_spreadsheet> class office_spreadsheet : public office_element_impl<office_spreadsheet>
{ {
public: public:
...@@ -55,27 +54,29 @@ public: ...@@ -55,27 +54,29 @@ public:
virtual void xlsx_convert(oox::xlsx_conversion_context & Context); virtual void xlsx_convert(oox::xlsx_conversion_context & Context);
private: private:
virtual void add_attributes( const xml::attributes_wc_ptr & Attributes ); 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); virtual void add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name);
virtual void add_text(const std::wstring & Text);
public: public:
// TODO: office-text-content-prelude: office_element_ptr named_expressions_;
// TODO: office-forms office_element_ptr database_ranges_;
// TODO: text-decls office_element_ptr data_pilot_tables_;
// TODO: table-decls office_element_ptr tracked_changes_;
office_element_ptr_array table_database_ranges_;
office_element_ptr_array table_data_pilot_tables_;
office_element_ptr tracked_changes_;//??
office_element_ptr_array content_; office_element_ptr_array content_;
// TODO: text-page-sequence
// TODO: office-text-content-epilogue:
// TODO: table-functions
}; // table:calculation-settings
// table:consolidation
// table:content-validations
// table:dde-links
// table:label-ranges
// text:alphabetical-index-auto-mark-file
// text:ddeconnection-decls
// text:sequence-decls
// text:user-fielddecls
// text:variable-decls
};
CP_REGISTER_OFFICE_ELEMENT2(office_spreadsheet); CP_REGISTER_OFFICE_ELEMENT2(office_spreadsheet);
} }
......
...@@ -172,7 +172,7 @@ void table_table::add_child_element( xml::sax * Reader, const std::wstring & Ns, ...@@ -172,7 +172,7 @@ void table_table::add_child_element( xml::sax * Reader, const std::wstring & Ns,
CP_CREATE_ELEMENT(table_shapes_); CP_CREATE_ELEMENT(table_shapes_);
} }
else if ( CP_CHECK_NAME(L"table", L"named-expressions") || else if ( CP_CHECK_NAME(L"table", L"named-expressions") ||
CP_CHECK_NAME(L"table", L"named-range") ) CP_CHECK_NAME(L"table", L"named-range") ) //???
{ {
CP_CREATE_ELEMENT(table_named_); CP_CREATE_ELEMENT(table_named_);
} }
......
...@@ -51,7 +51,6 @@ ...@@ -51,7 +51,6 @@
namespace cpdoccore { namespace cpdoccore {
namespace odf_reader { namespace odf_reader {
// table:table-attlist
class table_table_attlist class table_table_attlist
{ {
public: public:
...@@ -75,7 +74,6 @@ public: ...@@ -75,7 +74,6 @@ public:
friend class table_table; friend class table_table;
}; };
// table:table-row-attlist
class table_table_row_attlist class table_table_row_attlist
{ {
public: public:
...@@ -88,7 +86,6 @@ public: ...@@ -88,7 +86,6 @@ public:
}; };
// table:table-cell-attlist
class table_table_cell_attlist class table_table_cell_attlist
{ {
public: public:
...@@ -105,7 +102,6 @@ public: ...@@ -105,7 +102,6 @@ public:
}; };
// table:table-cell-attlist-extra
class table_table_cell_attlist_extra class table_table_cell_attlist_extra
{ {
public: public:
...@@ -119,7 +115,6 @@ public: ...@@ -119,7 +115,6 @@ public:
}; };
// table-table-source-attlist
class table_table_source_attlist class table_table_source_attlist
{ {
public: public:
...@@ -130,7 +125,6 @@ public: ...@@ -130,7 +125,6 @@ public:
}; };
// table:linked-source-attlist
class table_linked_source_attlist class table_linked_source_attlist
{ {
public: public:
...@@ -144,7 +138,6 @@ public: ...@@ -144,7 +138,6 @@ public:
}; };
// table:table-source
class table_table_source : public office_element_impl<table_table_source> class table_table_source : public office_element_impl<table_table_source>
{ {
public: public:
...@@ -165,7 +158,6 @@ private: ...@@ -165,7 +158,6 @@ private:
CP_REGISTER_OFFICE_ELEMENT2(table_table_source); CP_REGISTER_OFFICE_ELEMENT2(table_table_source);
// table:columns
class table_columns class table_columns
{ {
public: public:
...@@ -180,7 +172,6 @@ public: ...@@ -180,7 +172,6 @@ public:
}; };
// table:columns-no-group
class table_columns_no_group: public office_element class table_columns_no_group: public office_element
{ {
public: public:
...@@ -212,7 +203,6 @@ public: ...@@ -212,7 +203,6 @@ public:
table_columns table_columns_2_; table_columns table_columns_2_;
}; };
// table:columns-and-groups
class table_columns_and_groups class table_columns_and_groups
{ {
public: public:
...@@ -230,7 +220,6 @@ public: ...@@ -230,7 +220,6 @@ public:
}; };
// table:table-column-attlist
class table_table_column_attlist class table_table_column_attlist
{ {
public: public:
...@@ -243,7 +232,6 @@ public: ...@@ -243,7 +232,6 @@ public:
}; };
// table:table-column
class table_table_column : public office_element_impl<table_table_column> class table_table_column : public office_element_impl<table_table_column>
{ {
public: public:
...@@ -266,10 +254,8 @@ public: ...@@ -266,10 +254,8 @@ public:
table_table_column_attlist table_table_column_attlist_; table_table_column_attlist table_table_column_attlist_;
}; };
CP_REGISTER_OFFICE_ELEMENT2(table_table_column); CP_REGISTER_OFFICE_ELEMENT2(table_table_column);
// table:table-columns
class table_table_columns : public office_element_impl<table_table_columns> class table_table_columns : public office_element_impl<table_table_columns>
{ {
public: public:
...@@ -291,11 +277,8 @@ public: ...@@ -291,11 +277,8 @@ public:
office_element_ptr_array table_table_column_; office_element_ptr_array table_table_column_;
}; };
CP_REGISTER_OFFICE_ELEMENT2(table_table_columns); CP_REGISTER_OFFICE_ELEMENT2(table_table_columns);
// table:table-header-columns
class table_table_header_columns : public office_element_impl<table_table_header_columns> class table_table_header_columns : public office_element_impl<table_table_header_columns>
{ {
public: public:
...@@ -318,10 +301,8 @@ public: ...@@ -318,10 +301,8 @@ public:
office_element_ptr_array table_table_column_; office_element_ptr_array table_table_column_;
}; };
CP_REGISTER_OFFICE_ELEMENT2(table_table_header_columns); CP_REGISTER_OFFICE_ELEMENT2(table_table_header_columns);
// table:table-column-group-attlist
class table_table_column_group_attlist class table_table_column_group_attlist
{ {
public: public:
...@@ -331,7 +312,6 @@ public: ...@@ -331,7 +312,6 @@ public:
}; };
// table:table-column-group
class table_table_column_group : public office_element_impl<table_table_column_group> class table_table_column_group : public office_element_impl<table_table_column_group>
{ {
public: public:
...@@ -358,10 +338,8 @@ public: ...@@ -358,10 +338,8 @@ public:
table_table_column_group_attlist table_table_column_group_attlist_; table_table_column_group_attlist table_table_column_group_attlist_;
table_columns_and_groups table_columns_and_groups_; table_columns_and_groups table_columns_and_groups_;
}; };
CP_REGISTER_OFFICE_ELEMENT2(table_table_column_group); CP_REGISTER_OFFICE_ELEMENT2(table_table_column_group);
// table:table-row
class table_table_row : public office_element_impl<table_table_row> class table_table_row : public office_element_impl<table_table_row>
{ {
public: public:
...@@ -387,10 +365,8 @@ public: ...@@ -387,10 +365,8 @@ public:
office_element_ptr_array content_; // table-table-cell or table-covered-table-cell office_element_ptr_array content_; // table-table-cell or table-covered-table-cell
}; };
CP_REGISTER_OFFICE_ELEMENT2(table_table_row); CP_REGISTER_OFFICE_ELEMENT2(table_table_row);
// table:table-cell-content
class table_table_cell_content class table_table_cell_content
{ {
public: public:
...@@ -407,8 +383,6 @@ public: ...@@ -407,8 +383,6 @@ public:
// TODO table-detective // TODO table-detective
}; };
// table:table-cell
class table_table_cell : public office_element_impl<table_table_cell> class table_table_cell : public office_element_impl<table_table_cell>
{ {
public: public:
...@@ -443,7 +417,6 @@ public: ...@@ -443,7 +417,6 @@ public:
CP_REGISTER_OFFICE_ELEMENT2(table_table_cell); CP_REGISTER_OFFICE_ELEMENT2(table_table_cell);
// table:covered-table-cell
class table_covered_table_cell : public office_element_impl<table_covered_table_cell> class table_covered_table_cell : public office_element_impl<table_covered_table_cell>
{ {
public: public:
...@@ -479,7 +452,6 @@ public: ...@@ -479,7 +452,6 @@ public:
CP_REGISTER_OFFICE_ELEMENT2(table_covered_table_cell); CP_REGISTER_OFFICE_ELEMENT2(table_covered_table_cell);
// table:table-rows
class table_table_rows : public office_element_impl<table_table_rows> class table_table_rows : public office_element_impl<table_table_rows>
{ {
public: public:
...@@ -507,10 +479,8 @@ public: ...@@ -507,10 +479,8 @@ public:
office_element_ptr_array table_table_row_; office_element_ptr_array table_table_row_;
}; };
CP_REGISTER_OFFICE_ELEMENT2(table_table_rows); CP_REGISTER_OFFICE_ELEMENT2(table_table_rows);
// table:table-header-rows
class table_table_header_rows : public office_element_impl<table_table_header_rows> class table_table_header_rows : public office_element_impl<table_table_header_rows>
{ {
public: public:
...@@ -536,10 +506,8 @@ public: ...@@ -536,10 +506,8 @@ public:
office_element_ptr_array table_table_row_; office_element_ptr_array table_table_row_;
}; };
CP_REGISTER_OFFICE_ELEMENT2(table_table_header_rows); CP_REGISTER_OFFICE_ELEMENT2(table_table_header_rows);
// table:rows
class table_rows class table_rows
{ {
public: public:
...@@ -556,7 +524,6 @@ public: ...@@ -556,7 +524,6 @@ public:
void remove_equals_empty(); void remove_equals_empty();
}; };
// table:rows-no-group
class table_rows_no_group : public office_element class table_rows_no_group : public office_element
{ {
public: public:
...@@ -591,7 +558,6 @@ public: ...@@ -591,7 +558,6 @@ public:
}; };
// table:rows-and-groups
class table_rows_and_groups class table_rows_and_groups
{ {
public: public:
...@@ -611,7 +577,6 @@ public: ...@@ -611,7 +577,6 @@ public:
}; };
// table:table-row-group-attlist
class table_table_row_group_attlist class table_table_row_group_attlist
{ {
public: public:
...@@ -621,7 +586,6 @@ public: ...@@ -621,7 +586,6 @@ public:
}; };
// table:table-row-group
class table_table_row_group : public office_element_impl<table_table_row_group> class table_table_row_group : public office_element_impl<table_table_row_group>
{ {
public: public:
...@@ -647,10 +611,8 @@ public: ...@@ -647,10 +611,8 @@ public:
table_rows_and_groups table_rows_and_groups_; table_rows_and_groups table_rows_and_groups_;
}; };
CP_REGISTER_OFFICE_ELEMENT2(table_table_row_group); CP_REGISTER_OFFICE_ELEMENT2(table_table_row_group);
// table:table
class table_table : public office_element_impl<table_table> class table_table : public office_element_impl<table_table>
{ {
public: public:
...@@ -685,10 +647,8 @@ public: ...@@ -685,10 +647,8 @@ public:
//table-scenario //table-scenario
//office-forms //office-forms
}; };
CP_REGISTER_OFFICE_ELEMENT2(table_table); CP_REGISTER_OFFICE_ELEMENT2(table_table);
// table:shapes
class table_shapes : public office_element_impl<table_shapes> class table_shapes : public office_element_impl<table_shapes>
{ {
public: public:
...@@ -710,7 +670,6 @@ private: ...@@ -710,7 +670,6 @@ private:
office_element_ptr_array content_; office_element_ptr_array content_;
}; };
CP_REGISTER_OFFICE_ELEMENT2(table_shapes); CP_REGISTER_OFFICE_ELEMENT2(table_shapes);
} }
......
...@@ -71,20 +71,39 @@ void table_data_pilot_table::add_attributes( const xml::attributes_wc_ptr & Attr ...@@ -71,20 +71,39 @@ void table_data_pilot_table::add_attributes( const xml::attributes_wc_ptr & Attr
CP_APPLY_ATTR(L"table:grand-total" , table_grand_total_); CP_APPLY_ATTR(L"table:grand-total" , table_grand_total_);
CP_APPLY_ATTR(L"table:identify-categories" , table_identify_categories_); 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:ignore-empty-rows" , table_ignore_empty_rows_);
CP_APPLY_ATTR(L"table:show-filterbutton" , table_show_filterbutton_); 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:show-target-range-address", table_show_target_range_address_);
} }
void table_data_pilot_table::add_child_element( xml::sax * Reader, const std::wstring & Ns, const std::wstring & Name) void table_data_pilot_table::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" == Name)
CP_CREATE_ELEMENT (fields_);
else
CP_CREATE_ELEMENT (source_);
} }
void table_data_pilot_table::xlsx_convert(oox::xlsx_conversion_context & Context) void table_data_pilot_table::xlsx_convert(oox::xlsx_conversion_context & Context)
{ {
for (size_t i = 0; i < content_.size(); i++) if (!source_) return;
Context.get_pivots_context().start_table();
source_->xlsx_convert(Context);
for (size_t i = 0; i < fields_.size(); i++)
{ {
content_[i]->xlsx_convert(Context); fields_[i]->xlsx_convert(Context);
}
int index_view = Context.get_pivots_context().end_table();
if (index_view > 0)
{
Context.current_sheet().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"));
} }
} }
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
...@@ -108,10 +127,14 @@ void table_data_pilot_field::add_child_element( xml::sax * Reader, const std::ws ...@@ -108,10 +127,14 @@ void table_data_pilot_field::add_child_element( xml::sax * Reader, const std::ws
} }
void table_data_pilot_field::xlsx_convert(oox::xlsx_conversion_context & Context) void table_data_pilot_field::xlsx_convert(oox::xlsx_conversion_context & Context)
{ {
Context.get_pivots_context().start_field();
for (size_t i = 0; i < content_.size(); i++) for (size_t i = 0; i < content_.size(); i++)
{ {
content_[i]->xlsx_convert(Context); content_[i]->xlsx_convert(Context);
} }
Context.get_pivots_context().end_field();
} }
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
const wchar_t * table_data_pilot_field_reference::ns = L"table"; const wchar_t * table_data_pilot_field_reference::ns = L"table";
...@@ -120,8 +143,8 @@ const wchar_t * table_data_pilot_field_reference::name = L"data-pilot-field-refe ...@@ -120,8 +143,8 @@ const wchar_t * table_data_pilot_field_reference::name = L"data-pilot-field-refe
void table_data_pilot_field_reference::add_attributes( const xml::attributes_wc_ptr & Attributes ) void table_data_pilot_field_reference::add_attributes( const xml::attributes_wc_ptr & Attributes )
{ {
CP_APPLY_ATTR(L"table:field-name" , table_field_name_); CP_APPLY_ATTR(L"table:field-name" , table_field_name_);
CP_APPLY_ATTR(L"table:member_name" , table_member_name_); CP_APPLY_ATTR(L"table:member-name" , table_member_name_);
CP_APPLY_ATTR(L"table:member_type" , table_member_type_); CP_APPLY_ATTR(L"table:member-type" , table_member_type_);
CP_APPLY_ATTR(L"table:type" , table_type_); CP_APPLY_ATTR(L"table:type" , table_type_);
} }
...@@ -166,7 +189,7 @@ void table_database_source_sql::add_attributes( const xml::attributes_wc_ptr & A ...@@ -166,7 +189,7 @@ void table_database_source_sql::add_attributes( const xml::attributes_wc_ptr & A
{ {
CP_APPLY_ATTR(L"table:database-name" , table_database_name_); CP_APPLY_ATTR(L"table:database-name" , table_database_name_);
CP_APPLY_ATTR(L"table:parse-sql-statement" , table_parse_sql_statement_); CP_APPLY_ATTR(L"table:parse-sql-statement" , table_parse_sql_statement_);
CP_APPLY_ATTR(L"table:sqlstatement" , table_sql_statement_); CP_APPLY_ATTR(L"table:sql-statement" , table_sql_statement_);
} }
void table_database_source_sql::xlsx_convert(oox::xlsx_conversion_context & Context) void table_database_source_sql::xlsx_convert(oox::xlsx_conversion_context & Context)
......
...@@ -94,10 +94,11 @@ private: ...@@ -94,10 +94,11 @@ private:
_CP_OPT(odf_types::grand_total)table_grand_total_; _CP_OPT(odf_types::grand_total)table_grand_total_;
_CP_OPT(odf_types::Bool) table_identify_categories_; _CP_OPT(odf_types::Bool) table_identify_categories_;
_CP_OPT(odf_types::Bool) table_ignore_empty_rows_; _CP_OPT(odf_types::Bool) table_ignore_empty_rows_;
_CP_OPT(odf_types::Bool) table_show_filterbutton_; _CP_OPT(odf_types::Bool) table_show_filter_button_;
_CP_OPT(odf_types::Bool) table_show_target_range_address_; _CP_OPT(odf_types::Bool) table_show_target_range_address_;
office_element_ptr_array content_; office_element_ptr source_;
office_element_ptr_array fields_;
}; };
CP_REGISTER_OFFICE_ELEMENT2(table_data_pilot_table); CP_REGISTER_OFFICE_ELEMENT2(table_data_pilot_table);
......
...@@ -718,6 +718,14 @@ ...@@ -718,6 +718,14 @@
RelativePath="..\src\docx\xlsx_package.h" RelativePath="..\src\docx\xlsx_package.h"
> >
</File> </File>
<File
RelativePath="..\src\docx\xlsx_pivots_context.cpp"
>
</File>
<File
RelativePath="..\src\docx\xlsx_pivots_context.h"
>
</File>
<File <File
RelativePath="..\src\docx\xlsx_row_spanned.h" RelativePath="..\src\docx\xlsx_row_spanned.h"
> >
......
...@@ -80,8 +80,10 @@ class content_types_file : public element ...@@ -80,8 +80,10 @@ class content_types_file : public element
{ {
public: public:
content_types_file(); content_types_file();
virtual void write(const std::wstring & RootPath); virtual void write(const std::wstring & RootPath);
content_type & get_content_type() { return content_type_; } content_type & get_content_type() { return content_type_; }
bool add_or_find_default(const std::wstring & extension); bool add_or_find_default(const std::wstring & extension);
void set_media(external_items & _Mediaitems); void set_media(external_items & _Mediaitems);
......
...@@ -184,10 +184,11 @@ void xl_files::write(const std::wstring & RootPath) ...@@ -184,10 +184,11 @@ void xl_files::write(const std::wstring & RootPath)
pivot_table_files_.set_main_document(get_main_document()); pivot_table_files_.set_main_document(get_main_document());
pivot_table_files_.write(path); pivot_table_files_.write(path);
} }
{
sheets_files_.set_rels(&rels_files_); sheets_files_.set_rels(&rels_files_);
sheets_files_.set_main_document( this->get_main_document() ); sheets_files_.set_main_document( this->get_main_document() );
sheets_files_.write(path); sheets_files_.write(path);
}
if (sharedStrings_) if (sharedStrings_)
{ {
......
...@@ -47,9 +47,6 @@ public: ...@@ -47,9 +47,6 @@ public:
xlsx_content_types_file(); xlsx_content_types_file();
}; };
//------------------------------------------------------------------------ //------------------------------------------------------------------------
class sheet_content;
typedef _CP_PTR(sheet_content) sheet_content_ptr;
class sheet_content : boost::noncopyable class sheet_content : boost::noncopyable
{ {
public: public:
...@@ -65,10 +62,8 @@ private: ...@@ -65,10 +62,8 @@ private:
std::wstringstream content_; std::wstringstream content_;
rels_file_ptr rels_; rels_file_ptr rels_;
}; };
typedef _CP_PTR(sheet_content) sheet_content_ptr;
//------------------------------------------------------------------------ //------------------------------------------------------------------------
class pivot_cache_content;
typedef _CP_PTR(pivot_cache_content) pivot_cache_content_ptr;
class pivot_cache_content : boost::noncopyable class pivot_cache_content : boost::noncopyable
{ {
public: public:
...@@ -88,10 +83,8 @@ private: ...@@ -88,10 +83,8 @@ private:
std::wstringstream definitions_; std::wstringstream definitions_;
rels_file_ptr definitions_rels_file_; rels_file_ptr definitions_rels_file_;
}; };
typedef _CP_PTR(pivot_cache_content) pivot_cache_content_ptr;
//------------------------------------------------------------------------ //------------------------------------------------------------------------
class pivot_table_content;
typedef _CP_PTR(pivot_table_content) pivot_table_content_ptr;
class pivot_table_content : boost::noncopyable class pivot_table_content : boost::noncopyable
{ {
public: public:
...@@ -108,6 +101,7 @@ private: ...@@ -108,6 +101,7 @@ private:
std::wstringstream content_; std::wstringstream content_;
rels_file_ptr rels_file_; rels_file_ptr rels_file_;
}; };
typedef _CP_PTR(pivot_table_content) pivot_table_content_ptr;
//------------------------------------------------------------------------ //------------------------------------------------------------------------
class sheets_files : public element class sheets_files : public element
{ {
......
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