Commit 0db05389 authored by Elen.Subbotina's avatar Elen.Subbotina Committed by Alexander Trofimov

git-svn-id:...

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@55061 954022d7-b5bf-4e40-9824-e11837661b57
parent 8b64d60b
...@@ -79,7 +79,7 @@ void odf_style_context::process_office(office_element_ptr root ) ...@@ -79,7 +79,7 @@ void odf_style_context::process_office(office_element_ptr root )
root->add_child_element(it->odf_style_); root->add_child_element(it->odf_style_);
} }
} }
std::wstring & odf_style_context::find_odf_style_name(int oox_id_style, const style_family family) std::wstring odf_style_context::find_odf_style_name(int oox_id_style, const style_family family)
{ {
for (std::list<odf_style_state>::iterator it = style_state_list_.begin(); it != style_state_list_.end(); it++) for (std::list<odf_style_state>::iterator it = style_state_list_.begin(); it != style_state_list_.end(); it++)
{ {
...@@ -92,9 +92,9 @@ std::wstring & odf_style_context::find_odf_style_name(int oox_id_style, const st ...@@ -92,9 +92,9 @@ std::wstring & odf_style_context::find_odf_style_name(int oox_id_style, const st
} }
} }
return std::wstring(); return L"";
} }
office_element_ptr & odf_style_context::find_odf_style(int oox_id_style, const style_family family) office_element_ptr odf_style_context::find_odf_style(int oox_id_style, const style_family family)
{ {
for (std::list<odf_style_state>::iterator it = style_state_list_.begin(); it != style_state_list_.end(); it++) for (std::list<odf_style_state>::iterator it = style_state_list_.begin(); it != style_state_list_.end(); it++)
{ {
...@@ -109,6 +109,18 @@ office_element_ptr & odf_style_context::find_odf_style(int oox_id_style, const s ...@@ -109,6 +109,18 @@ office_element_ptr & odf_style_context::find_odf_style(int oox_id_style, const s
} }
return office_element_ptr(); return office_element_ptr();
} }
office_element_ptr odf_style_context::find_odf_style_default(const style_family family)
{
for (std::list<odf_style_state>::iterator it = default_styles_.begin(); it != default_styles_.end(); it++)
{
if (it->odf_style_)
{
if (it->style_family_ == family)return it->get_office_element();
}
}
return office_element_ptr();
}
std::wstring odf_style_context::get_name_family(const style_family & family) std::wstring odf_style_context::get_name_family(const style_family & family)
{ {
switch(family.get_type()) switch(family.get_type())
......
...@@ -30,9 +30,12 @@ public: ...@@ -30,9 +30,12 @@ public:
void process_master(office_element_ptr root ); void process_master(office_element_ptr root );
void process_office(office_element_ptr root ); void process_office(office_element_ptr root );
void clear_defaults() {default_styles_.clear();}
void add_default(odf_style_state & state) {default_styles_.push_back(state);}
std::wstring & find_odf_style_name (int oox_id_style, const style_family family); std::wstring find_odf_style_name (int oox_id_style, const style_family family);
office_element_ptr & find_odf_style (int oox_id_style, const style_family family); office_element_ptr find_odf_style (int oox_id_style, const style_family family);
office_element_ptr find_odf_style_default (const style_family family);
//void start_cell(const std::wstring & formula, //void start_cell(const std::wstring & formula,
...@@ -96,6 +99,8 @@ private: ...@@ -96,6 +99,8 @@ private:
std::list<odf_style_state> style_state_list_; std::list<odf_style_state> style_state_list_;
std::list<odf_style_state> default_styles_;// ..
std::list<odf_style_state> master_state_list_; std::list<odf_style_state> master_state_list_;
std::wstring get_name_family(const style_family & family); std::wstring get_name_family(const style_family & family);
......
...@@ -18,9 +18,6 @@ odf_style_state::odf_style_state(odf_conversion_context & Context, office_elemen ...@@ -18,9 +18,6 @@ odf_style_state::odf_style_state(odf_conversion_context & Context, office_elemen
if (!style_)return; if (!style_)return;
style_->style_family_ = style_family_ = family; style_->style_family_ = style_family_ = family;
//set default
} }
office_element_ptr & odf_style_state::get_office_element() office_element_ptr & odf_style_state::get_office_element()
...@@ -55,7 +52,6 @@ void odf_style_state::set_root(bool val)// ...@@ -55,7 +52,6 @@ void odf_style_state::set_root(bool val)//
{ {
root_ = val; root_ = val;
} }
void odf_style_state::convert() void odf_style_state::convert()
{ {
if (odf_style_== NULL)return; if (odf_style_== NULL)return;
......
...@@ -34,24 +34,174 @@ void ods_conversion_context::start_sheet(std::wstring & name) ...@@ -34,24 +34,174 @@ void ods_conversion_context::start_sheet(std::wstring & name)
void ods_conversion_context::end_sheet() void ods_conversion_context::end_sheet()
{ {
ods_table_context_.end_table(); ods_table_context_.end_table();
styles_context().clear_defaults();
}
void ods_conversion_context::start_row(int _start_row, int repeated, bool _default)
{
if (_start_row > ods_table_context_.state().current_row()+1)
{
int repeated_default = _start_row - ods_table_context_.state().current_row()-1;
start_row(_start_row-repeated_default, repeated_default, true);
end_row();
}
/////////////////////////////////////////////////////////////////
office_element_ptr style_elm;
if ( _default)
{
style_elm = styles_context().find_odf_style_default(style_family::TableRow);
}
else
{
styles_context().create_style(L"",style_family::TableRow, true, false, -1);
style_elm = styles_context().last_state().get_office_element();
}
office_element_ptr row_elm;
create_element(L"table", L"table-row",row_elm,this);
ods_table_context_.state().add_row(row_elm, repeated, style_elm);
}
void ods_conversion_context::end_row()
{
//add default last cells
int repeated = 1024;
office_element_ptr default_cell_elm;
create_element(L"table", L"table-cell",default_cell_elm,this);
current_table().add_default_cell(default_cell_elm, repeated);
}
size_t getColAddressInv(const std::wstring & a_)
{
std::wstring a = a_;
::boost::algorithm::to_upper(a);
static const size_t r = (L'Z' - L'A' + 1);
size_t mul = 1;
bool f = true;
size_t res = 0;
BOOST_REVERSE_FOREACH(const wchar_t c, a)
{
size_t v = c - L'A';
if (f)
f = false;
else
v += 1;
res += v * mul;
mul *= r;
}
return res;
}
size_t getRowAdderssInv(const std::wstring & a_)
{
int sz = a_.length();
if (a_.length()>0)
{
return boost::lexical_cast<size_t>(a_)-1;
}
else
return 0;
} }
void splitCellAddress(const std::wstring & a_, std::wstring & col, std::wstring & row)
{
std::wstring a = a_;
std::reverse(a.begin(), a.end());
::boost::algorithm::replace_all(a, L"$", L"");
//::boost::algorithm::replace_all(a, L"'", L"");
::boost::algorithm::to_upper(a);
void ods_conversion_context::add_column(int start_column, int repeated, const std::wstring & style_name) BOOST_FOREACH(wchar_t c, a)
{
if (c >= L'0' && c <= L'9')
row +=c;
else
col += c;
}
std::reverse(col.begin(), col.end());
std::reverse(row.begin(), row.end());
}
void parsing_ref (const std::wstring & ref, int & col,int & row)
{
std::wstring strCol, strRow;
splitCellAddress(ref,strCol,strRow);
col = getColAddressInv(strCol)+1;
row = getRowAdderssInv(strRow)+1;
}
void ods_conversion_context::start_cell(std::wstring & ref, int xfd_style)
{
int col=0, row=0;
parsing_ref ( ref, col,row);
if (col > current_table().current_column()+1)
{
int repeated = col - current_table().current_column() -1;
office_element_ptr default_cell_elm;
create_element(L"table", L"table-cell",default_cell_elm,this);
current_table().add_default_cell(default_cell_elm, repeated);
}
office_element_ptr style_elm;
if ( xfd_style >=0)
{
style_elm = styles_context().find_odf_style(xfd_style, style_family::TableCell);
}
office_element_ptr cell_elm;
create_element(L"table", L"table-cell",cell_elm,this);
ods_table_context_.state().start_cell(cell_elm, style_elm);
}
void ods_conversion_context::start_columns()
{
}
void ods_conversion_context::end_columns()
{
//add default last column
add_column(ods_table_context_.state().columns_count()+1,1024,true);
}
void ods_conversion_context::start_rows()
{
}
void ods_conversion_context::end_rows()
{
//add default last row
start_row(ods_table_context_.state().current_row()+1,1024,true);
end_row();
}
void ods_conversion_context::add_column(int start_column, int repeated, bool _default)
{ {
if (start_column > ods_table_context_.state().columns_count()+1) if (start_column > ods_table_context_.state().columns_count()+1)
{ {
//default_columns
int repeated_default = start_column - ods_table_context_.state().columns_count()-1; int repeated_default = start_column - ods_table_context_.state().columns_count()-1;
office_element_ptr element_column_default; add_column(start_column-repeated_default,repeated_default,true);
create_element(L"table", L"table-column",element_column_default,this); }
/////////////////////////////////////////////////////////////////
ods_table_context_.add_column(element_column_default,repeated_default,L""); office_element_ptr style_elm;
if ( _default)
{
style_elm = styles_context().find_odf_style_default(style_family::TableColumn);
}
else
{
styles_context().create_style(L"",style_family::TableColumn, true, false, -1);
style_elm = styles_context().last_state().get_office_element();
} }
office_element_ptr element_column; office_element_ptr column_elm;
create_element(L"table", L"table-column",column_elm,this);
create_element(L"table", L"table-column",element_column,this); ods_table_context_.state().add_column(column_elm, repeated, style_elm);
ods_table_context_.add_column(element_column,repeated,style_name);
} }
......
...@@ -18,7 +18,17 @@ public: ...@@ -18,7 +18,17 @@ public:
void start_sheet(std::wstring & name); void start_sheet(std::wstring & name);
void end_sheet(); void end_sheet();
void add_column(int start_column, int repeated, const std::wstring & StyleName); void start_columns();
void add_column(int start_column, int repeated, bool _default = false);
void end_columns();
void start_rows();
void start_row(int _start_row, int repeated, bool _default = false);
void end_row();
void start_cell(std::wstring & ref, int xfd_style);
void end_cell(){}
void end_rows();
ods_table_context ods_table_context_; ods_table_context ods_table_context_;
......
...@@ -45,14 +45,8 @@ void ods_table_context::start_table(office_element_ptr & elm, std::wstring & nam ...@@ -45,14 +45,8 @@ void ods_table_context::start_table(office_element_ptr & elm, std::wstring & nam
void ods_table_context::end_table() void ods_table_context::end_table()
{ {
state().convert();
} }
void ods_table_context::add_column(office_element_ptr & elm_column, int repeated, const std::wstring & style_name)
{
state().add_column(elm_column, repeated,style_name);
}
} }
} }
\ No newline at end of file
...@@ -45,12 +45,8 @@ public: ...@@ -45,12 +45,8 @@ public:
// int current_row() const; // int current_row() const;
//void set_table_row_group(int count, bool collapsed, int level); //void set_table_row_group(int count, bool collapsed, int level);
// void start_row(const std::wstring & StyleName, const std::wstring & defaultCellStyleName);
// void non_empty_row(); // void non_empty_row();
// bool is_empty_row() const; // bool is_empty_row() const;
// void end_row();
void add_column(office_element_ptr & elm, int repeated, const std::wstring & StyleName);
// size_t depth() const { return table_state_stack_.size(); } // size_t depth() const { return table_state_stack_.size(); }
......
...@@ -5,8 +5,15 @@ ...@@ -5,8 +5,15 @@
#include "ods_conversion_context.h" #include "ods_conversion_context.h"
#include "table.h" #include "table.h"
#include "styles.h" #include "styles.h"
#include "style_table_properties.h"
#include "style_text_properties.h"
#include "style_paragraph_properties.h"
#include "style_graphic_properties.h"
namespace cpdoccore { namespace cpdoccore {
namespace odf { namespace odf {
...@@ -14,6 +21,8 @@ ods_table_state::ods_table_state(ods_conversion_context & Context, office_elemen ...@@ -14,6 +21,8 @@ ods_table_state::ods_table_state(ods_conversion_context & Context, office_elemen
{ {
office_table_ = elm; office_table_ = elm;
columns_count_=0; columns_count_=0;
current_table_row_ =0;
current_table_column_ =0;
} }
void ods_table_state::set_name(std::wstring name) void ods_table_state::set_name(std::wstring name)
...@@ -47,23 +56,28 @@ void ods_table_state::set_table_style(office_element_ptr & elm) ...@@ -47,23 +56,28 @@ void ods_table_state::set_table_style(office_element_ptr & elm)
} }
void ods_table_state::add_column(office_element_ptr & elm, int repeated, const std::wstring & style_name) void ods_table_state::add_column(office_element_ptr & elm, int repeated,office_element_ptr & style_elm)
{ {
office_table_->add_child_element(elm); office_table_->add_child_element(elm);
ods_column_state state = {elm, repeated,style_name}; std::wstring style_name;
odf::style* style = dynamic_cast<odf::style*>(style_elm.get());
if (style)style_name = style->style_name_;
ods_element_state state = {elm, repeated,style_name, style_elm};
columns_count_ += repeated; columns_count_ += repeated;
columns_.push_back(state); columns_.push_back(state);
///
table_table_column* column = dynamic_cast<table_table_column*>(columns_.back().elm.get()); table_table_column* column = dynamic_cast<table_table_column*>(columns_.back().elm.get());
if (column == NULL)return; if (column == NULL)return;
column->table_table_column_attlist_.table_style_name_ = style_ref(style_name); if (style_name.length()>0) column->table_table_column_attlist_.table_style_name_ = style_ref(style_name);
column->table_table_column_attlist_.table_number_columns_repeated_ = repeated; column->table_table_column_attlist_.table_number_columns_repeated_ = repeated;
} }
void ods_table_state::set_default_column_cell_style(std::wstring & style_name) void ods_table_state::set_column_default_cell_style(std::wstring & style_name)
{ {
table_table_column* column = dynamic_cast<table_table_column*>(columns_.back().elm.get()); table_table_column* column = dynamic_cast<table_table_column*>(columns_.back().elm.get());
if (column == NULL)return; if (column == NULL)return;
...@@ -71,12 +85,135 @@ void ods_table_state::set_default_column_cell_style(std::wstring & style_name) ...@@ -71,12 +85,135 @@ void ods_table_state::set_default_column_cell_style(std::wstring & style_name)
column->table_table_column_attlist_.table_default_cell_style_name_ = style_ref(style_name); column->table_table_column_attlist_.table_default_cell_style_name_ = style_ref(style_name);
} }
void ods_table_state::set_column_width(int width)//cm, pt ???
{
odf::style* style = dynamic_cast<odf::style*>(columns_.back().style_elm.get());
if (!style)return;
style_table_column_properties * column_properties = style->style_content_.get_style_table_column_properties();
if (column_properties == NULL)return; //error ????
column_properties->style_table_column_properties_attlist_.style_column_width_ = length(width/2.,length::cm);
}
void ods_table_state::set_column_optimal_width(bool val)
{
odf::style* style = dynamic_cast<odf::style*>(columns_.back().style_elm.get());
if (!style)return;
style_table_column_properties * column_properties = style->style_content_.get_style_table_column_properties();
if (column_properties == NULL)return; //error ????
column_properties->style_table_column_properties_attlist_.style_use_optimal_column_width_ = val;
}
unsigned int ods_table_state::columns_count() const unsigned int ods_table_state::columns_count() const
{ {
return columns_count_; return columns_count_;
} }
void ods_table_state::add_row(office_element_ptr & elm, int repeated,office_element_ptr & style_elm)
{
current_table_column_ = 0;
current_table_row_+=repeated;
office_table_->add_child_element(elm);
std::wstring style_name;
odf::style* style = dynamic_cast<odf::style*>(style_elm.get());
if (style)style_name = style->style_name_;
ods_element_state state = {elm, repeated,style_name, style_elm};
rows_.push_back(state);
table_table_row* row = dynamic_cast<table_table_row*>(rows_.back().elm.get());
if (row == NULL)return;
if (style_name.length()>0) row->table_table_row_attlist_.table_style_name_ = style_ref(style_name);
row->table_table_row_attlist_.table_number_rows_repeated_ = repeated;
}
void ods_table_state::set_row_hidden(bool Val)
{
table_table_row* row = dynamic_cast<table_table_row*>(rows_.back().elm.get());
if (row == NULL)return;
row->table_table_row_attlist_.table_visibility_ = table_visibility(table_visibility::Collapse);
}
void ods_table_state::set_row_optimal_height(bool val)
{
odf::style* style = dynamic_cast<odf::style*>(rows_.back().style_elm.get());
if (!style)return;
style_table_row_properties * row_properties = style->style_content_.get_style_table_row_properties();
if (row_properties == NULL)return; //error ????
row_properties->style_table_row_properties_attlist_.style_use_optimal_row_height_ = val;
}
void ods_table_state::set_row_height(double height)
{
odf::style* style = dynamic_cast<odf::style*>(rows_.back().style_elm.get());
if (!style)return;
style_table_row_properties * row_properties = style->style_content_.get_style_table_row_properties();
if (row_properties == NULL)return; //error ????
row_properties->style_table_row_properties_attlist_.style_row_height_ = length(height,length::pt);
}
int ods_table_state::current_column() const
{
return current_table_column_;
}
int ods_table_state::current_row() const
{
return current_table_row_;
}
void ods_table_state::set_row_default_cell_style(std::wstring & style_name)
{
table_table_row* row = dynamic_cast<table_table_row*>(rows_.back().elm.get());
if (row == NULL)return;
row->table_table_row_attlist_.table_default_cell_style_name_ = style_ref(style_name);
}
office_element_ptr & ods_table_state::current_row_element()
{
if (rows_.size()>0)
return rows_.back().elm;
else
{
}
}
void ods_table_state::start_cell(office_element_ptr & elm, office_element_ptr & style_elm)
{
current_row_element()->add_child_element(elm);
table_table_cell* cell = dynamic_cast<table_table_cell*>(elm.get());
if (cell == NULL)return;
odf::style* style = dynamic_cast<odf::style*>(rows_.back().style_elm.get());
if (style)
{
cell->table_table_cell_attlist_.table_style_name_= style->style_name_;
}
}
void ods_table_state::end_cell()
{
}
void ods_table_state::add_default_cell(office_element_ptr & elm, int repeated)
{
current_row_element()->add_child_element(elm);
table_table_cell* cell = dynamic_cast<table_table_cell*>(elm.get());
if (cell == NULL)return;
cell->table_table_cell_attlist_.table_number_columns_repeated_ = repeated;
}
} }
} }
...@@ -20,11 +20,13 @@ class ods_conversion_context; ...@@ -20,11 +20,13 @@ class ods_conversion_context;
class table_table; class table_table;
class style; class style;
struct ods_column_state struct ods_element_state
{ {
office_element_ptr elm; office_element_ptr elm;
int repeated; int repeated;
std::wstring style_name; std::wstring style_name;
office_element_ptr style_elm;
}; };
class ods_table_state class ods_table_state
...@@ -35,20 +37,26 @@ public: ...@@ -35,20 +37,26 @@ public:
void set_name(std::wstring); void set_name(std::wstring);
void set_table_style(office_element_ptr & style); void set_table_style(office_element_ptr & style);
// std::wstring current_style() const { return table_style_; } void add_column(office_element_ptr & elm, int repeated ,office_element_ptr & style);
void add_column(office_element_ptr & elm, int repeated, const std::wstring & style_name); void set_column_width(int width);
// void start_row(const std::wstring & StyleName, const std::wstring & defaultCellStyleName); void set_column_optimal_width(bool val);
// void non_empty_row(); void set_column_default_cell_style(std::wstring & style_name);
// bool is_empty_row() const;
// void end_row(); void add_row(office_element_ptr & elm, int repeated ,office_element_ptr & style);//const std::wstring & StyleName, const std::wstring & defaultCellStyleName);
void set_row_hidden(bool Val);
//void set_row_collapsed(bool Val);
void set_row_optimal_height(bool val);
void set_row_height(double height);
void set_row_default_cell_style(std::wstring & style_name);
// std::wstring current_row_style() const;
// std::wstring default_row_cell_style() const;
void set_default_column_cell_style(std::wstring & style_name);
//void set_table_row_group(int count, bool collapsed, int level); //void set_table_row_group(int count, bool collapsed, int level);
// void start_cell(size_t columnsSpanned, size_t rowsSpanned); //void start_cell(/*size_t columnsSpanned, size_t rowsSpanned*/);
// void end_cell(); void end_cell();
void add_default_cell(office_element_ptr & cell, int repeated);
void start_cell(office_element_ptr & elm ,office_element_ptr & style);
office_element_ptr & current_row_element();
// void start_covered_cell(); // void start_covered_cell();
// void end_covered_cell(); // void end_covered_cell();
...@@ -56,8 +64,8 @@ public: ...@@ -56,8 +64,8 @@ public:
// void set_current_cell_style_id(unsigned int xfId); // void set_current_cell_style_id(unsigned int xfId);
// int get_current_cell_style_id(); // int get_current_cell_style_id();
//int current_column() const; int current_column() const;
//int current_row() const; int current_row() const;
// unsigned int current_columns_spaned() const; // unsigned int current_columns_spaned() const;
// unsigned int current_rows_spanned(unsigned int Column) const; // unsigned int current_rows_spanned(unsigned int Column) const;
...@@ -99,12 +107,13 @@ private: ...@@ -99,12 +107,13 @@ private:
// std::vector<std::wstring> column_default_cell_style_name_; // std::vector<std::wstring> column_default_cell_style_name_;
// std::wstring row_default_cell_style_name_; // std::wstring row_default_cell_style_name_;
// std::wstring cell_style_; // std::wstring cell_style_;
//int current_table_column_; int current_table_column_;
//int current_table_row_; int current_table_row_;
// unsigned int columns_spanned_num_; // unsigned int columns_spanned_num_;
// std::wstring columns_spanned_style_; // std::wstring columns_spanned_style_;
// std::vector<xlsx_row_spanned> rows_spanned_; // std::vector<xlsx_row_spanned> rows_spanned_;
std::vector<ods_column_state> columns_; std::vector<ods_element_state> columns_;
std::vector<ods_element_state> rows_;
unsigned int columns_count_; unsigned int columns_count_;
// xlsx_merge_cells merge_cells_; // xlsx_merge_cells merge_cells_;
// xlsx_table_metrics xlsx_table_metrics_; // xlsx_table_metrics xlsx_table_metrics_;
......
...@@ -31,7 +31,7 @@ void table_table_attlist::serialize(CP_ATTR_NODE) ...@@ -31,7 +31,7 @@ void table_table_attlist::serialize(CP_ATTR_NODE)
void table_table_row_attlist::serialize(CP_ATTR_NODE) void table_table_row_attlist::serialize(CP_ATTR_NODE)
{ {
CP_XML_ATTR(L"table:number-rows-repeated", table_number_rows_repeated_); CP_XML_ATTR(L"table:number-rows-repeated", table_number_rows_repeated_);
CP_XML_ATTR(L"table:style-name", table_style_name_); CP_XML_ATTR_OPT(L"table:style-name", table_style_name_);
CP_XML_ATTR_OPT(L"table:default-cell-style-name", table_default_cell_style_name_); CP_XML_ATTR_OPT(L"table:default-cell-style-name", table_default_cell_style_name_);
CP_XML_ATTR_OPT(L"table:visibility", table_visibility_); CP_XML_ATTR_OPT(L"table:visibility", table_visibility_);
} }
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "style_paragraph_properties.h" #include "style_paragraph_properties.h"
#include "style_graphic_properties.h" #include "style_graphic_properties.h"
using namespace cpdoccore; using namespace cpdoccore;
namespace Oox2Odf namespace Oox2Odf
...@@ -80,7 +79,6 @@ void XlsxConverter::convert_sheets() ...@@ -80,7 +79,6 @@ void XlsxConverter::convert_sheets()
{ {
std::wstring name = string2std_string(pSheet->m_oName.get2()); std::wstring name = string2std_string(pSheet->m_oName.get2());
ods_context->start_sheet(name); ods_context->start_sheet(name);
convert(pWorksheet); convert(pWorksheet);
ods_context->end_sheet(); ods_context->end_sheet();
} }
...@@ -92,61 +90,168 @@ void XlsxConverter::convert_sheets() ...@@ -92,61 +90,168 @@ void XlsxConverter::convert_sheets()
} }
void XlsxConverter::convert(OOX::Spreadsheet::CWorksheet *oox_sheet) void XlsxConverter::convert(OOX::Spreadsheet::CWorksheet *oox_sheet)
{ {
// //
if (oox_sheet->m_oSheetFormatPr.IsInit()) if (oox_sheet->m_oSheetFormatPr.IsInit())
convert(oox_sheet->m_oSheetFormatPr.GetPointer()); convert(oox_sheet->m_oSheetFormatPr.GetPointer());
//if (oox_sheet->m_oSheetPr.IsInit())
// convert(oox_sheet->m_oSheetPr.GetPointer());
// //
if(oox_sheet->m_oCols.IsInit()) ods_context->start_columns();
{ for (long col = 0 ; oox_sheet->m_oCols.IsInit() && col < oox_sheet->m_oCols->m_arrItems.GetSize(); col++)
for (long col = 0 ; col < oox_sheet->m_oCols->m_arrItems.GetSize();col++)
{ {
convert(oox_sheet->m_oCols->m_arrItems[col]); convert(oox_sheet->m_oCols->m_arrItems[col]);
} }
ods_context->end_columns();
//
ods_context->start_rows();
for (long row = 0 ; oox_sheet->m_oSheetData.IsInit() && row < oox_sheet->m_oSheetData->m_arrItems.GetSize(); row++)
{
convert(oox_sheet->m_oSheetData->m_arrItems[row]);
} }
ods_context->end_rows();
}
void XlsxConverter::convert(OOX::Spreadsheet::CRow *oox_row)
{
int row_number = oox_row->m_oR.IsInit() ? oox_row->m_oR->GetValue() : -1;
bool _default = true;
if (oox_row->m_oHt.IsInit() || oox_row->m_oCustomFormat.IsInit()) _default = false;
ods_context->start_row(row_number,1,_default);
if (oox_row->m_oHidden.IsInit()) ods_context->current_table().set_row_hidden(true);
if (oox_row->m_oCollapsed.IsInit()) ods_context->current_table().set_row_hidden(true);
if (oox_row->m_oS.IsInit() && ( oox_row->m_oCustomFormat.IsInit() && oox_row->m_oCustomFormat->GetValue()==1))
{
int xfd_id = oox_row->m_oS->GetValue();
std::wstring style_cell_name = ods_context->styles_context().find_odf_style_name(xfd_id,odf::style_family::TableCell);
ods_context->current_table().set_row_default_cell_style(style_cell_name );
}
if (oox_row->m_oHt.IsInit() == true)
{
double height = oox_row->m_oHt->GetValue();
ods_context->current_table().set_row_height(height);
// !!!
}
if (oox_row->m_oCustomHeight.IsInit() && oox_row->m_oCustomHeight->GetValue() == 1)
{
ods_context->current_table().set_row_optimal_height(false);
}
for (long cell = 0 ; cell < oox_row->m_arrItems.GetSize();cell++)
{
convert(oox_row->m_arrItems[cell]);
}
ods_context->end_row();
}
void XlsxConverter::convert(OOX::Spreadsheet::CCell *oox_cell)
{
//nullable<SimpleTypes::CUnsignedDecimalNumber<>> m_oCellMetadata;
//nullable<SimpleTypes::COnOff<>> m_oShowPhonetic;
//nullable<SimpleTypes::Spreadsheet::CCellTypeType<>> m_oType;
//nullable<SimpleTypes::CUnsignedDecimalNumber<>> m_oValueMetadata;
std::wstring ref = oox_cell->m_oRef.IsInit() ? string2std_string(oox_cell->m_oRef.get()) : L"";
int ifx_style = oox_cell->m_oStyle.IsInit() ? oox_cell->m_oStyle->GetValue() : -1;
ods_context->start_cell(ref,ifx_style);
//nullable<CFormula> m_oFormula;
//nullable<CSi> m_oRichText;
//nullable<CText> m_oValue;
ods_context->end_cell();
} }
void XlsxConverter::convert(OOX::Spreadsheet::CCol *oox_column) void XlsxConverter::convert(OOX::Spreadsheet::CCol *oox_column)
{ {
//nullable<SimpleTypes::COnOff<>> m_oBestFit; if (oox_column == NULL)return;
//nullable<SimpleTypes::COnOff<>> m_oCollapsed;
//nullable<SimpleTypes::COnOff<>> m_oHidden;
//nullable<SimpleTypes::CUnsignedDecimalNumber<>> m_oOutlineLevel;
//nullable<SimpleTypes::COnOff<>> m_oPhonetic;
int start_column = oox_column->m_oMin.IsInit() ? oox_column->m_oMin->GetValue() : 0 ; int start_column = oox_column->m_oMin.IsInit() ? oox_column->m_oMin->GetValue() : 0 ;
int repeated = (oox_column->m_oMax.IsInit() ? oox_column->m_oMax->GetValue() : 0) - int repeated = (oox_column->m_oMax.IsInit() ? oox_column->m_oMax->GetValue() : 0) -
(oox_column->m_oMin.IsInit() ? oox_column->m_oMin->GetValue() : 0) + 1; (oox_column->m_oMin.IsInit() ? oox_column->m_oMin->GetValue() : 0) + 1;
int oox_style_id = -1; ods_context->add_column(start_column, repeated);
ods_context->styles_context().create_style(L"",odf::style_family::TableColumn, true, false, oox_style_id); double width = oox_column->m_oWidth.IsInit() ? oox_column->m_oWidth->GetValue() : -1;
odf::style* style = dynamic_cast<odf::style*>(ods_context->styles_context().last_state().get_office_element().get()); if (width < 0 || (oox_column->m_oBestFit.IsInit() && oox_column->m_oBestFit->GetValue() == 1))
if (!style)return; {
ods_context->current_table().set_column_optimal_width(true);
odf::style_table_column_properties * column_properties = style->style_content_.get_style_table_column_properties(); }
if (column_properties == NULL)return; //error ???? else if (oox_column->m_oCustomWidth.IsInit() == false ||
(oox_column->m_oCustomWidth.IsInit() == true && oox_column->m_oCustomWidth->GetValue() == 1))
double width = oox_column->m_oWidth.IsInit() ? oox_column->m_oWidth->GetValue() : 0;
if (width < 1 || (oox_column->m_oBestFit.IsInit() && oox_column->m_oBestFit->GetValue()==true))
column_properties->style_table_column_properties_attlist_.style_use_optimal_column_width_ = true;
else if (oox_column->m_oCustomWidth.IsInit() == false || (oox_column->m_oCustomWidth.IsInit() && oox_column->m_oCustomWidth->GetValue()==true))
{ {
column_properties->style_table_column_properties_attlist_.style_column_width_ = odf::length(width/2.,odf::length::cm); //_ ods_context->current_table().set_column_width(width);
// !!! ods_context->current_table().set_column_optimal_width(false);
// !!!
//???
} }
ods_context->add_column(start_column, repeated, style->style_name_);
if (oox_column->m_oStyle.IsInit()) if (oox_column->m_oStyle.IsInit())
{ {
int xfd_id = oox_column->m_oStyle->GetValue();// cells - int xfd_id = oox_column->m_oStyle->GetValue();
std::wstring style_cell_name = ods_context->styles_context().find_odf_style_name(xfd_id,odf::style_family::TableCell); std::wstring style_cell_name = ods_context->styles_context().find_odf_style_name(xfd_id,odf::style_family::TableCell);
ods_context->current_table().set_column_default_cell_style(style_cell_name );
ods_context->current_table().set_default_column_cell_style(style_cell_name ); }
else
{
//
//???
} }
} }
void XlsxConverter::convert(OOX::Spreadsheet::CSheetFormatPr *oox_sheet_format) void XlsxConverter::convert(OOX::Spreadsheet::CSheetFormatPr *oox_sheet_format)
{ {
//nullable<SimpleTypes::CUnsignedDecimalNumber<>> m_oBaseColWidth;
//nullable<SimpleTypes::COnOff<>> m_oCustomHeight;
//nullable<SimpleTypes::CDouble> m_oDefaultColWidth;
//nullable<SimpleTypes::CDouble> m_oDefaultRowHeight;
//nullable<SimpleTypes::CUnsignedDecimalNumber<>> m_oOutlineLevelCol;
//nullable<SimpleTypes::CUnsignedDecimalNumber<>> m_oOutlineLevelRow;
//nullable<SimpleTypes::COnOff<>> m_oThickBottom;
//nullable<SimpleTypes::COnOff<>> m_oThickTop;
//nullable<SimpleTypes::COnOff<>> m_oZeroHeight;
// :(
if (oox_sheet_format->m_oDefaultColWidth.IsInit())
{
ods_context->styles_context().create_style(L"",odf::style_family::TableColumn, true, false, -1);
{
double width = oox_sheet_format->m_oDefaultColWidth->GetValue();
odf::style* style = dynamic_cast<odf::style*>(ods_context->styles_context().last_state().get_office_element().get());
if (style)
{
odf::style_table_column_properties * column_properties = style->style_content_.get_style_table_column_properties();
if (column_properties)
column_properties->style_table_column_properties_attlist_.style_column_width_ = odf::length(width/2.,odf::length::cm);
}
}
ods_context->styles_context().add_default(ods_context->styles_context().last_state());
}
if (oox_sheet_format->m_oDefaultRowHeight.IsInit())
{
ods_context->styles_context().create_style(L"",odf::style_family::TableRow, true, false, -1);
{
double height = oox_sheet_format->m_oDefaultRowHeight->GetValue();
odf::style* style = dynamic_cast<odf::style*>(ods_context->styles_context().last_state().get_office_element().get());
if (style)
{
odf::style_table_row_properties * row_properties = style->style_content_.get_style_table_row_properties();
if (row_properties)
row_properties->style_table_row_properties_attlist_.style_row_height_ = odf::length(height,odf::length::pt);
row_properties->style_table_row_properties_attlist_.style_use_optimal_row_height_ = true; //???? c
}
}
ods_context->styles_context().add_default(ods_context->styles_context().last_state());
}
} }
void XlsxConverter::convert_styles() void XlsxConverter::convert_styles()
{ {
...@@ -234,6 +339,8 @@ void XlsxConverter::convert(double oox_font_size, _CP_OPT(odf::font_size) & odf ...@@ -234,6 +339,8 @@ void XlsxConverter::convert(double oox_font_size, _CP_OPT(odf::font_size) & odf
} }
void XlsxConverter::convert(double oox_size, _CP_OPT(odf::length) & odf_size) void XlsxConverter::convert(double oox_size, _CP_OPT(odf::length) & odf_size)
{ {
// oox_size
//???
odf_size = odf::length(oox_size, odf::length::pt); odf_size = odf::length(oox_size, odf::length::pt);
} }
void XlsxConverter::convert(OOX::Spreadsheet::CFill * fill, odf::office_element_ptr & odf_style_) void XlsxConverter::convert(OOX::Spreadsheet::CFill * fill, odf::office_element_ptr & odf_style_)
...@@ -307,8 +414,8 @@ void XlsxConverter::convert(OOX::Spreadsheet::CColor *color, _CP_OPT(odf::color) ...@@ -307,8 +414,8 @@ void XlsxConverter::convert(OOX::Spreadsheet::CColor *color, _CP_OPT(odf::color)
unsigned char ucA=0, ucR=0, ucG=0, ucB=0; unsigned char ucA=0, ucR=0, ucG=0, ucB=0;
bool res=false; bool res=false;
// CColorMapping !!! //???
switch(theme_ind) switch(theme_ind)// CColorMapping !!!
{ {
case SimpleTypes::themecolorLight1: case SimpleTypes::themecolorLight1:
res=xlsx_theme->m_oThemeElements.m_oClrScheme.m_oLt1.tryGetRgb(ucR, ucG, ucB, ucA); break; res=xlsx_theme->m_oThemeElements.m_oClrScheme.m_oLt1.tryGetRgb(ucR, ucG, ucB, ucA); break;
......
...@@ -53,8 +53,13 @@ namespace Oox2Odf ...@@ -53,8 +53,13 @@ namespace Oox2Odf
void convert_styles(); void convert_styles();
void convert(OOX::Spreadsheet::CWorksheet *oox_sheet); void convert(OOX::Spreadsheet::CWorksheet *oox_sheet);
void convert(OOX::Spreadsheet::CCol *oox_column); void convert(OOX::Spreadsheet::CCol *oox_column);
void convert(OOX::Spreadsheet::CRow *oox_row);
void convert(OOX::Spreadsheet::CCell *oox_cell);
void convert(OOX::Spreadsheet::CSheetFormatPr *oox_sheet_format); void convert(OOX::Spreadsheet::CSheetFormatPr *oox_sheet_format);
//void convert(OOX::Spreadsheet::CSheetPr *oox_sheet_format);
void convert(OOX::Spreadsheet::CFill * fill, odf::office_element_ptr & odf_style_); void convert(OOX::Spreadsheet::CFill * fill, odf::office_element_ptr & odf_style_);
void convert(OOX::Spreadsheet::CFont * font, odf::office_element_ptr & odf_style_); void convert(OOX::Spreadsheet::CFont * font, odf::office_element_ptr & odf_style_);
......
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