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

формулы xlsx->ods

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@55390 954022d7-b5bf-4e40-9824-e11837661b57
parent 274f2b59
......@@ -39,7 +39,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;$(ProjectDir)include&quot;;&quot;$(SolutionDir)include&quot;;&quot;$(SolutionDir)3dparty\gtest\include\&quot;;&quot;$(SolutionDir)3dparty\utf8cpp\include&quot;"
AdditionalIncludeDirectories="&quot;$(ProjectDir)include&quot;;..\include;..\3dparty\gtest\include\;..\dparty\utf8cpp\include"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
......@@ -102,7 +102,7 @@
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;$(ProjectDir)include&quot;;&quot;$(SolutionDir)include&quot;;&quot;$(SolutionDir)3dparty\gtest\include\&quot;;&quot;$(SolutionDir)3dparty\utf8cpp\include&quot;"
AdditionalIncludeDirectories="&quot;$(ProjectDir)include&quot;;..\include;..\3dparty\gtest\include\;..\3dparty\utf8cpp\include"
RuntimeLibrary="2"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
......@@ -148,7 +148,11 @@
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\src\formulasconvert.cpp"
RelativePath=".\src\formulasconvert_odf.cpp"
>
</File>
<File
RelativePath=".\src\formulasconvert_oox.cpp"
>
</File>
</Filter>
......
#ifndef _CPDOCCORE_FORMULASCONVERT_H_
#define _CPDOCCORE_FORMULASCONVERT_H_
#pragma once
#include <string>
#include <cpdoccore/CPScopedPtr.h>
......@@ -41,8 +40,37 @@ private:
_CP_SCOPED_PTR(Impl) impl_;
};
class oox2odf_converter
{
public:
oox2odf_converter();
~oox2odf_converter();
// SUM(DDA1:BA3) -> of:=SUM([.DDA1:.BA3])
std::wstring convert(std::wstring const & expr);
std::wstring convert_formula(std::wstring const & expr);
// 1!$A$1 -> $1.$A$1
std::wstring convert_named_ref(std::wstring const & expr);
//Sheet2!C3:C19 -> Sheet2.C3:Sheet2.C19
std::wstring convert_chart_distance(std::wstring const & expr);
std::wstring convert_ref(std::wstring const & expr);
std::wstring convert_spacechar(std::wstring expr);
// // =[.A1]+[.B1] -> table = ""; ref = "A1"
// // of:=['Sheet2 A'.B2] -> table= "Sheet2 A"; ref = "B2"
// bool find_first_ref(std::wstring const & expr, std::wstring & table, std::wstring & ref);
////ref $A$1 -> ref $A$2 -> Table!.$A$1:$A2
//bool find_first_last_ref(std::wstring const & expr, std::wstring & table, std::wstring & ref_first,std::wstring & ref_last);
private:
class Impl;
_CP_SCOPED_PTR(Impl) impl_;
};
}
}
#endif
#include <cpdoccore/formulasconvert.h>
#include <boost/algorithm/string.hpp>
#include <boost/regex.hpp>
#include <boost/foreach.hpp>
namespace cpdoccore {
namespace formulasconvert {
class oox2odf_converter::Impl
{
public:
std::wstring convert(const std::wstring& expr);
std::wstring convert_formula(const std::wstring& expr);
std::wstring convert_chart_distance(const std::wstring& expr);
static void replace_cells_range(std::wstring& expr);
static void replace_semicolons(std::wstring& expr);
static void replace_vertical(std::wstring& expr);
static void replace_space(std::wstring& expr);
static std::wstring replace_cells_range_formater(boost::wsmatch const & what);
static std::wstring replace_arguments(boost::wsmatch const & what);
void replace_named_ref(std::wstring & expr);
// bool find_first_ref(std::wstring const & expr, std::wstring & table, std::wstring & ref);
//bool find_first_last_ref(std::wstring const & expr, std::wstring & table, std::wstring & ref_first,std::wstring & ref_last);
};
////Table!.$A$1:$A2 -> ref $A$1 -> ref $A$2
//bool oox2odf_converter::Impl::find_first_last_ref(std::wstring const & expr, std::wstring & table,std::wstring & ref_first,std::wstring & ref_last)
//{
// std::vector< std::wstring > splitted;
//
// boost::algorithm::split(splitted, expr, boost::algorithm::is_any_of(L".:"), boost::algorithm::token_compress_on);
//
// if (splitted.size()>2)
// {
// table = splitted[0];
// ref_first = splitted[1];
// ref_last = splitted[2];
// return true;
// }
// return false;
//}
// // =[.A1]+[.B1] -> table = ""; ref = "A1"
// // of:=['Sheet2 A'.B2] -> table= "Sheet2 A"; ref = "B2"
//
//bool oox2odf_converter::Impl::find_first_ref(std::wstring const & expr, std::wstring & table, std::wstring & ref)
//{
// boost::wregex re(L"\\[(?:\\$)?([^\\.]+?){0,1}\\.([a-zA-Z\\$]+\\d+)(?::\\.([a-zA-Z]+\\d+)){0,1}\\]");
// boost::wsmatch result;
// bool b = boost::regex_search(expr, result, re);
//
// size_t sz = result.size();
// if (sz == 4 && !result[1].matched)
// {
// table = L"";
// ref = result[2].str();
// return true;
// }
// else if (sz == 4 && result[1].matched)
// {
// table = result[1].str();
// boost::algorithm::replace_all(table, L"$", L"");
// boost::algorithm::replace_all(table, L"'", L"");
// ref = result[2].str();
// return true;
// }
// return false;
//}
//
//namespace
//{
//
//std::wstring replace_cell_range_formater(boost::wsmatch const & what)
//{
// const size_t sz = what.size();
// if (sz == 4 && !what[1].matched)
// {
// const std::wstring c1 = what[2].str();
// const std::wstring c2 = what[3].str();
// const std::wstring s = c1 + (c2.empty() ? L"" : (L":" + c2) );
// return s;
// }
// else if (sz == 4 && what[1].matched)
// {
// std::wstring sheet1 = what[1].str();
// boost::algorithm::replace_all(sheet1, L"$", L"");
//
// const std::wstring c1 = what[2].str();
// const std::wstring c2 = what[3].str();
// const std::wstring s = sheet1 + L"!" + c1 + (c2.empty() ? L"" : (L":" + c2) );
// return s;
// }
// return L"";
//}
//
//}
//
// çàìåíÿåì ôîðìàò àäðåñàöèè ÿ÷ååê ÍÀÎÁÎÐÎÒ
// [.A1] -> A1
// [.A1:.B5] -> A1:B5
// [Sheet2.A1:B5] -> Sheet2!A1:B5
// [Sheet2.A1] -> Sheet2!A1
// [$'Sheet2 A'.$B2] -> 'Sheet2 A'!$B2
void oox2odf_converter::Impl::replace_cells_range(std::wstring& expr)
{
boost::wregex re(L"([a-zA-Z$ ']+[0-9]+)?\\!?([a-zA-Z$]+\\d+)?\\:?([a-zA-Z$]+\\d+)?");
//boost::wsmatch result;
//bool b = boost::regex_search(expr, result, re);
std::wstring workstr = expr;
const std::wstring res = boost::regex_replace(
workstr,
re,
&replace_cells_range_formater,
boost::match_default | boost::format_all);
expr = res;
return;
}
std::wstring oox2odf_converter::Impl::replace_cells_range_formater(boost::wsmatch const & what)
{
const size_t sz = what.size();
if (what[1].matched && what[2].matched && what[3].matched)
{
//std::vector< std::wstring > splitted;
//
//boost::algorithm::split(splitted, what[0], boost::algorithm::is_any_of(L"!"), boost::algorithm::token_compress_on);
//
//std::wstring table;
//std::wstring ref;
//if (splitted.size()>1)
//{
// table = splitted[0];
// ref = splitted[1];
//}
//else if (splitted.size()==1)
//{
// ref = splitted[0];
//}
//std::wstring expr = std::wstring(L"[") + table + std::wstring(L".") + ref + std::wstring(L"]");
std::wstring sheet1 = what[1].str();
boost::algorithm::replace_all(sheet1, L"$", L"");
const std::wstring c1 = what[2].str();
const std::wstring c2 = what[3].str();
const std::wstring s = std::wstring(L"[") + sheet1 + L"." + c1 + (c2.empty() ? L"" : (L":" + c2) ) + std::wstring(L"]");
return s;
}
else if ((what[1].matched || what[2].matched) && what[3].matched)
{
const std::wstring c1 = what[1].matched ? what[1].str() : what[2].str();
const std::wstring c2 = what[3].str();
const std::wstring s = std::wstring(L"[") + c1 + (c2.empty() ? L"" : (L":" + c2) )+ std::wstring(L"]");
return s;
}
else if (what[1].matched || what[2].matched)
{
return what[1].matched ? what[1].str() : what[2].str();
}
//if (!what[1].matched)
// return L"";
//else if (
//{
// }
// else
return L"";
}
//namespace {
//
//std::wstring replace_named_ref_formater(boost::wsmatch const & what)
//{
// const size_t sz = what.size();
//
// if (sz == 4 && !what[1].matched)
// {
// const std::wstring c1 = what[2].str();
// const std::wstring c2 = what[3].str();
// const std::wstring s = c1 + (c2.empty() ? L"" : (L":" + c2) );
// return s;
// }
// else if (sz == 4 && what[1].matched)
// {
// std::wstring sheet1 = what[1].str();
// boost::algorithm::replace_all(sheet1, L"$", L"");
//
// const std::wstring c1 = what[2].str();
// const std::wstring c2 = what[3].str();
// const std::wstring s = sheet1 + L"!" + c1 + (c2.empty() ? L"" : (L":" + c2) );
// return s;
// }
// return L"";
//}
//
//}
// Ëèñò1!$A$1 -> $Ëèñò1.$A$1
void oox2odf_converter::Impl::replace_named_ref(std::wstring & expr)
{
std::vector< std::wstring > splitted;
boost::algorithm::split(splitted, expr, boost::algorithm::is_any_of(L"."), boost::algorithm::token_compress_on);
std::wstring table;
std::wstring ref;
if (splitted.size()>1)
{
table= splitted[0];
ref = splitted[1];
boost::algorithm::replace_all(table, L"$", L"");
expr = table +std::wstring(L"!") + ref;
}
else if (splitted.size()==1)
{
ref = splitted[0];
expr = ref;
}
}
namespace
{
std::wstring replace_semicolons_formater(boost::wsmatch const & what)
{
if (what[1].matched)
return L";";
else if (what[2].matched)
return what[2].str();
else if (what[3].matched)
return what[3].str();
//else if (what[4].matched)
// return what[4].str();
else
return L"";
}
}
// TODO
// çàìåíèòü çàïÿòûå íà òî÷êè ñ çàïÿòîé âî âñåõ âõîæäåíèÿõ êðîìå íàõîäÿùèõñÿ â êàâû÷êàõ --*è â ôèãóðíûõ ñêîáêàõ*--
// TODO: ïðîâåðèòü êàê ñîõðàíÿþòñÿ êàâû÷êè â ñòðîêå
void oox2odf_converter::Impl::replace_semicolons(std::wstring& expr)
{
const std::wstring res = boost::regex_replace(
expr,
//boost::wregex(L"(;)|(?:\".*?\")|(?:'.*?')"),
boost::wregex(L"(,)|(\".*?\")|('.*?')"),
&replace_semicolons_formater,
boost::match_default | boost::format_all);
expr = res;
}
namespace
{
std::wstring replace_vertical_formater(boost::wsmatch const & what)
{
if (what[1].matched)
{
std::wstring inner = what[1].str();
boost::algorithm::replace_all(inner, L";", L"|");
return L"{" + inner + L"}";
}
else if (what[2].matched)
return what[2].str();
else if (what[3].matched)
return what[3].str();
}
std::wstring replace_space_formater(boost::wsmatch const & what)
{
if (what[1].matched)
{
std::wstring inner = what[1].str();
boost::algorithm::replace_all(inner, L",", L" ");
return inner;
}
else if (what[2].matched)
return what[2].str();
else if (what[3].matched)
return what[3].str();
}
}
std::wstring forbidden_formulas1[] =
{
L"NULLFORMULA()"
/*
L"BETADIST",
L"CEILING",
L"FLOOR",
L"RANK",
L"ROUND",
L"ROUNDDOWN",
L"ROUNDUP",
L"SUBTOTAL",
L"FORMULA",
L"ISREF"*/
};
bool is_forbidden1(const std::wstring & formula)
{
BOOST_FOREACH(const std::wstring & s, forbidden_formulas1)
{
if (boost::algorithm::contains(formula, s))
return true;
}
return false;
}
// çàìåíèòü âåðòèêàëüíóþ ÷åðòó âî âñåõ âõîæäåíèÿõ â ôèãóðíûõ ñêîáêàõ, íî íå âíóòðè ñòðîê
void oox2odf_converter::Impl::replace_vertical(std::wstring& expr)
{
const std::wstring res = boost::regex_replace(
expr,
boost::wregex(L"(?:(?:\\{)([^\\}]*?)(?:\\}))|(\".*?\")|('.*?')"),
&replace_vertical_formater,
boost::match_default | boost::format_all);
expr = res;
}
// çàìåíèòü çàïÿòóþ âî âñåõ âõîæäåíèÿõ íà ïðîáåë
void oox2odf_converter::Impl::replace_space(std::wstring& expr)
{
const std::wstring res = boost::regex_replace(
expr,
boost::wregex(L"(?:(?:\\{)([^\\}]*?)(?:\\}))|(\".*?\")|('.*?')"),
&replace_space_formater,
boost::match_default | boost::format_all);
expr = res;
}
std::wstring replace_(boost::wsmatch const & what)
{
if (what[1].matched)
{
std::wstring inner = what[1].str();
boost::algorithm::replace_all(inner, L",", L" ");
return inner;
}
else if (what[2].matched)
return what[2].str();
else if (what[3].matched)
return what[3].str();
}
std::wstring oox2odf_converter::Impl::replace_arguments(boost::wsmatch const & what)
{
if (what[1].matched)
{
std::wstring workstr = what[1].str(), out;
replace_vertical(workstr);
replace_semicolons(workstr);
std::vector<std::wstring> distance;
boost::algorithm::split(distance,workstr, boost::algorithm::is_any_of(L";"), boost::algorithm::token_compress_on);
BOOST_FOREACH(std::wstring &d, distance)
{
replace_cells_range(d);
out = out + d + std::wstring(L";");
}
if (out.length()>0) out = out.substr(0,out.length()-1);
return std::wstring(L"(") + out + std::wstring(L")") ;
}
else if (what[2].matched)
return what[2].str();
else if (what[3].matched)
return what[3].str();
}
std::wstring oox2odf_converter::Impl::convert(const std::wstring& expr)
{
if (is_forbidden1(expr))
return L"NULLFORMULA";
std::wstring workstr = expr;
replace_cells_range(workstr);
replace_vertical(workstr);
replace_semicolons(workstr);
return workstr;
}
// of:=(Formula) -> (Formula)
std::wstring oox2odf_converter::Impl::convert_formula(const std::wstring& expr)
{
if (is_forbidden1(expr))
return L"NULLFORMULA";
std::wstring workstr = expr;
const std::wstring res = boost::regex_replace(
workstr,
boost::wregex(L"(?:(?:\\()([^\\)]*?)(?:\\)))|(\".*?\")|('.*?')"),
&oox2odf_converter::Impl::replace_arguments,
boost::match_default | boost::format_all);
return std::wstring(L"of:=") + res;
}
//Sheet2!C3:C19,Sheet2!L27:L34
//â
//Sheet2.C3:Sheet2.C19 Sheet2.L29:Sheet2.L36
//todooo
std::wstring oox2odf_converter::Impl::convert_chart_distance(const std::wstring& expr)
{
if (is_forbidden1(expr))
return L"NULLFORMULA()";
//std::wstring workstr = expr;
//replace_space(workstr);
//return workstr;
//ðàñïàðñèòü ïî äèàïàçîíàì - îäô-ïðîáåë, èê-ýëü-çàïÿòàÿ
std::vector<std::wstring> distance_inp;
std::vector<std::wstring> distance_out;
boost::algorithm::split(distance_inp,expr, boost::algorithm::is_any_of(L" "), boost::algorithm::token_compress_on);
BOOST_FOREACH(std::wstring &d,distance_inp)
{
std::wstring sheet;
std::vector<std::wstring> range;
std::vector<std::wstring> cells;
boost::algorithm::split(range,d, boost::algorithm::is_any_of(L":"), boost::algorithm::token_compress_on);
BOOST_FOREACH(std::wstring &c,range)
{
const ::std::string::size_type colon = c.find('.');
cells.push_back(c.substr(colon+1));
if (sheet.size()<1)
sheet=c.substr(0, colon);
}
std::wstring cells_out;
BOOST_FOREACH(std::wstring &c,cells)
{
cells_out.append(c);
cells_out.append(L":");
}
int res1 = sheet.find(L"-");
int res2 = sheet.find(L"'");
if (res1>=0 && !(res2==0))
{
sheet = L"'" + sheet + L"'";
}
distance_out.push_back(sheet+L"!"+cells_out.substr(0, cells_out.size()-1));
}
std::wstring result;
BOOST_FOREACH(std::wstring &d,distance_out)
{
result.append(d);
result.append(L",");
}
return result.substr(0, result.size()-1);
}
oox2odf_converter::oox2odf_converter(): impl_(new oox2odf_converter::Impl)
{
}
oox2odf_converter::~oox2odf_converter()
{
}
std::wstring oox2odf_converter::convert(const std::wstring& expr)
{
return impl_->convert(expr);
}
std::wstring oox2odf_converter::convert_formula(const std::wstring& expr)
{
return impl_->convert_formula(expr);
}
std::wstring oox2odf_converter::convert_chart_distance(const std::wstring& expr)
{
return impl_->convert_chart_distance(expr);
}
std::wstring oox2odf_converter::convert_named_ref(const std::wstring& expr)
{
std::wstring workstr = expr;
impl_->replace_named_ref(workstr);
return workstr;
}
std::wstring oox2odf_converter::convert_ref(std::wstring const & expr)
{
std::wstring workstr = expr;
impl_->replace_cells_range(workstr);
return workstr;
}
std::wstring oox2odf_converter::convert_spacechar(std::wstring expr)
{
while(true)
{
int pos = expr.find(L"%20");
if (pos <0)break;
expr.replace(pos,3,L" ");
}
return expr;
}
//bool oox2odf_converter::find_first_ref(std::wstring const & expr, std::wstring & table, std::wstring & ref)
//{
// return impl_->find_first_ref(expr, table, ref);
//}
//bool oox2odf_converter::find_first_last_ref(std::wstring const & expr, std::wstring & table, std::wstring & ref_first,std::wstring & ref_last)
//{
// return impl_->find_first_last_ref(expr, table, ref_first,ref_last);
//}
}
}
......@@ -9,11 +9,14 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DocxFormat", "..\Common\DocxFormat\Projects\DocxFormat2005.vcproj", "{A100103A-353E-45E8-A9B8-90B87CC5C0B0}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OdfFormat", "source\OdfFormat.vcproj", "{E5A67556-44DA-4481-8F87-0A3AEDBD20DD}"
ProjectSection(ProjectDependencies) = postProject
{94954A67-A853-43B1-A727-6EF2774C5A6A} = {94954A67-A853-43B1-A727-6EF2774C5A6A}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Oox2OdfConverter", "source\Oox2OdfConverter.vcproj", "{BEE01B53-244A-44E6-8947-ED9342D9247E}"
ProjectSection(ProjectDependencies) = postProject
{E5A67556-44DA-4481-8F87-0A3AEDBD20DD} = {E5A67556-44DA-4481-8F87-0A3AEDBD20DD}
{A100103A-353E-45E8-A9B8-90B87CC5C0B0} = {A100103A-353E-45E8-A9B8-90B87CC5C0B0}
{E5A67556-44DA-4481-8F87-0A3AEDBD20DD} = {E5A67556-44DA-4481-8F87-0A3AEDBD20DD}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ASCOfficeOdfFileWTest", "ASCOfficeOdfFileWTest\ASCOfficeOdfFileWTest.vcproj", "{FBA8446A-150F-4A10-B4DA-1022048D6473}"
......@@ -21,6 +24,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ASCOfficeOdfFileWTest", "AS
{6258296E-ABCE-4BC6-9F4A-8522CD615603} = {6258296E-ABCE-4BC6-9F4A-8522CD615603}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cpformulasconvert", "..\ASCOfficeOdfFile\formulasconvert\formulasconvert.vcproj", "{94954A67-A853-43B1-A727-6EF2774C5A6A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
......@@ -47,6 +52,10 @@ Global
{FBA8446A-150F-4A10-B4DA-1022048D6473}.Debug|Win32.Build.0 = Debug|Win32
{FBA8446A-150F-4A10-B4DA-1022048D6473}.Release|Win32.ActiveCfg = Release|Win32
{FBA8446A-150F-4A10-B4DA-1022048D6473}.Release|Win32.Build.0 = Release|Win32
{94954A67-A853-43B1-A727-6EF2774C5A6A}.Debug|Win32.ActiveCfg = Debug|Win32
{94954A67-A853-43B1-A727-6EF2774C5A6A}.Debug|Win32.Build.0 = Debug|Win32
{94954A67-A853-43B1-A727-6EF2774C5A6A}.Release|Win32.ActiveCfg = Release|Win32
{94954A67-A853-43B1-A727-6EF2774C5A6A}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
......@@ -40,7 +40,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\ASCOfficeOdfFile\include;..\..\ASCOfficeOdfFile\3dparty\utf8cpp\include;..\..\ASCOfficeOdfFile\src\odf\datatypes;.\OdfFormat"
AdditionalIncludeDirectories="..\..\ASCOfficeOdfFile\include;..\..\ASCOfficeOdfFile\3dparty\utf8cpp\include;..\..\ASCOfficeOdfFile\src\odf\datatypes;.\OdfFormat;..\..\ASCOfficeOdfFile\formulasconvert\include"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
MinimalRebuild="true"
BasicRuntimeChecks="3"
......@@ -105,7 +105,7 @@
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="..\..\ASCOfficeOdfFile\include;..\..\ASCOfficeOdfFile\3dparty\utf8cpp\include;..\..\ASCOfficeOdfFile\src\odf\datatypes;.\OdfFormat"
AdditionalIncludeDirectories="..\..\ASCOfficeOdfFile\include;..\..\ASCOfficeOdfFile\3dparty\utf8cpp\include;..\..\ASCOfficeOdfFile\src\odf\datatypes;.\OdfFormat;..\..\ASCOfficeOdfFile\formulasconvert\include"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
......
#include "precompiled_cpodf.h"
#include "logging.h"
#include <cpdoccore/formulasconvert.h>
#include "ods_table_state.h"
#include "odf_text_context.h"
#include "ods_conversion_context.h"
......@@ -23,7 +25,15 @@ namespace utils
{
std::wstring convert_date(std::wstring & oox_date)
{
int iDate = boost::lexical_cast<int>(oox_date);
int iDate = 0;
try
{
iDate = boost::lexical_cast<int>(oox_date);
}catch(...)
{
return oox_date;
}
boost::gregorian::date date_ = boost::gregorian::date(1900, 1, 1) + boost::gregorian::date_duration(iDate-2);
......@@ -38,10 +48,19 @@ std::wstring convert_date(std::wstring & oox_date)
std::wstring convert_time(std::wstring & oox_time)
{
double dTime = 0;
try
{
dTime = boost::lexical_cast<double>(oox_time);
}catch(...)
{
return oox_time;
}
//PT12H15M42S
int hours=0, minutes=0;
double sec=0;
double dTime = boost::lexical_cast<double>(oox_time);
boost::posix_time::time_duration day(24, 0, 0);
......@@ -447,6 +466,17 @@ void ods_table_state::set_merge_cells(int start_col, int start_row, int end_col,
}
}
}
static formulasconvert::oox2odf_converter formulas_converter;
void ods_table_state::set_cell_formula(std::wstring & formula)
{
std::wstring odfFormula = formulas_converter.convert_formula(formula);
table_table_cell* cell = dynamic_cast<table_table_cell*>(cells_.back().elm.get());
if (cell == NULL)return;
cell->table_table_cell_attlist_.table_formula_ = odfFormula;
}
void ods_table_state::set_cell_text(odf_text_context* text_context)
{
......
......@@ -84,8 +84,8 @@ public:
void set_cell_format_value(office_value_type::type value_type);
void set_cell_type(int type);
void set_cell_value(std::wstring & value);
void set_cell_text(odf_text_context *text_context);
void set_cell_formula(std::wstring &formula);
///////////////////////////////
void add_hyperlink(std::wstring & ref,int col, int row, std::wstring & link);
......
......@@ -385,6 +385,7 @@ void XlsxConverter::convert(OOX::Spreadsheet::CFormula *oox_formula)
{
if (oox_formula == NULL)return;
ods_context->current_table().set_cell_formula(string2std_string(oox_formula->m_sText));
}
void XlsxConverter::convert(OOX::Spreadsheet::CCol *oox_column)
{
......
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