Commit 06b3b7dc authored by Elen.Subbotina's avatar Elen.Subbotina Committed by Alexander Trofimov

типы данных (все - проценты, числа, даты ...)

форматирование типов данных 

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@55321 954022d7-b5bf-4e40-9824-e11837661b57
parent afbb4861
......@@ -301,13 +301,21 @@ void common_value_and_type_attlist::apply_from(const common_value_and_type_attli
}
void common_value_and_type_attlist::serialize(CP_ATTR_NODE)
{
CP_XML_ATTR_OPT(L"office:value-type", office_value_type_);
CP_XML_ATTR_OPT(L"office:value", office_value_);
if (office_value_)
{
CP_XML_ATTR_OPT(L"office:currency", office_currency_);
}
CP_XML_ATTR_OPT(L"office:date-value", office_date_value_);
CP_XML_ATTR_OPT(L"office:time-value", office_time_value_);
CP_XML_ATTR_OPT(L"office:boolean-value", office_boolean_value_);
CP_XML_ATTR_OPT(L"office:string-value", office_string_value_);
if (office_string_value_ || office_boolean_value_|| office_time_value_ || office_date_value_ || office_value_)
{
CP_XML_ATTR_OPT(L"office:value-type", office_value_type_);
//todooo .. .. ???
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////
......
......@@ -5,7 +5,8 @@
#include "odfattributes.h"
namespace cpdoccore { namespace odf {
namespace cpdoccore {
namespace odf {
class office_value_type
{
......
......@@ -590,28 +590,32 @@ void table_table_cell::xlsx_convert(oox::xlsx_conversion_context & Context)
std::wstring number_val = L"";
_CP_OPT(bool) bool_val;
int odf_value_type=0;
int odf_value_type = office_value_type::Custom;
if (table_table_cell_attlist_.common_value_and_type_attlist_)
{
const common_value_and_type_attlist & attr = *table_table_cell_attlist_.common_value_and_type_attlist_;
if (attr.office_value_type_)
odf_value_type = attr.office_value_type_->get_type();
if (attr.office_value_type_->get_type() == office_value_type::Float)
if ((odf_value_type == office_value_type::Float) ||
(odf_value_type == office_value_type::Custom && attr.office_value_))
{
t_val = XlsxCellType::n;
number_val = attr.office_value_.get_value_or(L"");
}
else if (attr.office_value_type_->get_type() == office_value_type::Percentage)
else if (odf_value_type == office_value_type::Percentage)
{
t_val = XlsxCellType::n;
number_val = attr.office_value_.get_value_or(L"");
}
else if (attr.office_value_type_->get_type() == office_value_type::Currency)
else if (odf_value_type == office_value_type::Currency)
{
t_val = XlsxCellType::n;
number_val = attr.office_value_.get_value_or(L"");
}
else if (attr.office_value_type_->get_type() == office_value_type::Date)
else if ((odf_value_type == office_value_type::Date) ||
(odf_value_type == office_value_type::Custom && attr.office_date_value_))
{
t_val = XlsxCellType::n;
if (attr.office_date_value_)
......@@ -623,7 +627,8 @@ void table_table_cell::xlsx_convert(oox::xlsx_conversion_context & Context)
}
}
}
else if (attr.office_value_type_->get_type() == office_value_type::Time)
else if ((odf_value_type == office_value_type::Time) ||
(odf_value_type == office_value_type::Custom && attr.office_time_value_))
{
t_val = XlsxCellType::n;
if (attr.office_time_value_)
......@@ -637,15 +642,17 @@ void table_table_cell::xlsx_convert(oox::xlsx_conversion_context & Context)
}
}
}
else if (attr.office_value_type_->get_type() == office_value_type::Boolean)
else if ((odf_value_type == office_value_type::Boolean) ||
(odf_value_type == office_value_type::Custom && attr.office_boolean_value_))
{
t_val = XlsxCellType::b;
if (attr.office_boolean_value_)
bool_val = oox::parseBoolVal(attr.office_boolean_value_.get());
}
else if (attr.office_value_type_->get_type() == office_value_type::String)
else if ((odf_value_type == office_value_type::String) ||
(odf_value_type == office_value_type::Custom && attr.office_date_value_))
{
t_val = XlsxCellType::s;
t_val = XlsxCellType::s;//
}
}
......
......@@ -1002,6 +1002,22 @@
RelativePath=".\OdfFormat\header_footer.h"
>
</File>
<File
RelativePath=".\OdfFormat\number_style.cpp"
>
</File>
<File
RelativePath=".\OdfFormat\number_style.h"
>
</File>
<File
RelativePath=".\OdfFormat\odf_number_styles_context.cpp"
>
</File>
<File
RelativePath=".\OdfFormat\odf_number_styles_context.h"
>
</File>
<File
RelativePath=".\OdfFormat\odf_style_context.cpp"
>
......
#include "precompiled_cpodf.h"
#include <boost/foreach.hpp>
#include <cpdoccore/xml/simple_xml_writer.h>
#include <cpdoccore/xml/xmlchar.h>
#include <cpdoccore/xml/utils.h>
#include <cpdoccore/xml/serialize.h>
#include <cpdoccore/xml/attributes.h>
#include <cpdoccore/CPColorUtils.h>
#include "number_style.h"
#include "paragraph_elements.h"
#include "style_text_properties.h"
#include "style_map.h"
namespace cpdoccore {
namespace odf {
std::wstring number_style_base::get_style_name() const
{
if (common_data_style_attlist_.style_name_)
return common_data_style_attlist_.style_name_->style_name();
else
return L"";
}
void number_style_base::set_style_name(std::wstring & name)
{
common_data_style_attlist_.style_name_ = style_ref(name);
}
void number_style_base::serialize(std::wostream & strm)
{
if (style_text_properties_)
style_text_properties_->serialize(strm);
BOOST_FOREACH(office_element_ptr & elm, style_map_)
{
elm->serialize(strm);
}
BOOST_FOREACH(office_element_ptr & elm, content_)
{
elm->serialize(strm);
}
}
void number_style_base::serialize(CP_ATTR_NODE)
{
common_data_style_attlist_.serialize(CP_GET_XML_NODE());
}
void number_date_style::serialize(std::wostream & strm)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE_SIMPLE()
{
CP_XML_ATTR_OPT(L"number:automatic-order", number_automatic_order_);
number_style_base::serialize(CP_GET_XML_NODE()); //attr
number_style_base::serialize(CP_XML_STREAM()); //nodes
}
}
}
void number_time_style::serialize(std::wostream & strm)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE_SIMPLE()
{
CP_XML_ATTR_OPT(L"number:automatic-order", number_automatic_order_);
number_style_base::serialize(CP_GET_XML_NODE()); //attr
number_style_base::serialize(CP_XML_STREAM()); //nodes
}
}
}
void number_style_base::create_child_element( const ::std::wstring & Ns, const ::std::wstring & Name)
{
if CP_CHECK_NAME(L"style", L"text-properties")
{
CP_CREATE_ELEMENT(style_text_properties_);
}
else if CP_CHECK_NAME(L"style", L"map")
{
CP_CREATE_ELEMENT(style_map_);
}
else
{
CP_CREATE_ELEMENT(content_);
}
}
void number_style_base::add_child_element(office_element_ptr & child_element)
{
ElementType type = child_element->get_type();
if (type == typeStyleTextProperties)
{
style_text_properties_ = child_element;
}
else if (type == typeStyleMap)
{
style_map_.push_back(child_element);
}
else
content_.push_back(child_element);
}
// number:number-style
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * number_number_style::ns = L"number";
const wchar_t * number_number_style::name = L"number-style";
void number_number_style::serialize(std::wostream & strm)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE_SIMPLE()
{
number_style_base::serialize(CP_GET_XML_NODE()); //attr
number_style_base::serialize(CP_XML_STREAM()); //nodes
}
}
}
// number:text
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * number_text::ns = L"number";
const wchar_t * number_text::name = L"text";
void number_text::serialize(std::wostream & strm)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE_SIMPLE()
{
BOOST_FOREACH(office_element_ptr & elm, text_)
{
elm->serialize(CP_XML_STREAM());
}
}
}
}
void number_text::add_text(const std::wstring & Text)
{
office_element_ptr elm = text_text::create(Text) ;
text_.push_back( elm );
}
// number:embedded-text
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * number_embedded_text::ns = L"number";
const wchar_t * number_embedded_text::name = L"embedded-text";
void number_embedded_text::serialize(std::wostream & strm)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE_SIMPLE()
{
CP_XML_ATTR_OPT(L"number:position", number_position_);
BOOST_FOREACH(office_element_ptr & elm, text_)
{
elm->serialize(CP_XML_STREAM());
}
}
}
}
void number_embedded_text::add_text(const std::wstring & Text)
{
office_element_ptr elm = text_text::create(Text) ;
text_.push_back( elm );
}
// number:number
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * number_number::ns = L"number";
const wchar_t * number_number::name = L"number";
void number_number::serialize(std::wostream & strm)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE_SIMPLE()
{
CP_XML_ATTR_OPT(L"number:decimal-replacement", number_decimal_replacement_);
CP_XML_ATTR_OPT(L"number:display-factor", number_display_factor_);
CP_XML_ATTR_OPT(L"number:decimal-places", number_decimal_places_);
CP_XML_ATTR_OPT(L"number:min-integer-digits", number_min_integer_digits_);
CP_XML_ATTR_OPT(L"number:grouping", number_grouping_);
BOOST_FOREACH(office_element_ptr & elm, number_embedded_text_)
{
elm->serialize(CP_XML_STREAM());
}
}
}
}
void number_number::create_child_element( const ::std::wstring & Ns, const ::std::wstring & Name)
{
if CP_CHECK_NAME(L"number", L"embedded-text")
{
CP_CREATE_ELEMENT(number_embedded_text_);
}
else
CP_NOT_APPLICABLE_ELM();
}
void number_number::add_child_element(office_element_ptr & child)
{
ElementType type = child->get_type();
if (type == typeNumberEmbeddedText)
{
number_embedded_text_.push_back(child);
}
else
{std::wstringstream str; str <<L"Non add child in "; str << ns; str << L":"; str <<name; _CP_LOG(error) << str.str();}
}
// number:scientific-number
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * number_scientific_number::ns = L"number";
const wchar_t * number_scientific_number::name = L"scientific-number";
void number_scientific_number::serialize(std::wostream & strm)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE_SIMPLE()
{
CP_XML_ATTR_OPT(L"number:min-exponent-digits", number_min_exponent_digits_);
CP_XML_ATTR_OPT(L"number:decimal-places", number_decimal_places_);
CP_XML_ATTR_OPT(L"number:min-integer-digits", number_min_integer_digits_);
CP_XML_ATTR_OPT(L"number:grouping", number_grouping_);
}
}
}
// number:currency-symbol
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * number_currency_symbol::ns = L"number";
const wchar_t * number_currency_symbol::name = L"currency-symbol";
void number_currency_symbol::serialize(std::wostream & strm)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE_SIMPLE()
{
CP_XML_ATTR_OPT(L"number:language", number_language_);
CP_XML_ATTR_OPT(L"number:country", number_country_);
for (long i=0; i < text_.size(); i++)
CP_XML_STREAM() << text_[i];
}
}
}
void number_currency_symbol::add_text(const std::wstring & Text)
{
text_.push_back(Text);
}
//void number_currency_symbol::xlsx_convert(oox::xlsx_conversion_context & Context)
//{
// std::wostream & strm = Context.get_num_format_context().output();
// strm << xml::utils::replace_text_to_xml(L"\"");
// BOOST_FOREACH(const std::wstring & t, text_)
// {
// strm << xml::utils::replace_text_to_xml(t);
// }
// strm << xml::utils::replace_text_to_xml(L"\"");
//}
// number:currency-style
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * number_currency_style::ns = L"number";
const wchar_t * number_currency_style::name = L"currency-style";
void number_currency_style::serialize(std::wostream & strm)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE_SIMPLE()
{
number_style_base::serialize(CP_GET_XML_NODE()); //attr
number_style_base::serialize(CP_XML_STREAM()); //nodes
}
}
}
// number:text-content
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * number_text_content::ns = L"number";
const wchar_t * number_text_content::name = L"text-content";
void number_text_content::serialize(std::wostream & strm)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE_SIMPLE()
{
BOOST_FOREACH(office_element_ptr & elm, text_)
{
elm->serialize(CP_XML_STREAM());
}
}
}
}
void number_text_content::add_text(const std::wstring & Text)
{
office_element_ptr elm = text_text::create(Text) ;
text_.push_back( elm );
}
// number:text-style
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * number_text_style::ns = L"number";
const wchar_t * number_text_style::name = L"text-style";
void number_text_style::serialize(std::wostream & strm)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE_SIMPLE()
{
number_style_base::serialize(CP_GET_XML_NODE()); //attr
number_style_base::serialize(CP_XML_STREAM()); //nodes
}
}
}
// number:percentage-style
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * number_percentage_style::ns = L"number";
const wchar_t * number_percentage_style::name = L"percentage-style";
void number_percentage_style::serialize(std::wostream & strm)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE_SIMPLE()
{
number_style_base::serialize(CP_GET_XML_NODE()); //attr
number_style_base::serialize(CP_XML_STREAM()); //nodes
}
}
}
//////////////////////////////
namespace
{
void format_number_number(
std::wostream & strm,
bool number_grouping_,
int number_min_integer_digits_,
int number_decimal_places_
)
{
if (number_grouping_)
{
if (number_min_integer_digits_ >= 4)
strm << std::wstring( number_min_integer_digits_ - 3, L'0');
else
strm << L'#';
strm << L',';
strm << std::wstring( (std::max)(0, 3 - number_min_integer_digits_), L'#');
strm << std::wstring( (std::min)(3, number_min_integer_digits_), L'0');
}
else
{
if (number_min_integer_digits_ > 0)
strm << std::wstring( number_min_integer_digits_, L'0');
else
strm << L"#";
}
if (number_decimal_places_)
{
strm << L".";
strm << std::wstring(number_decimal_places_, L'0');
}
}
}
//void number_number::xlsx_convert(oox::xlsx_conversion_context & Context)
//{
// std::wostream & strm = Context.get_num_format_context().output();
//
// format_number_number(
// strm,
// number_grouping_.get_value_or(false),
// number_min_integer_digits_.get_value_or(0),
// number_decimal_places_.get_value_or(0)
// );
//}
// number:day
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * number_day::ns = L"number";
const wchar_t * number_day::name = L"day";
void number_day::serialize(std::wostream & strm)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE_SIMPLE()
{
CP_XML_ATTR_OPT(L"number:style", number_style_);
CP_XML_ATTR_OPT(L"number:calendar", number_calendar_);
}
}
}
//void number_day::xlsx_convert(oox::xlsx_conversion_context & Context)
//{
// std::wostream & strm = Context.get_num_format_context().output();
// if (number_style_.get_value_or(L"short") == L"long")
// {
// strm << L"DD";
// }
// else
// {
// strm << L"D";
// }
//}
// number:day-of-week
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * number_day_of_week::ns = L"number";
const wchar_t * number_day_of_week::name = L"day-of-week";
void number_day_of_week::serialize(std::wostream & strm)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE_SIMPLE()
{
CP_XML_ATTR_OPT(L"number:style", number_style_);
CP_XML_ATTR_OPT(L"number:calendar", number_calendar_);
}
}
}
//
//void number_day_of_week::xlsx_convert(oox::xlsx_conversion_context & Context)
//{
// std::wostream & strm = Context.get_num_format_context().output();
// if (number_style_.get_value_or(L"short") == L"long")
// {
// strm << L"DDDD";
// }
// else
// {
// strm << L"DDD";
// }
//}
// number:quarter
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * number_quarter::ns = L"number";
const wchar_t * number_quarter::name = L"quarter";
void number_quarter::serialize(std::wostream & strm)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE_SIMPLE()
{
CP_XML_ATTR_OPT(L"number:style", number_style_);
CP_XML_ATTR_OPT(L"number:calendar", number_calendar_);
}
}
}
//void number_quarter::xlsx_convert(oox::xlsx_conversion_context & Context)
//{
// std::wostream & strm = Context.get_num_format_context().output();
// if (number_style_.get_value_or(L"short") == L"long")
// {
// // TODO: ??
// strm << L"";
// }
// else
// {
// // TODO: ??
// strm << L"";
// }
//}
// number:month
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * number_month::ns = L"number";
const wchar_t * number_month::name = L"month";
void number_month::serialize(std::wostream & strm)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE_SIMPLE()
{
CP_XML_ATTR_OPT(L"number:textual", number_textual_);
CP_XML_ATTR_OPT(L"number:possessive-form", number_possessive_form_);
CP_XML_ATTR_OPT(L"number:style", number_style_);
CP_XML_ATTR_OPT(L"number:calendar", number_calendar_);
}
}
}
//void number_month::xlsx_convert(oox::xlsx_conversion_context & Context)
//{
// std::wostream & strm = Context.get_num_format_context().output();
// if (!number_textual_.get_value_or(false))
// {
// if (number_style_.get_value_or(L"short") == L"long")
// {
// strm << L"MM";
// }
// else
// {
// strm << L"M";
// }
// }
// else
// {
// if (number_style_.get_value_or(L"short") == L"long")
// {
// strm << L"MMMM";
// }
// else
// {
// strm << L"MMM";
// }
// }
//}
// number:year
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * number_year::ns = L"number";
const wchar_t * number_year::name = L"year";
void number_year::serialize(std::wostream & strm)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE_SIMPLE()
{
CP_XML_ATTR_OPT(L"number:style", number_style_);
CP_XML_ATTR_OPT(L"number:calendar", number_calendar_);
}
}
}
//void number_year::xlsx_convert(oox::xlsx_conversion_context & Context)
//{
// std::wostream & strm = Context.get_num_format_context().output();
// if (number_style_.get_value_or(L"short") == L"long")
// {
// strm << L"YYYY";
// }
// else
// {
// strm << L"YY";
// }
//}
// number:date-style
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * number_date_style::ns = L"number";
const wchar_t * number_date_style::name = L"date-style";
// number:time-style
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * number_time_style::ns = L"number";
const wchar_t * number_time_style::name = L"time-style";
// number:hours
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * number_hours::ns = L"number";
const wchar_t * number_hours::name = L"hours";
void number_hours::serialize(std::wostream & strm)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE_SIMPLE()
{
CP_XML_ATTR_OPT(L"number:style", number_style_);
CP_XML_ATTR_OPT(L"number:calendar", number_calendar_);
}
}
}
//void number_hours::xlsx_convert(oox::xlsx_conversion_context & Context)
//{
// std::wostream & strm = Context.get_num_format_context().output();
// if (number_style_.get_value_or(L"short") == L"long")
// {
// strm << L"HH";
// }
// else
// {
// // TODO
// strm << L"HH";
// }
//}
// number:minutes
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * number_minutes::ns = L"number";
const wchar_t * number_minutes::name = L"minutes";
void number_minutes::serialize(std::wostream & strm)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE_SIMPLE()
{
CP_XML_ATTR_OPT(L"number:style", number_style_);
CP_XML_ATTR_OPT(L"number:calendar", number_calendar_);
}
}
}
//void number_minutes::xlsx_convert(oox::xlsx_conversion_context & Context)
//{
// std::wostream & strm = Context.get_num_format_context().output();
// if (number_style_.get_value_or(L"short") == L"long")
// {
// strm << L"MM";
// }
// else
// {
// // TODO
// strm << L"MM";
// }
//}
// number:seconds
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * number_seconds::ns = L"number";
const wchar_t * number_seconds::name = L"seconds";
void number_seconds::serialize(std::wostream & strm)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE_SIMPLE()
{
CP_XML_ATTR_OPT(L"number:style", number_style_);
CP_XML_ATTR_OPT(L"number:decimal-places", number_decimal_places_);
CP_XML_ATTR_OPT(L"number:calendar", number_calendar_);
}
}
}
//void number_seconds::xlsx_convert(oox::xlsx_conversion_context & Context)
//{
// std::wostream & strm = Context.get_num_format_context().output();
// if (number_style_.get_value_or(L"short") == L"long")
// {
// strm << L"SS";
// }
// else
// {
// // TODO
// strm << L"SS";
// }
//
// if (int dec = number_decimal_places_.get_value_or(0))
// {
// strm << L".";
// strm << std::wstring(dec, L'0');
// }
//}
// number:am-pm
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * number_am_pm::ns = L"number";
const wchar_t * number_am_pm::name = L"am-pm";
void number_am_pm::serialize(std::wostream & strm)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE_SIMPLE();
}
}
//void number_am_pm::xlsx_convert(oox::xlsx_conversion_context & Context)
//{
// std::wostream & strm = Context.get_num_format_context().output();
// strm << L"AM/PM";
//}
// number:fraction
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * number_fraction::ns = L"number";
const wchar_t * number_fraction::name = L"fraction";
void number_fraction::serialize(std::wostream & strm)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE_SIMPLE()
{
CP_XML_ATTR_OPT(L"number:min-integer-digits", number_min_integer_digits_);
CP_XML_ATTR_OPT(L"number:grouping", number_grouping_);
CP_XML_ATTR_OPT(L"number:calendar", number_calendar_);
CP_XML_ATTR_OPT(L"number:denominator-value", number_denominator_value_);
CP_XML_ATTR_OPT(L"number:min-numerator-digits", number_min_numerator_digits_);
CP_XML_ATTR_OPT(L"number:min-denominator-digits", number_min_denominator_digits_);
}
}
}
//void number_fraction::xlsx_convert(oox::xlsx_conversion_context & Context)
//{
// std::wostream & strm = Context.get_num_format_context().output();
//
// format_number_number(strm,
// number_grouping_.get_value_or(false),
// number_min_integer_digits_.get_value_or(0),
// 0);
//
// if (number_min_numerator_digits_.get_value_or(0) &&
// number_min_denominator_digits_.get_value_or(0))
// {
// strm << L' ';
// strm << std::wstring(number_min_numerator_digits_.get_value_or(0), L'?');
// strm << L'/';
//
// if (!number_denominator_value_)
// strm << std::wstring(number_min_denominator_digits_.get_value_or(0), L'?');
// else
// strm << *number_denominator_value_;
// }
//}
//
//void number_scientific_number::xlsx_convert(oox::xlsx_conversion_context & Context)
//{
// std::wostream & strm = Context.get_num_format_context().output();
// format_number_number(
// strm,
// number_grouping_.get_value_or(false),
// number_min_integer_digits_.get_value_or(0),
// number_decimal_places_.get_value_or(0)
// );
//
// if (int e = number_min_exponent_digits_.get_value_or(0))
// {
// strm << L"E+" << std::wstring(e, L'0');
// }
//}
//
}
}
#pragma once
#include <iosfwd>
#include <cpdoccore/CPOptional.h>
#include <cpdoccore/xml/xmlelement.h>
#include <cpdoccore/xml/nodetype.h>
#include "office_elements.h"
#include "office_elements_create.h"
#include "common_attlists.h"
namespace cpdoccore {
namespace odf {
class number_style_base : public office_element
{
public:
CPDOCCORE_DEFINE_VISITABLE();
virtual void create_child_element( const ::std::wstring & Ns, const ::std::wstring & Name);
virtual void add_child_element(office_element_ptr & child);
virtual void serialize(std::wostream & strm);
void serialize(CP_ATTR_NODE);
std::wstring get_style_name() const;
void set_style_name(std::wstring & name);
common_data_style_attlist common_data_style_attlist_;
office_element_ptr style_text_properties_;
office_element_ptr_array content_;
office_element_ptr_array style_map_;
};
/// \brief number:number-style
class number_number_style : public number_style_base
{
public:
static const wchar_t * ns;
static const wchar_t * name;
static const xml::NodeType xml_type = xml::typeElement;
static const ElementType type = typeNumberNumberStyle;
CPDOCCORE_DEFINE_VISITABLE();
CPDOCCORE_OFFICE_DOCUMENT_IMPL_NAME_FUNCS_;
virtual void serialize(std::wostream & strm);
};
CP_REGISTER_OFFICE_ELEMENT2(number_number_style);
/// \brief number:currency-style
class number_currency_style : public number_style_base
{
public:
static const wchar_t * ns;
static const wchar_t * name;
static const xml::NodeType xml_type = xml::typeElement;
static const ElementType type = typeNumberCurrencyStyle;
CPDOCCORE_DEFINE_VISITABLE();
CPDOCCORE_OFFICE_DOCUMENT_IMPL_NAME_FUNCS_;
virtual void serialize(std::wostream & strm);
};
CP_REGISTER_OFFICE_ELEMENT2(number_currency_style);
/// \brief number:text-style
class number_text_style : public number_style_base
{
public:
static const wchar_t * ns;
static const wchar_t * name;
static const xml::NodeType xml_type = xml::typeElement;
static const ElementType type = typeNumberTextStyle;
CPDOCCORE_DEFINE_VISITABLE();
CPDOCCORE_OFFICE_DOCUMENT_IMPL_NAME_FUNCS_;
virtual void serialize(std::wostream & strm);
};
CP_REGISTER_OFFICE_ELEMENT2(number_text_style);
/// \brief number:date-style
class number_date_style : public number_style_base
{
public:
static const wchar_t * ns;
static const wchar_t * name;
static const xml::NodeType xml_type = xml::typeElement;
static const ElementType type = typeNumberDataStyle;
CPDOCCORE_DEFINE_VISITABLE();
CPDOCCORE_OFFICE_DOCUMENT_IMPL_NAME_FUNCS_;
virtual void serialize(std::wostream & strm);
_CP_OPT(bool) number_automatic_order_;
};
CP_REGISTER_OFFICE_ELEMENT2(number_date_style);
/// \brief number:percentage-style
class number_percentage_style : public number_style_base
{
public:
static const wchar_t * ns;
static const wchar_t * name;
static const xml::NodeType xml_type = xml::typeElement;
static const ElementType type = typeNumberPercentageStyle;
CPDOCCORE_DEFINE_VISITABLE();
CPDOCCORE_OFFICE_DOCUMENT_IMPL_NAME_FUNCS_;
virtual void serialize(std::wostream & strm);
};
CP_REGISTER_OFFICE_ELEMENT2(number_percentage_style);
/// \brief number:time-style
class number_time_style : public number_style_base
{
public:
static const wchar_t * ns;
static const wchar_t * name;
static const xml::NodeType xml_type = xml::typeElement;
static const ElementType type = typeNumberTimeStyle;
CPDOCCORE_DEFINE_VISITABLE();
CPDOCCORE_OFFICE_DOCUMENT_IMPL_NAME_FUNCS_;
_CP_OPT(bool) number_automatic_order_;
virtual void serialize(std::wostream & strm);
};
CP_REGISTER_OFFICE_ELEMENT2(number_time_style);
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
/// \brief number:text
class number_text : public office_element_impl<number_text>
{
public:
static const wchar_t * ns;
static const wchar_t * name;
static const xml::NodeType xml_type = xml::typeElement;
static const ElementType type = typeNumberText;
CPDOCCORE_DEFINE_VISITABLE();
virtual void create_child_element( const ::std::wstring & Ns, const ::std::wstring & Name){}
virtual void add_child_element(office_element_ptr & child)
{std::wstringstream str; str <<L"Non add child in "; str << ns; str << L":"; str <<name; _CP_LOG(error) << str.str();}
virtual void serialize(std::wostream & strm);
virtual void add_text(const std::wstring & Text);
private:
office_element_ptr_array text_;
};
CP_REGISTER_OFFICE_ELEMENT2(number_text);
/// \brief number:number
class number_number : public office_element_impl<number_number>
{
public:
static const wchar_t * ns;
static const wchar_t * name;
static const xml::NodeType xml_type = xml::typeElement;
static const ElementType type = typeNumberNumber;
CPDOCCORE_DEFINE_VISITABLE();
virtual void create_child_element( const ::std::wstring & Ns, const ::std::wstring & Name);
virtual void add_child_element(office_element_ptr & child);
virtual void serialize(std::wostream & strm);
// number-number-attlist
_CP_OPT(std::wstring) number_decimal_replacement_;
_CP_OPT(double) number_display_factor_;
// common-decimal-places-attlist
_CP_OPT(int) number_decimal_places_;
// common-number-attlist
_CP_OPT(int) number_min_integer_digits_;
_CP_OPT(bool) number_grouping_;
office_element_ptr_array number_embedded_text_;
};
CP_REGISTER_OFFICE_ELEMENT2(number_number);
/// \brief number:embedded-text
class number_embedded_text : public office_element_impl<number_embedded_text>
{
public:
static const wchar_t * ns;
static const wchar_t * name;
static const xml::NodeType xml_type = xml::typeElement;
static const ElementType type = typeNumberEmbeddedText;
CPDOCCORE_DEFINE_VISITABLE();
virtual void create_child_element( const ::std::wstring & Ns, const ::std::wstring & Name){CP_NOT_APPLICABLE_ELM();}
virtual void add_child_element(office_element_ptr & child)
{std::wstringstream str; str <<L"Non add child in "; str << ns; str << L":"; str <<name; _CP_LOG(error) << str.str();}
virtual void serialize(std::wostream & strm);
virtual void add_text(const std::wstring & Text);
_CP_OPT(int) number_position_;
office_element_ptr_array text_;
};
CP_REGISTER_OFFICE_ELEMENT2(number_embedded_text);
/// \brief number:scientific-number
class number_scientific_number : public office_element_impl<number_scientific_number>
{
public:
static const wchar_t * ns;
static const wchar_t * name;
static const xml::NodeType xml_type = xml::typeElement;
static const ElementType type = typeNumberScientificNumber;
CPDOCCORE_DEFINE_VISITABLE();
virtual void create_child_element( const ::std::wstring & Ns, const ::std::wstring & Name){CP_NOT_APPLICABLE_ELM();}
virtual void add_child_element(office_element_ptr & child)
{std::wstringstream str; str <<L"Non add child in "; str << ns; str << L":"; str <<name; _CP_LOG(error) << str.str();}
virtual void serialize(std::wostream & strm);
// number-scientific-number-attlist
_CP_OPT(int) number_min_exponent_digits_;
// common-decimal-places-attlist
_CP_OPT(int) number_decimal_places_;
// common-number-attlist
_CP_OPT(int) number_min_integer_digits_;
_CP_OPT(bool) number_grouping_;
};
CP_REGISTER_OFFICE_ELEMENT2(number_scientific_number);
/// \brief number:currency-symbol
class number_currency_symbol : public office_element_impl<number_currency_symbol>
{
public:
static const wchar_t * ns;
static const wchar_t * name;
static const xml::NodeType xml_type = xml::typeElement;
static const ElementType type = typeNumberCurrencySymbol;
CPDOCCORE_DEFINE_VISITABLE();
virtual void create_child_element( const ::std::wstring & Ns, const ::std::wstring & Name){CP_NOT_APPLICABLE_ELM();}
virtual void add_child_element(office_element_ptr & child)
{std::wstringstream str; str <<L"Non add child in "; str << ns; str << L":"; str <<name; _CP_LOG(error) << str.str();}
virtual void serialize(std::wostream & strm);
virtual void add_text(const std::wstring & Text);
_CP_OPT(std::wstring) number_language_;
_CP_OPT(std::wstring) number_country_;
std::vector<std::wstring> text_;
};
CP_REGISTER_OFFICE_ELEMENT2(number_currency_symbol);
/// \brief number:text-content
class number_text_content : public office_element_impl<number_text_content>
{
public:
static const wchar_t * ns;
static const wchar_t * name;
static const xml::NodeType xml_type = xml::typeElement;
static const ElementType type = typeNumberTextContent;
CPDOCCORE_DEFINE_VISITABLE();
virtual void create_child_element( const ::std::wstring & Ns, const ::std::wstring & Name){CP_NOT_APPLICABLE_ELM();}
virtual void add_child_element(office_element_ptr & child)
{std::wstringstream str; str <<L"Non add child in "; str << ns; str << L":"; str <<name; _CP_LOG(error) << str.str();}
virtual void serialize(std::wostream & strm);
virtual void add_text(const std::wstring & Text);
office_element_ptr_array text_;
};
CP_REGISTER_OFFICE_ELEMENT2(number_text_content);
/// \class number_day_of_week
/// \brief number:day-of-week
/// number-day-of-week
class number_day_of_week : public office_element_impl<number_day_of_week>
{
public:
static const wchar_t * ns;
static const wchar_t * name;
static const xml::NodeType xml_type = xml::typeElement;
static const ElementType type = typeNumberDayOfWeek;
CPDOCCORE_DEFINE_VISITABLE();
virtual void create_child_element( const ::std::wstring & Ns, const ::std::wstring & Name){CP_NOT_APPLICABLE_ELM();}
virtual void add_child_element(office_element_ptr & child)
{std::wstringstream str; str <<L"Non add child in "; str << ns; str << L":"; str <<name; _CP_LOG(error) << str.str();}
virtual void serialize(std::wostream & strm);
private:
_CP_OPT(std::wstring) number_style_;
_CP_OPT(std::wstring) number_calendar_;
};
CP_REGISTER_OFFICE_ELEMENT2(number_day_of_week);
/// \brief number:quarter
class number_quarter : public office_element_impl<number_quarter>
{
public:
static const wchar_t * ns;
static const wchar_t * name;
static const xml::NodeType xml_type = xml::typeElement;
static const ElementType type = typeNumberQuarter;
CPDOCCORE_DEFINE_VISITABLE();
virtual void create_child_element( const ::std::wstring & Ns, const ::std::wstring & Name){CP_NOT_APPLICABLE_ELM();}
virtual void add_child_element(office_element_ptr & child)
{std::wstringstream str; str <<L"Non add child in "; str << ns; str << L":"; str <<name; _CP_LOG(error) << str.str();}
virtual void serialize(std::wostream & strm);
_CP_OPT(std::wstring) number_style_;
_CP_OPT(std::wstring) number_calendar_;
};
CP_REGISTER_OFFICE_ELEMENT2(number_quarter);
/// \brief number:day
class number_day : public office_element_impl<number_day>
{
public:
static const wchar_t * ns;
static const wchar_t * name;
static const xml::NodeType xml_type = xml::typeElement;
static const ElementType type = typeNumberDay;
CPDOCCORE_DEFINE_VISITABLE();
virtual void create_child_element( const ::std::wstring & Ns, const ::std::wstring & Name){CP_NOT_APPLICABLE_ELM();}
virtual void add_child_element(office_element_ptr & child)
{std::wstringstream str; str <<L"Non add child in "; str << ns; str << L":"; str <<name; _CP_LOG(error) << str.str();}
virtual void serialize(std::wostream & strm);
_CP_OPT(std::wstring) number_style_;
_CP_OPT(std::wstring) number_calendar_;
};
CP_REGISTER_OFFICE_ELEMENT2(number_day);
/// \brief number:month
class number_month : public office_element_impl<number_month>
{
public:
static const wchar_t * ns;
static const wchar_t * name;
static const xml::NodeType xml_type = xml::typeElement;
static const ElementType type = typeNumberMonth;
CPDOCCORE_DEFINE_VISITABLE();
virtual void create_child_element( const ::std::wstring & Ns, const ::std::wstring & Name){CP_NOT_APPLICABLE_ELM();}
virtual void add_child_element(office_element_ptr & child)
{std::wstringstream str; str <<L"Non add child in "; str << ns; str << L":"; str <<name; _CP_LOG(error) << str.str();}
virtual void serialize(std::wostream & strm);
_CP_OPT(Bool) number_textual_;
_CP_OPT(bool) number_possessive_form_;
_CP_OPT(std::wstring) number_style_;
_CP_OPT(std::wstring) number_calendar_;
};
CP_REGISTER_OFFICE_ELEMENT2(number_month);
/// \brief number:year
class number_year : public office_element_impl<number_year>
{
public:
static const wchar_t * ns;
static const wchar_t * name;
static const xml::NodeType xml_type = xml::typeElement;
static const ElementType type = typeNumberYear;
CPDOCCORE_DEFINE_VISITABLE();
virtual void create_child_element( const ::std::wstring & Ns, const ::std::wstring & Name){CP_NOT_APPLICABLE_ELM();}
virtual void add_child_element(office_element_ptr & child)
{std::wstringstream str; str <<L"Non add child in "; str << ns; str << L":"; str <<name; _CP_LOG(error) << str.str();}
virtual void serialize(std::wostream & strm);
_CP_OPT(std::wstring) number_style_;
_CP_OPT(std::wstring) number_calendar_;
};
CP_REGISTER_OFFICE_ELEMENT2(number_year);
/// \brief number:hours
class number_hours : public office_element_impl<number_hours>
{
public:
static const wchar_t * ns;
static const wchar_t * name;
static const xml::NodeType xml_type = xml::typeElement;
static const ElementType type = typeNumberHours;
CPDOCCORE_DEFINE_VISITABLE();
virtual void create_child_element( const ::std::wstring & Ns, const ::std::wstring & Name){CP_NOT_APPLICABLE_ELM();}
virtual void add_child_element(office_element_ptr & child)
{std::wstringstream str; str <<L"Non add child in "; str << ns; str << L":"; str <<name; _CP_LOG(error) << str.str();}
virtual void serialize(std::wostream & strm);
_CP_OPT(std::wstring) number_style_;
_CP_OPT(std::wstring) number_calendar_;
};
CP_REGISTER_OFFICE_ELEMENT2(number_hours);
/// \brief number:minutes
class number_minutes : public office_element_impl<number_minutes>
{
public:
static const wchar_t * ns;
static const wchar_t * name;
static const xml::NodeType xml_type = xml::typeElement;
static const ElementType type = typeNumberMinutes;
CPDOCCORE_DEFINE_VISITABLE();
virtual void create_child_element( const ::std::wstring & Ns, const ::std::wstring & Name){CP_NOT_APPLICABLE_ELM();}
virtual void add_child_element(office_element_ptr & child)
{std::wstringstream str; str <<L"Non add child in "; str << ns; str << L":"; str <<name; _CP_LOG(error) << str.str();}
virtual void serialize(std::wostream & strm);
_CP_OPT(std::wstring) number_style_;
_CP_OPT(std::wstring) number_calendar_;
};
CP_REGISTER_OFFICE_ELEMENT2(number_minutes);
/// \brief number:seconds
class number_seconds : public office_element_impl<number_seconds>
{
public:
static const wchar_t * ns;
static const wchar_t * name;
static const xml::NodeType xml_type = xml::typeElement;
static const ElementType type = typeNumberSeconds;
CPDOCCORE_DEFINE_VISITABLE();
virtual void create_child_element( const ::std::wstring & Ns, const ::std::wstring & Name){CP_NOT_APPLICABLE_ELM();}
virtual void add_child_element(office_element_ptr & child)
{std::wstringstream str; str <<L"Non add child in "; str << ns; str << L":"; str <<name; _CP_LOG(error) << str.str();}
virtual void serialize(std::wostream & strm);
_CP_OPT(std::wstring) number_style_;
_CP_OPT(int) number_decimal_places_;
_CP_OPT(std::wstring) number_calendar_;
};
CP_REGISTER_OFFICE_ELEMENT2(number_seconds);
/// \brief number:am-pm
class number_am_pm : public office_element_impl<number_am_pm>
{
public:
static const wchar_t * ns;
static const wchar_t * name;
static const xml::NodeType xml_type = xml::typeElement;
static const ElementType type = typeNumberAmPm;
CPDOCCORE_DEFINE_VISITABLE();
virtual void create_child_element( const ::std::wstring & Ns, const ::std::wstring & Name){CP_NOT_APPLICABLE_ELM();}
virtual void add_child_element(office_element_ptr & child)
{std::wstringstream str; str <<L"Non add child in "; str << ns; str << L":"; str <<name; _CP_LOG(error) << str.str();}
virtual void serialize(std::wostream & strm);
};
CP_REGISTER_OFFICE_ELEMENT2(number_am_pm);
/// \brief number:fraction
class number_fraction : public office_element_impl<number_fraction>
{
public:
static const wchar_t * ns;
static const wchar_t * name;
static const xml::NodeType xml_type = xml::typeElement;
static const ElementType type = typeNumberFraction;
CPDOCCORE_DEFINE_VISITABLE();
virtual void create_child_element( const ::std::wstring & Ns, const ::std::wstring & Name){CP_NOT_APPLICABLE_ELM();}
virtual void add_child_element(office_element_ptr & child)
{std::wstringstream str; str <<L"Non add child in "; str << ns; str << L":"; str <<name; _CP_LOG(error) << str.str();}
virtual void serialize(std::wostream & strm);
_CP_OPT(int) number_min_integer_digits_;
_CP_OPT(bool) number_grouping_;
_CP_OPT(std::wstring) number_calendar_;
_CP_OPT(int) number_denominator_value_;
_CP_OPT(int) number_min_numerator_digits_;
_CP_OPT(int) number_min_denominator_digits_;
};
CP_REGISTER_OFFICE_ELEMENT2(number_fraction);
}
}
......@@ -8,105 +8,6 @@ namespace odf {
class office_element;
typedef shared_ptr<office_element>::Type office_element_ptr;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//class styles_container;
//class style_instance;
//typedef boost::shared_ptr<style_instance> style_instance_ptr;
//typedef boost::shared_ptr<styles_container> styles_container_ptr;
//class style_instance
//{
//public:
// style_instance(
// styles_container * Container,
// const std::wstring & Name,
// style_family::type Type,
// style_content * Content,
// bool IsAutomatic,
// bool IsDefault,
// const std::wstring & ParentStyleName,
// const std::wstring & NextStyleName,
// const std::wstring & DataStyleName
// );
//
//
// const std::wstring & name() const;
// style_family::type type() const;
// style_content * content() const;
// style_instance * parent() const;
// const std::wstring & parent_name() const;
// style_instance * next() const;
// const std::wstring & next_name() const;
// bool is_automatic() const;
// bool is_default() const;
// const styles_container * container() const { return container_; }
// const std::wstring & data_style_name() const;
//
//private:
// styles_container * container_;
// std::wstring name_;
// style_family::type style_type_;
// style_content * content_;
//
// bool is_automatic_;
// bool is_default_;
//
// std::wstring parent_name_;
// std::wstring next_name_;
// mutable style_instance * parent_;
// mutable style_instance * next_;
// std::wstring data_style_name_;
//};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//class styles_container
//{
//public:
// styles_container() : hyperlink_style_pos_(-1)
// {}
//
// typedef std::vector<style_instance_ptr> instances_array;
//
// void add_style(const std::wstring & Name,
// style_family::type Type,
// style_content * Content,
// bool IsAutomatic,
// bool IsDefault,
// const std::wstring & ParentStyleName,
// const std::wstring & NextStyleName,
// const std::wstring & DataStyleName);
//
// void add_master_page_name(const std::wstring & StyleName, const std::wstring & MasterPageName);
//
// style_instance * hyperlink_style();
// style_instance * style_by_name(const std::wstring & Name, style_family::type Type,bool object_in_styles) const;
// style_instance * style_default_by_type(style_family::type Type) const;
//
// const std::wstring master_page_name_by_name(const std::wstring & StyleName) const;
//
// instances_array & instances() { return instances_; }
//
// presentation_layouts_instance & presentation_layouts() { return presentation_layouts_; }
// presentation_masters_instance & presentation_masters() { return presentation_masters_; }
//
//private:
// //presentation_layouts_instance presentation_layouts_;
// //presentation_masters_instance presentation_masters_;
//
// instances_array instances_;
//
// typedef boost::unordered_map<std::wstring, int> map_wstring_int_t;
// map_wstring_int_t map_;
//
// typedef boost::unordered_map<std::wstring, std::wstring> map_wstring_wstring;
// map_wstring_wstring master_page_name_;
//
// typedef boost::unordered_map<style_family::type, int> map_style_family_int;
// map_style_family_int default_map_;
// int hyperlink_style_pos_;
//};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
......@@ -131,6 +32,8 @@ public:
odf_style_context & styles_context(){return style_context_;}
odf_number_styles_context & numbers_styles_context() {return style_context_.numbers_styles();}
private:
rels rels_;
......
#include "precompiled_cpodf.h"
#include "logging.h"
#include "odf_number_styles_context.h"
#include "ods_conversion_context.h"
#include "number_style.h"
namespace cpdoccore {
namespace odf {
odf_number_styles_context::odf_number_styles_context(odf_conversion_context & Context): context_(Context)
{
}
void odf_number_styles_context::create(int oox_num_fmt, std::wstring formatCode)
{
if (oox_num_fmt <164)return create_default(oox_num_fmt,formatCode);
number_format_state state;
state.oox_num_fmt = oox_num_fmt;
state.style_name = std::wstring(L"NF1000") + boost::lexical_cast<std::wstring>( number_format_array_.size()+1);
state.ods_type = office_value_type::Custom;
//////////////////////////////
boost::algorithm::split(state.format_code, formatCode, boost::algorithm::is_any_of(L";"), boost::algorithm::token_compress_on);
if (state.format_code.size()>1 && state.format_code[state.format_code.size()-1].find(L"@")>=0)
{
state.format_code.pop_back();
}
number_format_array_.push_back(state);
named_link_map_[oox_num_fmt] = number_format_array_.size()-1;
detect_format(number_format_array_.back());
}
void odf_number_styles_context::create_default(int oox_num_fmt, std::wstring formatCode)
{
number_format_state state;
state.oox_num_fmt = oox_num_fmt;
state.ods_type = office_value_type::Custom;
state.style_name = std::wstring(L"NF1000") + boost::lexical_cast<std::wstring>( number_format_array_.size()+1);
switch (oox_num_fmt)
{
case 1: formatCode = L"0"; state.ods_type =office_value_type::Float; break;
case 2: formatCode = L"0.00"; state.ods_type =office_value_type::Float; break;
case 3: formatCode = L"#,##0"; state.ods_type =office_value_type::Float; break;
case 4: formatCode = L"#,##0.00"; state.ods_type =office_value_type::Float; break;
case 9: formatCode = L"0%"; state.ods_type =office_value_type::Percentage; break;
case 10: formatCode = L"0.00%"; state.ods_type =office_value_type::Percentage; break;
case 11: formatCode = L"0.00E+00"; state.ods_type =office_value_type::Float; break;
case 12: formatCode = L"# ?/?"; state.ods_type =office_value_type::Float; break;
case 13: formatCode = L"# ??/??"; state.ods_type =office_value_type::Float; break;
case 14: formatCode = L"mm-dd-yy"; state.ods_type =office_value_type::Date; break;
case 15: formatCode = L"d-mmm-yy"; state.ods_type =office_value_type::Date; break;
case 16: formatCode = L"d-mmm"; state.ods_type =office_value_type::Date; break;
case 17: formatCode = L"mmm-yy"; state.ods_type =office_value_type::Date; break;
case 18: formatCode = L"h:mm AM/PM"; state.ods_type =office_value_type::Time; break;
case 19: formatCode = L"h:mm:ss AM/PM"; state.ods_type =office_value_type::Time; break;
case 20: formatCode = L"h:mm"; state.ods_type =office_value_type::Time; break;
case 21: formatCode = L"h:mm:ss"; state.ods_type =office_value_type::Time; break;
case 22: formatCode = L"m/d/yy h:mm"; state.ods_type =office_value_type::Time; break;
case 37: formatCode = L"#,##0 ;(#,##0)"; state.ods_type =office_value_type::Float; break;
case 38: formatCode = L"#,##0 ;[Red](#,##0)"; state.ods_type =office_value_type::Float; break;
case 39: formatCode = L"#,##0.00;(#,##0.00)"; state.ods_type =office_value_type::Float; break;
case 40: formatCode = L"#,##0.00;[Red](#,##0.00)"; state.ods_type =office_value_type::Float; break;
case 45: formatCode = L"mm:ss"; state.ods_type =office_value_type::Time; break;
case 46: formatCode = L"[h]:mm:ss"; state.ods_type =office_value_type::Time; break;
case 47: formatCode = L"mmss.0"; state.ods_type =office_value_type::Time; break;
case 49: formatCode = L"@"; state.ods_type =office_value_type::String; break;
default:
/////////////////////////////////// formatCode ..
if (oox_num_fmt >=5 && oox_num_fmt <=8)state.ods_type =office_value_type::Currency;
if (oox_num_fmt >=43 && oox_num_fmt <=44)state.ods_type =office_value_type::Currency;
if (oox_num_fmt >=27 && oox_num_fmt <=31)state.ods_type =office_value_type::Date;
if (oox_num_fmt >=50 && oox_num_fmt <=54)state.ods_type =office_value_type::Date;
if (oox_num_fmt >=57 && oox_num_fmt <=58)state.ods_type =office_value_type::Date;
if (oox_num_fmt ==36)state.ods_type =office_value_type::Date;
if (oox_num_fmt >=32 && oox_num_fmt <=35)state.ods_type =office_value_type::Time;
if (oox_num_fmt >=55 && oox_num_fmt <=56)state.ods_type =office_value_type::Time;
if (oox_num_fmt >=60 && oox_num_fmt <=62)state.ods_type =office_value_type::Float;
if (oox_num_fmt >=69 && oox_num_fmt <=70)state.ods_type =office_value_type::Float;
if (oox_num_fmt >=67 && oox_num_fmt <=68)state.ods_type =office_value_type::Percentage;
if (oox_num_fmt >=71 && oox_num_fmt <=74)state.ods_type =office_value_type::Date;
if (oox_num_fmt >=75 && oox_num_fmt <=80)state.ods_type =office_value_type::Time;
if (oox_num_fmt ==81)state.ods_type =office_value_type::Date;
}
boost::algorithm::split(state.format_code, formatCode, boost::algorithm::is_any_of(L";"), boost::algorithm::token_compress_on);
if (state.format_code.size()>1 && state.format_code[state.format_code.size()-1].find(L"@")>=0)
{
state.format_code.pop_back();
}
////////////////////////////////////////////
number_format_array_.push_back(state);
named_link_map_[oox_num_fmt] = number_format_array_.size()-1;
detect_format(number_format_array_.back());
}
number_format_state & odf_number_styles_context::add_or_find(int oox_num_fmt, std::wstring formatCode)
{
if (named_link_map_.count(oox_num_fmt) > 0)
{
return number_format_array_[named_link_map_.at(oox_num_fmt)];
}
else
{
create(oox_num_fmt,formatCode);
return number_format_array_.back();
}
}
void odf_number_styles_context::process_styles(office_element_ptr root )
{
for (long i=0; i< number_format_array_.size(); i++)
{
create_style(number_format_array_[i]);
root->add_child_element(styles_elments.back());
}
}
void odf_number_styles_context::create_style(number_format_state & state)
{
office_element_ptr elm;
switch(state.ods_type)
{
case office_value_type::Float: create_number_style (state, elm); break;
case office_value_type::Currency: create_currency_style (state, elm); break;
case office_value_type::Percentage: create_percentage_style (state, elm); break;
case office_value_type::Date: create_date_style (state, elm); break;
case office_value_type::Time: create_time_style (state, elm); break;
case office_value_type::Boolean: create_boolean_style (state, elm); break;
case office_value_type::String: create_text_style (state, elm); break;
}
number_style_base* number_style_ = dynamic_cast<number_style_base*>(elm.get());
if (number_style_)
{
number_style_->set_style_name(state.style_name);
}
styles_elments.push_back(elm);
}
void odf_number_styles_context::create_number_style(number_format_state & state, office_element_ptr & root_elm)
{
create_element(L"number", L"number-style", root_elm, &context_);
if (state.format_code.size()>0)
{
office_element_ptr elm;
create_element(L"number", L"number", elm, &context_);
styles_elments.push_back(elm);
number_number* number_number_ = dynamic_cast<number_number*>(elm.get());
if (number_number_)
{
std::vector<std::wstring> numbers;
boost::algorithm::split(numbers, state.format_code[0], boost::algorithm::is_any_of(L",."), boost::algorithm::token_compress_on);
number_number_->number_min_integer_digits_= numbers[0].size();
if (numbers.size()>1)
{
number_number_->number_decimal_places_= numbers[1].size();
}
}
root_elm->add_child_element(elm);
}
}
void odf_number_styles_context::create_percentage_style(number_format_state & state, office_element_ptr & root_elm)
{
create_element(L"number", L"percentage-style", root_elm, &context_);
}
void odf_number_styles_context::create_currency_style(number_format_state & state, office_element_ptr & root_elm)
{
create_element(L"number", L"currency-style", root_elm, &context_);
{
office_element_ptr elm;
create_element(L"number", L"currency-symbol", elm, &context_);
styles_elments.push_back(elm);
number_currency_symbol* number_currency_symbol_ = dynamic_cast<number_currency_symbol*>(elm.get());
if (number_currency_symbol_)
{
number_currency_symbol_->add_text(state.currency_str);
}
root_elm->add_child_element(elm);
}
}
void odf_number_styles_context::create_date_style(number_format_state & state, office_element_ptr & root_elm)
{
create_element(L"number", L"date-style", root_elm, &context_);
//state.language_code == L"F800" System long date format
std::wstring s = state.format_code[0];
boost::algorithm::to_lower(s);
boost::wregex re(L"(\\w+)");
std::list<std::wstring> result;
bool b = boost::regex_split(std::back_inserter(result),s, re);
int res;
int sz=0;
for (std::list<std::wstring>::iterator i=result.begin(); i!=result.end(); ++i)
{
office_element_ptr elm;
s = *i;
sz = s.length();
if ((res=s.find(L"m")) >=0)
{
create_element(L"number", L"month", elm, &context_);
number_month* number_month_ = dynamic_cast<number_month*>(elm.get());
if (number_month_ && sz > 2)number_month_->number_textual_ = true;
}
if ((res=s.find(L"d")) >=0)
{
if (sz < 3)
{
create_element(L"number", L"day", elm, &context_);
number_day* number_day_ = dynamic_cast<number_day*>(elm.get());
if (number_day_)
{
if (sz == 1)number_day_->number_style_ = L"short";
if (sz == 2)number_day_->number_style_ = L"long";
}
}
else
{
create_element(L"number", L"day-of-week", elm, &context_);
}
}
if ((res=s.find(L"y")) >=0)
{
create_element(L"number", L"year", elm, &context_);
number_year* number_year_ = dynamic_cast<number_year*>(elm.get());
if (number_year_)
{
if (sz<3) number_year_->number_style_ = L"short";
else number_year_->number_style_ = L"long";
}
}
if (elm)
{
root_elm->add_child_element(elm);
styles_elments.push_back(elm);
//////////////////// ////////////////////
create_element(L"number", L"text", elm, &context_);
number_text* number_text_ = dynamic_cast<number_text*>(elm.get());
if (number_text_)number_text_->add_text(L"."); //
root_elm->add_child_element(elm);
styles_elments.push_back(elm);
}
}
styles_elments.pop_back();//
}
void odf_number_styles_context::create_time_style(number_format_state & state, office_element_ptr & root_elm)
{
create_element(L"number", L"time-style", root_elm, &context_);
// state.language_code == L"F400")//System time format
std::wstring s = state.format_code[0];
boost::algorithm::to_lower(s);
boost::wregex re(L"(\\w+)");
std::list<std::wstring> result;
bool b = boost::regex_split(std::back_inserter(result),s, re);
int res;
int sz=0;
for (std::list<std::wstring>::iterator i=result.begin(); i!=result.end(); ++i)
{
office_element_ptr elm;
s = *i;
sz = s.length();
if ((res=s.find(L"h")) >=0)
{
create_element(L"number", L"hours", elm, &context_);
number_hours* number_hours_ = dynamic_cast<number_hours*>(elm.get());
if (number_hours_)
{
if (sz == 1)number_hours_->number_style_ = L"short";
if (sz == 2)number_hours_->number_style_ = L"long";
}
}
if ((res=s.find(L"m")) >=0)
{
create_element(L"number", L"minutes", elm, &context_);
number_minutes* number_minutes_ = dynamic_cast<number_minutes*>(elm.get());
if (number_minutes_)
{
if (sz == 1)number_minutes_->number_style_ = L"short";
if (sz == 2)number_minutes_->number_style_ = L"long";
}
}
if ((res=s.find(L"s")) >=0)
{
create_element(L"number", L"seconds", elm, &context_);
number_seconds* number_seconds_ = dynamic_cast<number_seconds*>(elm.get());
if (number_seconds_)
{
if (sz == 1) number_seconds_->number_style_ = L"short";
if (sz == 2) number_seconds_->number_style_ = L"long";
}
}
if ((res=s.find(L"am")) >=0 || (res=s.find(L"pm")) >=0)
{
create_element(L"number", L"am-pm", elm, &context_);
}
if (elm)
{
root_elm->add_child_element(elm);
styles_elments.push_back(elm);
//////////////////// ////////////////////
create_element(L"number", L"text", elm, &context_);
number_text* number_text_ = dynamic_cast<number_text*>(elm.get());
if (number_text_)number_text_->add_text(L":"); //
root_elm->add_child_element(elm);
styles_elments.push_back(elm);
}
}
styles_elments.pop_back();//
}
void odf_number_styles_context::create_boolean_style(number_format_state & state, office_element_ptr & root_elm)
{
create_element(L"number", L"boolean-style", root_elm, &context_);
}
void odf_number_styles_context::create_text_style(number_format_state & state, office_element_ptr & root_elm)
{
create_element(L"number", L"text-style", root_elm, &context_);
}
void odf_number_styles_context::detect_format(number_format_state & state)
{
if (state.ods_type != office_value_type::Custom)return;
if (state.format_code.size()<1)return;
//find [$<Currency String>-<language info>].
boost::wregex re(L"(?:\\[)(?:\\$)(\\S+)?\-(\\S+)(?:\\])");
boost::wsmatch result;
bool b = boost::regex_search(state.format_code[0], result, re);
if (b && result.size()==3)
{
state.currency_str=result[1];
state.language_code=result[2];
state.format_code[0] = boost::regex_replace( state.format_code[0],re,L"");
}
if (state.currency_str.length()>0)
{
state.ods_type = office_value_type::Currency;
return;
}
std::wstring tmp = state.format_code[0];
boost::algorithm::to_lower(tmp);
if (state.format_code.size() == 1)//any
{
int res=0;
if ((res=tmp.find(L"at"))>=0 || (res=tmp.find(L"pm"))>=0 ||
(res=tmp.find(L"h"))>=0 || (res=tmp.find(L"s"))>=0 || state.language_code == L"F400")
{
state.ods_type = office_value_type::Time;
return;
}
if ((res=tmp.find(L"y"))>=0 || (res=tmp.find(L"d"))>=0)//m
{
state.ods_type = office_value_type::Date;
return;
}
if ((res=tmp.find(L"%"))>=0)
{
state.ods_type = office_value_type::Percentage;
return;
}
state.ods_type = office_value_type::Float;
return;
}
else if (state.format_code.size() == 2)//>0, <0
{
}
else if (state.format_code.size() == 3)//>0, <0, ==0
{
}
///////////////////////////////
}
}
}
#pragma once
#include <string>
#include <vector>
#include <boost/unordered_map.hpp>
#include "office_elements.h"
#include "office_elements_create.h"
#include "officevaluetype.h"
namespace cpdoccore {
namespace odf {
class ods_conversion_context;
class office_element;
typedef shared_ptr<office_element>::Type office_element_ptr;
struct number_format_state
{
int oox_num_fmt;//äåôîëòíûå (ïî äîêóìåíòàöèè - íîìåðà 0-163, çà èñêëþ÷åíèåì íåêîòîðûõ)
office_value_type::type ods_type;
std::vector<std::wstring> format_code;
std::wstring style_name;
std::wstring language_code;
std::wstring currency_str;
};
class odf_number_styles_context
{
public:
odf_number_styles_context(odf_conversion_context & Context);
number_format_state & add_or_find(int oox_num_fmt, std::wstring formatCode = L"");
void process_styles(office_element_ptr root );
private:
std::vector<number_format_state> number_format_array_;
boost::unordered_map<int, int> named_link_map_;
void create(int oox_num_fmt, std::wstring formatCode = L"");
void create_default(int oox_num_fmt, std::wstring formatCode = L"");
void create_style(number_format_state & state);
void detect_format(number_format_state & state);
////////////////
odf_conversion_context & context_;
std::vector<office_element_ptr> styles_elments;
//////////////////
void create_number_style(number_format_state & state, office_element_ptr & root_elm);
void create_currency_style(number_format_state & state, office_element_ptr & root_elm);
void create_date_style(number_format_state & state, office_element_ptr & root_elm);
void create_time_style(number_format_state & state, office_element_ptr & root_elm);
void create_boolean_style(number_format_state & state, office_element_ptr & root_elm);
void create_text_style(number_format_state & state, office_element_ptr & root_elm);
void create_percentage_style(number_format_state & state, office_element_ptr & root_elm);
};
}
}
......@@ -13,7 +13,7 @@
namespace cpdoccore {
namespace odf {
odf_style_context::odf_style_context(odf_conversion_context & Context): context_(Context)
odf_style_context::odf_style_context(odf_conversion_context & Context): context_(Context), number_styles_context_(Context)
{
}
......@@ -41,6 +41,14 @@ void odf_style_context::create_style(std::wstring oox_name,const style_family fa
last_state().style_oox_name_ = oox_name;
}
void odf_style_context::add_style(office_element_ptr elm, bool automatic, bool root, style_family family)
{
style_state_list_.push_back( odf_style_state(elm, family) );
last_state().set_automatic(automatic);
last_state().set_root(root);
}
void odf_style_context::create_default(const style_family family)
{
office_element_ptr elm;
......@@ -91,6 +99,8 @@ void odf_style_context::process_master(office_element_ptr root )
}
void odf_style_context::process_office(office_element_ptr root )
{
number_styles_context_.process_styles(root );
for (long i =0; i < style_state_list_.size(); i++)
{
if (style_state_list_[i].automatic_== false && style_state_list_[i].root_ == true && style_state_list_[i].odf_style_)
......
......@@ -2,6 +2,7 @@
#include <string>
#include "odf_style_state.h"
#include "odf_number_styles_context.h"
namespace cpdoccore {
......@@ -24,6 +25,8 @@ public:
void create_style(std::wstring name, const style_family style_family, bool automatic = false, bool root = false, int oox_id = -1);
void create_default(const style_family style_family);
void add_style(office_element_ptr elm, bool automatic = false, bool root = false, style_family style_family=style_family::None);
office_element_ptr & add_or_find(std::wstring name, const style_family family, bool automatic = false, bool root = false, int id = -1);
void process_automatic_styles(office_element_ptr root );
......@@ -42,62 +45,12 @@ public:
bool find_odf_style_state(int oox_id_style, const style_family family, odf_style_state *& state, bool root = false);
//void start_cell(const std::wstring & formula,
// size_t columnsSpanned,
// size_t rowsSpanned);
//void end_cell();
// std::wstring default_row_cell_style() const;
// std::wstring default_column_cell_style() const;
// void start_covered_cell();
// void end_covered_cell();
// void start_cell_content();
// int end_cell_content();
// void set_current_cell_style_id(unsigned int xfId);
// int get_current_cell_style_id();
// int current_column() const;
// int current_row() const;
//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();
// bool is_empty_row() const;
// void end_row();
// void start_column(unsigned int repeated, const std::wstring & defaultCellStyleName);
// size_t depth() const { return table_state_stack_.size(); }
// unsigned int columns_count();
// void serialize_merge_cells(std::wostream & _Wostream);
//void serialize_table_format(std::wostream & _Wostream);
//xlsx_table_metrics & get_table_metrics();
//
//xlsx_drawing_context & get_drawing_context();
// xlsx_comments_context & get_comments_context();
//
// void table_column_last_width(double w);
// double table_column_last_width() const;
odf_style_state & last_state();
// void start_hyperlink();
//std::wstring end_hyperlink(std::wstring const & ref, std::wstring const & href, std::wstring const & display);
// void dump_rels_hyperlinks(rels & Rels);
// void serialize_hyperlinks(std::wostream & _Wostream);
odf_number_styles_context & numbers_styles() {return number_styles_context_;}
private:
odf_number_styles_context number_styles_context_;
odf_conversion_context & context_;
......
......@@ -63,6 +63,13 @@ void odf_style_state::set_parent_style_name(std::wstring & name)
style_->style_parent_style_name_ = name;
}
void odf_style_state::set_data_style_name(std::wstring & name)
{
style* style_ = dynamic_cast<style*>(odf_style_.get());
if (!style_)return;
style_->style_data_style_name_ = name;
}
//////////////////////////////////////////////////////////////////////
void odf_style_state::set_automatic(bool val)
{
......
......@@ -53,6 +53,7 @@ public:
int get_number_format() {return num_fmt_id_;}
void set_parent_style_name(std::wstring & name) ;
void set_data_style_name(std::wstring & name);
//////////////////////////////////////////////////////////////////////////////////////////
style_text_properties * get_text_properties();
style_paragraph_properties * get_paragraph_properties() ;
......
#include "precompiled_cpodf.h"
#include "logging.h"
#include <boost/foreach.hpp>
#include <iostream>
#include "odf_text_context.h"
#include "odf_style_context.h"
#include "odf_conversion_context.h"
#include "text_elements.h"
#include "paragraph_elements.h"
namespace cpdoccore {
namespace odf
{
odf_text_context::odf_text_context(odf_style_context * styles_context,odf_conversion_context *odf_context)
{
styles_context_ = styles_context;
odf_context_ = odf_context;
last_paragraph_ = NULL;
}
odf_text_context::~odf_text_context()
{
}
void odf_text_context::set_styles_context(odf_style_context* styles_context)
{
styles_context_ = styles_context;
}
void odf_text_context::add_text_content(const std::wstring & text)
{
if (current_level_.size() >=0 )
current_level_.back()->add_text(text);
else
{
}
}
void odf_text_context::start_paragraph(office_element_ptr & elm)
{
office_element_ptr style;
int level = current_level_.size();
odf_text_state state={elm,L"", style,level};
text_elements_list_.push_back(state);
if (current_level_.size()>0)
current_level_.back()->add_child_element(elm);
current_level_.push_back(elm);
//text_p *text_p_ = dynamic_cast<text_p*>(elm.get());
//if (text_p_ == NULL)return;
//
//paragraph *new_paragraph = &(text_p_->paragraph_);
//if (last_paragraph_)
// last_paragraph_->set_next(new_paragraph);
//new_paragraph->set_prev(last_paragraph_);
//last_paragraph_ = new_paragraph;
}
void odf_text_context::end_paragraph()
{
current_level_.pop_back();
}
void odf_text_context::start_element(office_element_ptr & elm)
{
int level = current_level_.size();
odf_text_state state={elm, L"", office_element_ptr(), level};
text_elements_list_.push_back(state);
if (current_level_.size()>0)
current_level_.back()->add_child_element(elm);
current_level_.push_back(elm);
}
void odf_text_context::end_element()
{
current_level_.pop_back();
}
void odf_text_context::start_span()// -
{
if (styles_context_ == NULL)return;
office_element_ptr span_elm;
create_element(L"text", L"span", span_elm, odf_context_);
text_span* span = dynamic_cast<text_span*>(span_elm.get());
if (span == NULL)return;
span->text_style_name_ = style_ref(styles_context_->last_state().get_name());
int level = current_level_.size();
odf_text_state state={ span_elm,
styles_context_->last_state().get_name(),
styles_context_->last_state().get_office_element(),
level};
text_elements_list_.push_back(state);
if (current_level_.size()>0)
current_level_.back()->add_child_element(span_elm);
current_level_.push_back(span_elm);
}
void odf_text_context::end_span()
{
current_level_.pop_back();
}
}
}
\ No newline at end of file
#pragma once
#include <string>
#include <vector>
//
//#include "ods_drawing_context.h"
//#include "ods_comments_context.h"
//#include "ods_hyperlinks.h"
#include "office_elements.h"
#include "office_elements_create.h"
namespace cpdoccore {
namespace odf
{
class odf_conversion_context;
class odf_style_context;
class paragraph;
struct odf_text_state
{
office_element_ptr elm;
std::wstring style_name;
office_element_ptr style_elm;
int level;
};
class odf_text_context: boost::noncopyable
{
public:
odf_text_context(odf_style_context * styles_context_,odf_conversion_context *odf_context);
~odf_text_context();
public:
void set_styles_context(odf_style_context* styles_context);// embedded
void add_text_content(const std::wstring & text);
void start_paragraph(office_element_ptr & elm);
void end_paragraph();
void start_element(office_element_ptr & elm); // t, h, list???
void end_element();
void start_span();
void end_span();
std::vector<office_element_ptr> current_level_;//
std::vector<odf_text_state> text_elements_list_;//, , ... - ( ?? + ????
private:
paragraph * last_paragraph_;
odf_style_context * styles_context_;
odf_conversion_context *odf_context_;
};
}
}
\ No newline at end of file
......@@ -15,7 +15,7 @@ namespace odf {
ods_conversion_context::ods_conversion_context(package::odf_document * outputDocument)
: odf_conversion_context(outputDocument), ods_table_context_(*this), current_text_context_(NULL)
: odf_conversion_context(outputDocument), table_context_(*this), current_text_context_(NULL)
{
}
......@@ -32,13 +32,13 @@ void ods_conversion_context::start_sheet(std::wstring & name)
{
create_element(L"table", L"table",current_spreadsheet_->getContent(),this);
ods_table_context_.start_table(current_spreadsheet_->getContent().back(),name);
table_context_.start_table(current_spreadsheet_->getContent().back(),name);
}
void ods_conversion_context::end_sheet()
{
ods_table_context_.end_table();
table_context_.end_table();
styles_context().reset_defaults();
}
......@@ -230,9 +230,10 @@ void ods_conversion_context::start_cell(std::wstring & ref, int xfd_style)
}
office_element_ptr style_elm;
int number_format =0;
std::wstring style_cell_name;
office_value_type::type format_value_type = office_value_type::Custom;
if ( xfd_style >=0)
{
odf_style_state *style_state=NULL;
......@@ -240,8 +241,11 @@ void ods_conversion_context::start_cell(std::wstring & ref, int xfd_style)
if (style_state)
{
style_elm = style_state->get_office_element();
number_format = style_state->get_number_format();
style_cell_name = style_state->get_name();
int number_format = style_state->get_number_format();//oox
if (number_format >0)
format_value_type = numbers_styles_context().add_or_find(number_format).ods_type;
}
else
{//error
......@@ -253,7 +257,7 @@ void ods_conversion_context::start_cell(std::wstring & ref, int xfd_style)
current_table().start_cell(cell_elm, style_elm);
current_table().set_cell_format_value(number_format);
current_table().set_cell_format_value(format_value_type);
}
void ods_conversion_context::start_columns()
......
......@@ -38,7 +38,7 @@ public:
void add_merge_cells(std::wstring & ref);
void add_hyperlink(std::wstring & ref, std::wstring & link, std::wstring & display);
///////////////////////////////////////////////////////
ods_table_state & current_table() { return ods_table_context_.state();}
ods_table_state & current_table() { return table_context_.state();}
odf_text_context* current_text_context(){return current_text_context_;}
/////////////////////////////////////////////////////
......@@ -46,12 +46,12 @@ public:
void end_text_context();
private:
ods_table_context ods_table_context_;
ods_table_context table_context_;
odf_text_context* current_text_context_;
office_spreadsheet* current_spreadsheet_;
};
......
......@@ -266,32 +266,7 @@ ods_hyperlink_state & ods_table_state::current_hyperlink()
{
}
}
office_value_type::type oox_valuetype_2_odf(int oox_fmt)
{
switch (oox_fmt)
{
case 2:
case 3:
case 4:
return office_value_type::Float;
case 9:
case 10:
return office_value_type::Percentage;
case 14:
case 15:
case 16:
case 17:
return office_value_type::Date;
case 18:
case 19:
return office_value_type::Time;
case 49:
return office_value_type::String;
case 0://general
default:
return office_value_type::String;
}
}
void ods_table_state::start_cell(office_element_ptr & elm, office_element_ptr & style_elm)
{
current_row_element()->add_child_element(elm);
......@@ -319,16 +294,16 @@ void ods_table_state::start_cell(office_element_ptr & elm, office_element_ptr &
cells_.push_back(state);
}
void ods_table_state::set_cell_format_value(int format_value)
void ods_table_state::set_cell_format_value(office_value_type::type value_type)
{
if (cells_.size() < 1)return;
if (format_value == 0)return; //general .. need detect
if (value_type == office_value_type::Custom)return; //general .. need detect
table_table_cell* cell = dynamic_cast<table_table_cell*>(cells_.back().elm.get());
if (cell == NULL)return;
common_value_and_type_attlist cell_type;
cell_type.office_value_type_ = office_value_type(oox_valuetype_2_odf(format_value));
cell_type.office_value_type_ = office_value_type(value_type);
cell->table_table_cell_attlist_.common_value_and_type_attlist_ = cell_type;
......@@ -343,13 +318,16 @@ void ods_table_state::set_cell_type(int type)
_CP_OPT(office_value_type) cell_type;
switch (type)
{
case 0: //cell_type = office_value_type(office_value_type::Boolean);
case 0: cell_type = office_value_type(office_value_type::Boolean);
break;
case 1: cell_type = office_value_type(office_value_type::Date);
break;
case 4: cell_type = office_value_type(office_value_type::Float);
break;
case 3:
case 5:
case 6:
case 2:// error-type
case 3:// inline
case 5:// shared
case 6://
cell_type = office_value_type(office_value_type::String);
break;
}
......@@ -361,6 +339,10 @@ void ods_table_state::set_cell_type(int type)
}
cell->table_table_cell_attlist_.common_value_and_type_attlist_->office_value_type_ = cell_type;
}
else
{
// - - numFmt
}
}
void ods_table_state::add_hyperlink(std::wstring & ref,int col, int row, std::wstring & link)
{
......@@ -450,7 +432,6 @@ void ods_table_state::set_cell_value(std::wstring & value)
cell->table_table_cell_attlist_.common_value_and_type_attlist_->office_time_value_ = value;
break;
case office_value_type::Currency:
cell->table_table_cell_attlist_.common_value_and_type_attlist_->office_currency_ = value;//
default:
cell->table_table_cell_attlist_.common_value_and_type_attlist_->office_value_ = value;
}
......
......@@ -12,6 +12,8 @@
#include "office_elements.h"
#include "office_elements_create.h"
#include "officevaluetype.h"
namespace cpdoccore {
namespace odf {
......@@ -79,7 +81,7 @@ public:
void end_cell();
void add_default_cell(office_element_ptr & cell, int repeated);
void set_cell_format_value(int format);
void set_cell_format_value(office_value_type::type value_type);
void set_cell_type(int type);
void set_cell_value(std::wstring & value);
......
......@@ -224,7 +224,7 @@ void XlsxConverter::convert(OOX::Spreadsheet::CCell *oox_cell)
ods_context->start_cell(ref,ifx_style);
int value_type = 0;//general
int value_type = -1;//not defined
if (oox_cell->m_oType.IsInit())
{
value_type = oox_cell->m_oType->GetValue();
......@@ -518,24 +518,27 @@ void XlsxConverter::convert_styles()
if (!xlsx_styles)return;
if (!xlsx_styles->m_oCellStyleXfs.IsInit())return;
for (long i=0; xlsx_styles->m_oNumFmts.IsInit() && i< xlsx_styles->m_oNumFmts->m_oCount->GetValue(); i++)//in styles record
{
convert(xlsx_styles->m_oNumFmts->m_arrItems[i]);
}
for (long i=0;i< xlsx_styles->m_oCellStyleXfs->m_oCount->GetValue(); i++)//in styles record
for (long i=0; xlsx_styles->m_oCellStyleXfs.IsInit() && i< xlsx_styles->m_oCellStyleXfs->m_oCount->GetValue(); i++)//in styles record
{
convert(xlsx_styles->m_oCellStyleXfs->m_arrItems[i] , i, false, true);
convert(xlsx_styles->m_oCellStyleXfs->m_arrItems[i] , i, false, true);// ""
}
///////////////////////////////////
for (long i=0;i< xlsx_styles->m_oCellXfs->m_oCount->GetValue(); i++)
for (long i=0; xlsx_styles->m_oCellXfs.IsInit() && i< xlsx_styles->m_oCellXfs->m_oCount->GetValue(); i++)
{
convert(xlsx_styles->m_oCellXfs->m_arrItems[i],i, true,false);
}
for (long i=0;i< xlsx_styles->m_oCellStyles->m_oCount->GetValue(); i++)//styles.xml
for (long i=0; xlsx_styles->m_oCellStyles.IsInit() && i< xlsx_styles->m_oCellStyles->m_oCount->GetValue(); i++)//styles.xml
{
// 1 .. , , ...
//
convert(xlsx_styles->m_oCellStyles->m_arrItems[i],i);
convert(xlsx_styles->m_oCellStyles->m_arrItems[i],i); //
}
}
......@@ -631,11 +634,14 @@ void XlsxConverter::convert(OOX::Spreadsheet::CColor *color, _CP_OPT(odf::backgr
if (odf_color)odf_bckgrd_color = odf::background_color(odf_color.get());
}
void XlsxConverter::convert(OOX::Spreadsheet::CNumFmt *numFmt, odf::style_table_cell_properties * cell_properties)
void XlsxConverter::convert(OOX::Spreadsheet::CNumFmt *numFmt)
{
if (!numFmt)return;
if (numFmt->m_oFormatCode.IsInit() && numFmt->m_oNumFmtId.IsInit())
{
ods_context->numbers_styles_context().add_or_find(numFmt->m_oNumFmtId->GetValue(), string2std_string(numFmt->m_oFormatCode.get()));
}
}
void XlsxConverter::convert(OOX::Spreadsheet::CBorder *border, odf::style_table_cell_properties * cell_properties)
{
......@@ -761,9 +767,9 @@ void XlsxConverter::convert(OOX::Spreadsheet::CXfs * xfc_style, int oox_id, bool
{
OOX::Spreadsheet::CStyles * xlsx_styles = xlsx_document->GetStyles();
int id_parent = xfc_style->m_oXfId.IsInit() ? xfc_style->m_oXfId->GetValue() : -1; //parent
int id_parent = xfc_style->m_oXfId.IsInit() ? xfc_style->m_oXfId->GetValue() : -1;
int fill_id = xfc_style->m_oFillId.IsInit() ? xfc_style->m_oFillId->GetValue() : -1;
int numFmt_id = xfc_style->m_oNumFmtId.IsInit() ? xfc_style->m_oNumFmtId->GetValue(): 0; //general
int numFmt_id = xfc_style->m_oNumFmtId.IsInit() ? xfc_style->m_oNumFmtId->GetValue(): -1;
int font_id = xfc_style->m_oFontId.IsInit() ? xfc_style->m_oFontId->GetValue() : -1;
int border_id = xfc_style->m_oBorderId.IsInit() ? xfc_style->m_oBorderId->GetValue(): -1;
......@@ -780,32 +786,40 @@ void XlsxConverter::convert(OOX::Spreadsheet::CXfs * xfc_style, int oox_id, bool
{
convert(xlsx_styles->m_oFills->m_arrItems[fill_id], table_cell_properties);
}
if (xlsx_styles->m_oNumFmts.IsInit() && numFmt_id>=0 && (id_parent < 0 || xfc_style->m_oApplyNumberFormat.IsInit()))
if (numFmt_id>=0/* && (id_parent < 0 || xfc_style->m_oApplyNumberFormat.IsInit())*/)
{
//if (numFmt_id < xlsx_styles->m_oNumFmts.Count())
//{
// convert(xlsx_styles->m_oNumFmts->m_arrItems[numFmt_id], elm_style);
//}
// .. .. ..
ods_context->styles_context().last_state().set_data_style_name(ods_context->numbers_styles_context().add_or_find(numFmt_id).style_name);
ods_context->styles_context().last_state().set_number_format(numFmt_id);
}
if (xlsx_styles->m_oBorders.IsInit() && border_id >=0 && (id_parent < 0 || xfc_style->m_oApplyBorder.IsInit()))
{
convert(xlsx_styles->m_oBorders->m_arrItems[border_id], table_cell_properties);
}
ods_context->styles_context().last_state().set_number_format(numFmt_id);
if (table_cell_properties)
{//default
table_cell_properties->style_table_cell_properties_attlist_.fo_wrap_option_ = odf::wrap_option(odf::wrap_option::Wrap);
table_cell_properties->style_table_cell_properties_attlist_.style_text_align_source_ = odf::text_align_source(odf::text_align_source::Fix);
//table_cell_properties->style_table_cell_properties_attlist_.style_text_align_source_ = odf::text_align_source(odf::text_align_source::Fix);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (id_parent >=0)
{
ods_context->styles_context().last_state().set_parent_style_name(ods_context->styles_context().find_odf_style_name(id_parent, odf::style_family::TableCell));
odf::odf_style_state *parent_style_state=NULL;
ods_context->styles_context().find_odf_style_state(id_parent, odf::style_family::TableCell,parent_style_state );
if (parent_style_state)
{
ods_context->styles_context().last_state().set_parent_style_name(parent_style_state->get_name());
if (numFmt_id < 0)
{
ods_context->styles_context().last_state().set_number_format(parent_style_state->get_number_format());
}
}
}
}
} // namespace Docx2Odt
\ No newline at end of file
......@@ -76,16 +76,14 @@ namespace Oox2Odf
void convert(OOX::Spreadsheet::CText *oox_text);
void convert(OOX::Spreadsheet::CFormula *oox_formula);
void convert(OOX::Spreadsheet::CHyperlink *oox_hyperlink,OOX::Spreadsheet::CWorksheet *oox_sheet);
void convert(OOX::Spreadsheet::CHyperlink *oox_hyperlink, OOX::Spreadsheet::CWorksheet *oox_sheet);
void convert(OOX::Spreadsheet::CSheetFormatPr *oox_sheet_format_pr);
void convert(OOX::Spreadsheet::CSheetPr *oox_sheet_pr);
void convert(OOX::Spreadsheet::CFont * font, odf::style_text_properties * text_properties);
void convert(OOX::Spreadsheet::CNumFmt *numFmt, odf::style_table_cell_properties * cell_properties);
void convert(OOX::Spreadsheet::CBorder *border, odf::style_table_cell_properties * cell_properties);
void convert(OOX::Spreadsheet::CFill *fill, odf::style_table_cell_properties * cell_properties);
void convert(OOX::Spreadsheet::CFont *font, odf::style_text_properties *text_properties);
void convert(OOX::Spreadsheet::CBorder *border, odf::style_table_cell_properties *cell_properties);
void convert(OOX::Spreadsheet::CFill *fill, odf::style_table_cell_properties *cell_properties);
void convert(OOX::Spreadsheet::CColor *color, _CP_OPT(odf::color) & odf_color);
void convert(OOX::Spreadsheet::CColor *color, _CP_OPT(odf::background_color) & odf_bckgrd_color);
......@@ -93,8 +91,9 @@ namespace Oox2Odf
void convert(double oox_font_size, _CP_OPT(odf::font_size) & odf_font_size);
void convert(double oox_size, _CP_OPT(odf::length) & odf_size);
void convert(OOX::Spreadsheet::CXfs * cell_style, int oox_id, bool automatic=true, bool root = false);
void convert(OOX::Spreadsheet::CCellStyle * cell_style, int oox_id);
void convert(OOX::Spreadsheet::CXfs *cell_style, int oox_id, bool automatic=true, bool root = false);
void convert(OOX::Spreadsheet::CCellStyle *cell_style, int oox_id);
void convert(OOX::Spreadsheet::CNumFmt *numFmt);
void convert_sharing_string(int number);
};
......
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