This commit is contained in:
Elena.Subbotina
2024-03-06 10:15:20 +03:00
parent b88d303ceb
commit 46fc80f423
3 changed files with 38 additions and 32 deletions

View File

@ -929,31 +929,42 @@ void odf_number_styles_context::detect_format(number_format_state & state)
std::wstring strFormatCode = boost::regex_replace(state.format_code[0], re_unwanted, &replace_unwanted, boost::match_any | boost::format_all);
//find [$<Currency String>-<language info>].
boost::wregex re(L"(?=(\\[{1}\\${1}(\\w*)\\-(\\d*)\\]{1}))");
boost::wregex re(L"(\\[\\$.*\-[\\w\\d]+\\])");
std::vector<std::wstring> result;
std::wstring tmp = strFormatCode;
bool b = boost::regex_split(std::back_inserter(result), tmp, re);
if (b && result.size() >= 3)
{
state.currency_str = result[1];
int code = -1;
try
if (b && result.size() > 0)
{//split Currency String
tmp = result[0].substr(1, result[0].size() - 2);
size_t sep = tmp.find(L"-");
if (sep != std::wstring::npos)
{
std::wstringstream ss;
ss << std::hex << result[2];
ss >> state.language_code;
}catch(...){}
state.currency_str = tmp.substr(1, sep - 1);
try
{
std::wstringstream ss;
ss << std::hex << tmp.substr(sep + 1);
ss >> state.language_code;
}
catch (...) {}
}
if (false == state.currency_str.empty())
{
size_t pos_digit = (std::min)(strFormatCode.find(L"0"), strFormatCode.find(L"#"));
size_t pos_currency = strFormatCode.find(state.currency_str);
if (pos_digit != std::wstring::npos) state.currency_pos = pos_digit < pos_currency ? 1 : 2;
}
XmlUtils::replace_all(strFormatCode, result[0], L"");
}
if (state.format_code.size() > 0) //any
{
boost::wregex re1(L"([mM]{2,}|[hH]{2,}|[sS]{2,})");
boost::wregex re2(L"([mM]{1,}|[dD]{1,}|[yY]{2,})");
boost::wregex re1(L"([mM]{2,}|[hH]{1,}|[sS]{2,})");
boost::wregex re2(L"([M]{2,}|[m]{1,}|[dD]{1,}|[yY]{2,})");
tmp = strFormatCode;

View File

@ -49,7 +49,7 @@ typedef shared_ptr<office_element>::Type office_element_ptr;
struct number_format_state
{
int oox_num_fmt;//дефолтные (по документации - номера 0-163, за исключением некоторых)
int oox_num_fmt;//дефолтные
odf_types::office_value_type::type ods_type;
@ -59,6 +59,7 @@ struct number_format_state
unsigned int language_code;
std::wstring currency_str;
unsigned int currency_pos = 0;
};
class odf_number_styles_context
@ -67,7 +68,7 @@ public:
odf_number_styles_context();
void set_odf_context(odf_conversion_context * Context);
number_format_state & add_or_find(int oox_num_fmt, std::wstring formatCode = L"");
number_format_state & add_or_find(int oox_num_fmt, std::wstring formatCode = L"");
void process_styles(office_element_ptr root );
private:
@ -81,7 +82,7 @@ private:
void detect_format(number_format_state & state);
////////////////
odf_conversion_context *odf_context_;
odf_conversion_context *odf_context_;
std::vector<office_element_ptr> styles_elments;
//////////////////
@ -94,8 +95,6 @@ private:
void create_percentage_style(number_format_state & state, office_element_ptr & root_elm);
void create_numbers(number_format_state & state, office_element_ptr & elm, office_element_ptr & root_elm);
};
}
}

View File

@ -100,9 +100,9 @@ namespace utils//////////////////////////////////////////// ОБЩАЯ хрен
}
return convert_date(iDate);
}
std::wstring convert_time(double dTime)
std::wstring convert_time(double dTime, bool bPT)
{
//12H15M42S
//12H15M42S - pt
int hours = 0, minutes = 0;
double sec = 0;
@ -110,23 +110,20 @@ namespace utils//////////////////////////////////////////// ОБЩАЯ хрен
double millisec = day.total_milliseconds() * dTime;
sec = millisec / 1000.;
hours = (int)(sec / 60. / 60.);
minutes = (int)((sec - (hours * 60 * 60)) / 60.);
sec = sec - (hours * 60 + minutes) * 60.;
minutes = (int)((sec - (hours * (int)60 * (int)60)) / 60.);
sec = sec - (hours * (int)60 + minutes) * 60.;
int sec1 = (int)sec;
std::wstring time_str =
(hours < 10 ? L"0" : L"") + boost::lexical_cast<std::wstring>(hours)
//+ std::wstring(L"H") +
+ std::wstring(L":") +
+ (bPT ? std::wstring(L"H") : std::wstring(L":")) +
(minutes < 10 ? L"0" : L"") + boost::lexical_cast<std::wstring>(minutes)
//+ std::wstring(L"M") +
+ std::wstring(L":") +
(sec1 < 10 ? L"0" : L"") + boost::lexical_cast<std::wstring>(sec1);
//+ std::wstring(L"S");
+ (bPT ? std::wstring(L"M") : std::wstring(L":")) +
(sec1 < 10 ? L"0" : L"") + boost::lexical_cast<std::wstring>(sec1)
+ (bPT ? std::wstring(L"S") : std::wstring(L""));
return time_str;
}
@ -148,7 +145,7 @@ namespace utils//////////////////////////////////////////// ОБЩАЯ хрен
std::wstring sDate, sTime;
if (dTime > 0)
{
sTime = convert_time(dTime);
sTime = convert_time(dTime, false);
}
if (nDate > 0)
{
@ -173,8 +170,7 @@ namespace utils//////////////////////////////////////////// ОБЩАЯ хрен
{
return oox_time;
}
//PT12H15M42S
return std::wstring(L"PT") + convert_time(dTime);
return std::wstring(L"PT") + convert_time(dTime, true);
}
};