Commit 6afc38c8 authored by ElenaSubbotina's avatar ElenaSubbotina

XlsFormat - fix after tesing, pivot external links, pivot consolidations

parent 31363e8f
......@@ -31,14 +31,14 @@
*/
#include "DConRef.h"
#include "../../../../../Common/DocxFormat/Source/XML/Utils.h"
namespace XLS
{
DConRef::DConRef()
{
bFilePath = false;
bSheetName = false;
index_external = -1;
}
......@@ -54,6 +54,8 @@ BaseObjectPtr DConRef::clone()
void DConRef::readFields(CFRecord& record)
{
GlobalWorkbookInfoPtr global_info_ = record.getGlobalWorkbookInfo();
record >> ref >> cchFile;
if (cchFile > 1)
......@@ -68,39 +70,96 @@ void DConRef::readFields(CFRecord& record)
stFile = stFile_.value();
std::wstring sTmp = stFile;
while(true)
{
bool bDel = false;
int pos = stFile.find(L"\x0001");
int pos = sTmp.find(L"\x0001");
if (pos >= 0)
{
bDel = true;
stFile = stFile.substr(pos + 1);
path.push_back(sTmp.substr(0, pos));
sTmp = sTmp.substr(pos + 1);
continue;
}
pos = stFile.find(L"\x0002");
pos = sTmp.find(L"\x0002");
if (pos >= 0)
{
bDel = true;
stFile = stFile.substr(pos + 1);
path.push_back(sTmp.substr(0, pos));
sTmp = sTmp.substr(pos + 1);
continue;
}
pos = stFile.find(L"\x0003");
pos = sTmp.find(L"\x0003");
if (pos >= 0)
{
bDel = true;
stFile = stFile.substr(pos + 1);
path.push_back(sTmp.substr(0, pos));
sTmp = sTmp.substr(pos + 1);
continue;
}
if (!bDel)
break;
}
int pos = stFile.find(L"]");
int pos = sTmp.find(L"]");
if (pos >= 0)
{
stFile = stFile.substr(pos + 1);
file_name = sTmp.substr(1, pos - 1);
sheet_name = sTmp.substr(pos + 1);
}
else
{
sheet_name = sTmp;
}
}
int unused = record.getDataSize() - record.getRdPtr();
record.skipNunBytes(unused);
bool bFound = false;
for (size_t i = 0; i < global_info_->sheets_names.size(); i++) // todooo отдельно???
{
if (global_info_->sheets_names[i] == sheet_name)
{
bFound = true;
break;
}
}
if (!bFound && (!path.empty() || !file_name.empty()))
{//external sheet
std::wstring full_path;
if (!path.empty())
{
full_path = get_external_path();
}
std::unordered_map<std::wstring, std::wstring>::iterator pFind = global_info_->mapPivotCacheExternal.find(file_name);
if (pFind == global_info_->mapPivotCacheExternal.end())
{
index_external = global_info_->mapPivotCacheExternal.size() ;
global_info_->mapPivotCacheExternal.insert(std::make_pair(file_name, full_path));
}
else
{
if (pFind->second.empty() && !full_path.empty())
{
pFind->second = full_path;
}
index_external = std::distance( global_info_->mapPivotCacheExternal.begin(), pFind) ;
}
}
}
std::wstring DConRef::get_external_path()
{
std::wstring result = L"file:///";
for (size_t i = 0; i < path.size(); i++)
{
result += L"\\" + path[i];
}
if (!file_name.empty())
result += L"\\" + file_name;
return result;
}
} // namespace XLS
......
......@@ -57,9 +57,13 @@ public:
unsigned short cchFile;
std::wstring stFile;
bool bFilePath;
bool bSheetName;
std::vector<std::wstring> path;
std::wstring file_name;
std::wstring sheet_name;
int index_external;
private:
std::wstring get_external_path();
};
} // namespace XLS
......
......@@ -72,6 +72,20 @@ int SXDI::serialize(std::wostream & strm)
CP_XML_ATTR(L"baseField", df);
CP_XML_ATTR(L"baseItem", isxvi);
CP_XML_ATTR(L"numFmtId", ifmt);
switch(iiftab)
{
case 0x0000: CP_XML_ATTR(L"subtotal", L"sum"); break;
case 0x0001: CP_XML_ATTR(L"subtotal", L"count"); break;
case 0x0002: CP_XML_ATTR(L"subtotal", L"average"); break;
case 0x0003: CP_XML_ATTR(L"subtotal", L"max"); break;
case 0x0004: CP_XML_ATTR(L"subtotal", L"min"); break;
case 0x0005: CP_XML_ATTR(L"subtotal", L"product"); break;
case 0x0006: CP_XML_ATTR(L"subtotal", L"countNums");break;
case 0x0007: CP_XML_ATTR(L"subtotal", L"stdDev"); break;
case 0x0008: CP_XML_ATTR(L"subtotal", L"stdDevp"); break;
case 0x0009: CP_XML_ATTR(L"subtotal", L"var"); break;
case 0x000a: CP_XML_ATTR(L"subtotal", L"varp"); break;
}
}
}
return 0;
......
......@@ -120,7 +120,12 @@ int DREF::serialize(std::wostream & strm)
CP_XML_NODE(L"worksheetSource")
{
CP_XML_ATTR(L"ref", ref->ref.toString());
CP_XML_ATTR(L"sheet", ref->stFile);
CP_XML_ATTR(L"sheet", ref->sheet_name);
if (ref->index_external >= 0)
{
CP_XML_ATTR(L"r:id", L"extId" + std::to_wstring(ref->index_external + 1));
}
}
}
}
......
......@@ -31,7 +31,7 @@
*/
#pragma once
#include <Logic/CompositeObject.h>
#include "../CompositeObject.h"
namespace XLS
{
......
......@@ -250,14 +250,16 @@ int FDB::serialize(std::wostream & strm, bool bSql)
// }
//}
if ((bDate & bNumber) || (bNumber & bString))
if ((bDate & bNumber) || (bNumber & bString & !bEmpty))
{
CP_XML_ATTR(L"containsSemiMixedTypes", 1);
}
else if ((bDate & bString) || ((bEmpty || !bNumber) & bInteger & bString))
{
if (bInteger) bNumber = true;
CP_XML_ATTR(L"containsMixedTypes", 1);
if (bInteger) bNumber = true;
if (bEmpty && bNumber) bInteger = false;
}
else if (!bEmpty && !bString && !bBool)
{
......
......@@ -205,43 +205,48 @@ int PIVOTVIEW::serialize(std::wostream & strm)
}
}
}
if (!core->m_arPIVOTIVD.empty())
int index_ivd = 0;
int index_tli = 0;
if (view->cDimRw > 0 && index_ivd < core->m_arPIVOTIVD.size())
{
CP_XML_NODE(L"rowFields")
{
CP_XML_ATTR(L"count", view->cDimRw);
PIVOTIVD* ivd = dynamic_cast<PIVOTIVD*>(core->m_arPIVOTIVD[0].get());
PIVOTIVD* ivd = dynamic_cast<PIVOTIVD*>(core->m_arPIVOTIVD[index_ivd].get());
ivd->serialize(CP_XML_STREAM());
index_ivd++;
}
}
if (!core->m_arPIVOTLI.empty())//0 or 2
if (view->cRw > 0 && index_tli < core->m_arPIVOTLI.size())
{
CP_XML_NODE(L"rowItems")
{
CP_XML_ATTR(L"count", view->cRw);
PIVOTLI* line = dynamic_cast<PIVOTLI*>(core->m_arPIVOTLI[0].get());
PIVOTLI* line = dynamic_cast<PIVOTLI*>(core->m_arPIVOTLI[index_tli].get());
line->serialize(CP_XML_STREAM());
index_tli++;
}
}
if (core->m_arPIVOTIVD.size() == 2)//0 or 2
if (view->cDimCol > 0 && index_ivd < core->m_arPIVOTIVD.size())
{
CP_XML_NODE(L"colFields")
{
CP_XML_ATTR(L"count", view->cDimCol);
PIVOTIVD* ivd = dynamic_cast<PIVOTIVD*>(core->m_arPIVOTIVD[1].get());
PIVOTIVD* ivd = dynamic_cast<PIVOTIVD*>(core->m_arPIVOTIVD[index_ivd].get());
ivd->serialize(CP_XML_STREAM());
}
}
if (core->m_arPIVOTLI.size() == 2)//0 or 2
if (view->cCol > 0 && index_tli < core->m_arPIVOTLI.size())
{
CP_XML_NODE(L"colItems")
{
CP_XML_ATTR(L"count", view->cCol);
PIVOTLI* line = dynamic_cast<PIVOTLI*>(core->m_arPIVOTLI[1].get());
PIVOTLI* line = dynamic_cast<PIVOTLI*>(core->m_arPIVOTLI[index_tli].get());
line->serialize(CP_XML_STREAM());
}
}
......
......@@ -98,6 +98,7 @@ const bool SXOPER::loadContent(BinProcessor& proc)
{
SxErr* err = dynamic_cast<SxErr*>(elements_.back().get());
//bNumber = true;
bString = true;
node = L"e";
value = L"#VALUE!";//std::to_wstring(err->wbe);
}
......
......@@ -156,7 +156,7 @@ int SXTBL::serialize(std::wostream & strm)
for (size_t j = 0; j < m_arSXTBRGIITM[i].strings.size(); j++)
{
SXString* str = dynamic_cast<SXString*>(m_arSXTBRGIITM[i].strings[i].get());
SXString* str = dynamic_cast<SXString*>(m_arSXTBRGIITM[i].strings[j].get());
CP_XML_NODE(L"pageItem")
{
CP_XML_ATTR(L"name", str->segment.value());
......@@ -183,6 +183,36 @@ int SXTBL::serialize(std::wostream & strm)
{
CP_XML_ATTR(L"name", name->stName.value());
}
if (bin)
{
switch(bin->nBuiltin)
{
case 0x0000: CP_XML_ATTR(L"name", L"_xlnm.Consolidate_Area"); break;
case 0x0001: CP_XML_ATTR(L"name", L"_xlnm.Auto_Open"); break;
case 0x0002: CP_XML_ATTR(L"name", L"_xlnm.Auto_Close"); break;
case 0x0003: CP_XML_ATTR(L"name", L"_xlnm.Extract"); break;
case 0x0004: CP_XML_ATTR(L"name", L"_xlnm.Database"); break;
case 0x0005: CP_XML_ATTR(L"name", L"_xlnm.Criteria"); break;
case 0x0006: CP_XML_ATTR(L"name", L"_xlnm.Print_Area"); break;
case 0x0007: CP_XML_ATTR(L"name", L"_xlnm.Print_Titles"); break;
case 0x0008: CP_XML_ATTR(L"name", L"_xlnm.Recorder"); break;
case 0x0009: CP_XML_ATTR(L"name", L"_xlnm.Data_Form"); break;
case 0x000a: CP_XML_ATTR(L"name", L"_xlnm.Auto_Activate"); break;
case 0x000b: CP_XML_ATTR(L"name", L"_xlnm.Auto_Deactivate"); break;
case 0x000c: CP_XML_ATTR(L"name", L"_xlnm.Sheet_Title"); break;
case 0x000d: CP_XML_ATTR(L"name", L"_xlnm._FilterDatabase"); break; //??
}
}
if (ref)
{
CP_XML_ATTR(L"ref", ref->ref.toString());
CP_XML_ATTR(L"sheet", ref->sheet_name);
if (ref->index_external >= 0)
{
CP_XML_ATTR(L"r:id", L"extId" + std::to_wstring(ref->index_external + 1));
}
}
}
}
}
......
......@@ -116,7 +116,8 @@ public:
std::vector<_sx_name> arPivotSxNames;
std::vector<std::wstring> arPivotCacheSxNames;
std::vector<std::wstring> arPivotCacheReferences;
std::unordered_map<std::wstring, std::wstring> mapPivotCacheExternal;
std::map<std::wstring, std::vector<std::wstring>> mapDefineNames;
std::vector<std::wstring> arDefineNames;
......
......@@ -1977,4 +1977,9 @@ void XlsConverter::convert(XLS::PIVOTCACHEDEFINITION * pivot_cached)
pivot_cached->serialize_records(strmR);
xlsx_context->get_pivots_context().add_cache(strmD.str(), strmR.str());
if (!xls_global_info->mapPivotCacheExternal.empty())
{
xlsx_context->get_pivots_context().add_cache_external(xls_global_info->mapPivotCacheExternal);
}
}
\ No newline at end of file
......@@ -43,8 +43,12 @@ class xlsx_pivots_context::Impl
public:
struct _pivot_cache
{
std::wstring definitionsData_;
std::wstring recordsData_;
_pivot_cache(const std::wstring & def, const std::wstring & rec) : definitions_(def), records_(rec) {}
std::wstring definitions_;
std::wstring records_;
std::unordered_map<std::wstring, std::wstring> externals_;
};
struct _pivot_view
{
......@@ -67,9 +71,13 @@ void xlsx_pivots_context::add_cache(std::wstring definitions, std::wstring recor
{
if (definitions.empty()) return;
Impl::_pivot_cache c = {definitions, records};
Impl::_pivot_cache c(definitions, records);
impl_->caches_.push_back(c);
}
void xlsx_pivots_context::add_cache_external(std::unordered_map<std::wstring, std::wstring> &externals)
{
impl_->caches_.back().externals_ = externals;
}
int xlsx_pivots_context::get_cache_count()
{
......@@ -81,12 +89,20 @@ bool xlsx_pivots_context::is_connections()
}
void xlsx_pivots_context::dump_rels_cache(int index, rels & Rels)
{
if (impl_->caches_[index].recordsData_.empty() == false)
if (impl_->caches_[index].records_.empty() == false)
{
Rels.add(relationship(L"rId1",
L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheRecords",
L"pivotCacheRecords" + std::to_wstring(index + 1) + L".xml", L""));
}
int i = 0;
for (std::unordered_map<std::wstring, std::wstring>::iterator it = impl_->caches_[index].externals_.begin();
it != impl_->caches_[index].externals_.end(); it++, i++)
{
Rels.add(relationship(L"extId" + std::to_wstring(i + 1),
L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/externalLinkPath",
it->second, L"External"));
}
}
void xlsx_pivots_context::dump_rels_view(int index, rels & Rels)
{
......@@ -99,7 +115,7 @@ void xlsx_pivots_context::dump_rels_view(int index, rels & Rels)
}
void xlsx_pivots_context::write_cache_definitions_to(int index, std::wostream & strm)
{
strm << impl_->caches_[index].definitionsData_;
strm << impl_->caches_[index].definitions_;
}
void xlsx_pivots_context::write_connections_to(std::wostream & strm)
{
......@@ -116,7 +132,7 @@ void xlsx_pivots_context::write_connections_to(std::wostream & strm)
void xlsx_pivots_context::write_cache_records_to(int index, std::wostream & strm)
{
strm << impl_->caches_[index].recordsData_;
strm << impl_->caches_[index].records_;
}
void xlsx_pivots_context::write_table_view_to(int index, std::wostream & strm)
{
......
......@@ -31,6 +31,7 @@
*/
#pragma once
#include "oox_package.h"
#include <unordered_map>
namespace oox {
......@@ -47,6 +48,8 @@ public:
int get_view_count();
void add_cache(std::wstring definitions, std::wstring records);
void add_cache_external(std::unordered_map<std::wstring, std::wstring> &externals);
int get_cache_count();
void write_cache_definitions_to (int index, std::wostream & strm);
......
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