Commit 8a759169 authored by ElenaSubbotina's avatar ElenaSubbotina

XlsFormat - pivots dB connections

parent da45eb4f
......@@ -35,11 +35,11 @@
namespace XLS
{
DbOrParamQry::DbOrParamQry()
DbOrParamQry::DbOrParamQry(int typeRecord_)
{
typeRecord = typeRecord_;
}
DbOrParamQry::~DbOrParamQry()
{
}
......@@ -52,10 +52,32 @@ BaseObjectPtr DbOrParamQry::clone()
void DbOrParamQry::readFields(CFRecord& record)
{
#pragma message("####################### DbOrParamQry record is not implemented")
Log::error("DbOrParamQry record is not implemented.");
size_t size = record.getDataSize() - record.getRdPtr();
if (typeRecord == 1)
{
unsigned short flags;
record >> param.wTypeSql >> flags >> param.grbit >> param.fVal;
param.pbt = GETBITS(flags, 0, 1);
param.fNonDefaultName = GETBIT(flags, 2);
}
else
{
unsigned short flags;
record >> flags >> query.cparams >> query.cstQuery >> query.cstWebPost >> query.cstSQLSav >> query.cstOdbcConn;
record.skipNunBytes(record.getDataSize() - record.getRdPtr());
query.dbt = GETBITS(flags, 0, 2);
query.fOdbcConn = GETBIT(flags, 3);
query.fSql = GETBIT(flags, 4);
query.fSqlSav = GETBIT(flags, 5);
query.fWeb = GETBIT(flags, 6);
query.fSavePwd = GETBIT(flags, 7);
query.fTablesOnlyHTML = GETBIT(flags, 8);
}
}
} // namespace XLS
......
......@@ -36,24 +36,48 @@
namespace XLS
{
// Logical representation of DbOrParamQry record in BIFF8
class DbOrParamQry: public BiffRecord
{
BIFF_RECORD_DEFINE_TYPE_INFO(DbOrParamQry)
BASE_OBJECT_DEFINE_CLASS_NAME(DbOrParamQry)
public:
DbOrParamQry();
DbOrParamQry(int typeRecord = 2);
~DbOrParamQry();
BaseObjectPtr clone();
void readFields(CFRecord& record);
static const ElementType type = typeDbOrParamQry;
int typeRecord;
//PARAMQRY_Fixed - 8 bytes + variable
struct
{
unsigned short wTypeSql;
unsigned char pbt;
bool fNonDefaultName;
unsigned short grbit;
unsigned short fVal;
}param;
//---------------------------------------
struct
{
unsigned char dbt;
bool fOdbcConn;
bool fSql;
bool fSqlSav;
bool fWeb;
bool fSavePwd;
bool fTablesOnlyHTML;
short cparams;
short cstQuery;
short cstWebPost;
short cstSQLSav;
short cstOdbcConn;
}query;
};
} // namespace XLS
......
......@@ -31,7 +31,7 @@
*/
#include "SXString.h"
#include "../../../../../Common/DocxFormat/Source/XML/Utils.h"
namespace XLS
{
......@@ -39,12 +39,10 @@ SXString::SXString()
{
}
SXString::~SXString()
{
}
BaseObjectPtr SXString::clone()
{
return BaseObjectPtr(new SXString(*this));
......@@ -73,5 +71,15 @@ int SXString::serialize(std::wostream & strm)
return 0;
}
std::wstring SXString::value()
{
std::wstring s = segment.value();
XmlUtils::replace_all(s, L"\x0d", L"_x000d_");
XmlUtils::replace_all(s, L"\x0a", L"_x000a_");
return s;
}
} // namespace XLS
......@@ -49,6 +49,8 @@ public:
void readFields(CFRecord& record);
std::wstring value();
int serialize(std::wostream & strm);
static const ElementType type = typeSXString;
......
......@@ -63,7 +63,8 @@ public:
{
return false;
}
proc.mandatory<DbOrParamQry>();
DbOrParamQry param(1);
proc.mandatory(param);
return true;
};
};
......@@ -80,11 +81,14 @@ public:
const bool loadContent(BinProcessor& proc)
{
if(!proc.mandatory<DbOrParamQry>())
DbOrParamQry param(1);
if(!proc.mandatory(param))
{
return false;
}
proc.repeated<Parenthesis_DBQUERY_3>(0, 0);
int count = proc.repeated<Parenthesis_DBQUERY_3>(0, 0);
return true;
};
};
......@@ -105,8 +109,11 @@ public:
{
return false;
}
proc.repeated<SXString>(0, 0);
int count = proc.repeated<SXString>(0, 0);
proc.optional<Parenthesis_DBQUERY_2>();
return true;
};
};
......@@ -117,20 +124,126 @@ BaseObjectPtr DBQUERY::clone()
return BaseObjectPtr(new DBQUERY(*this));
}
// DBQUERY = DbOrParamQry [1*SXString [DbOrParamQry *(SXString DbOrParamQry)]] *SXString
const bool DBQUERY::loadContent(BinProcessor& proc)
{
global_info = proc.getGlobalWorkbookInfo();
if(!proc.mandatory<DbOrParamQry>())
{
return false;
}
m_DbQry = elements_.front(); elements_.pop_front();
proc.optional<Parenthesis_DBQUERY_1>();
proc.repeated<SXString>(0, 0);
while(!elements_.empty())
{
SXString* str = dynamic_cast<SXString*>(elements_.front().get());
if (!str)
{
m_DbParam = elements_.front(); elements_.pop_front();
break;
}
m_arSXString.push_back(str->value());
elements_.pop_front();
}
while(!elements_.empty())
{
SXString* str = dynamic_cast<SXString*>(elements_.front().get());
if (str)
{
_DbParam a;
a.string = str->value();
m_arParams.push_back(a);
}
else
{
DbOrParamQry* param = dynamic_cast<DbOrParamQry*>(elements_.front().get());
if (param)
{
m_arParams.back().param = elements_.front();
}
}
elements_.pop_front();
}
int count = proc.repeated<SXString>(0, 0);
while(!elements_.empty())
{
SXString* str = dynamic_cast<SXString*>(elements_.front().get());
if (str)
{
m_arSXString.push_back(str->value());
}
elements_.pop_front();
}
return true;
}
int DBQUERY::serialize(std::wostream & strm)
{
connectionId = ++global_info->connectionId;
CP_XML_WRITER(strm)
{
CP_XML_NODE(L"cacheSource")
{
CP_XML_ATTR(L"type", L"external");
CP_XML_ATTR(L"connectionId", connectionId); //connectionId in connections(root)
}
}
serialize_connection(global_info->connections_stream);
return 0;
}
int DBQUERY::serialize_connection(std::wostream & strm)
{
DbOrParamQry* queryOrParam = dynamic_cast<DbOrParamQry*>(m_DbQry.get());
if (!queryOrParam) return 0;
CP_XML_WRITER(strm)
{
CP_XML_NODE(L"connection")
{
CP_XML_ATTR(L"id", 1); //connectionId in connections(root)
CP_XML_ATTR(L"name", L"Connection");
CP_XML_ATTR(L"type", queryOrParam->query.dbt);
//switch(queryOrParam->query.dbt)
//{
// case 0x1: CP_XML_ATTR(L"type", 1); break;
// case 0x2:
// case 0x3:
// case 0x4:
// case 0x5:
// case 0x6:
// case 0x7:
//}
if (queryOrParam->query.fSavePwd) CP_XML_ATTR(L"savePassword", 1);
if (queryOrParam->query.fSavePwd) CP_XML_ATTR(L"refreshedVersion", 1);
int index = 0;
CP_XML_NODE(L"dbPr")
{
if (index < m_arSXString.size())
{
CP_XML_ATTR(L"command", m_arSXString[index]);
}
index++;
if (index < m_arSXString.size())
{
CP_XML_ATTR(L"connection", m_arSXString[index]);
}
index++;
}
}
}
return 0;
}
} // namespace XLS
......@@ -35,9 +35,12 @@
namespace XLS
{
struct _DbParam
{
std::wstring string;
BaseObjectPtr param;
};
// Logical representation of DBQUERY union of records
class DBQUERY: public CompositeObject
{
BASE_OBJECT_DEFINE_CLASS_NAME(DBQUERY)
......@@ -49,6 +52,18 @@ public:
virtual const bool loadContent(BinProcessor& proc);
int serialize(std::wostream & stream);
int serialize_connection(std::wostream & strm);
BaseObjectPtr m_DbQry;
BaseObjectPtr m_DbParam;
std::vector<_DbParam> m_arParams;
std::vector<std::wstring> m_arSXString;
//------------------------------------------------------
GlobalWorkbookInfoPtr global_info;
int connectionId;
};
} // namespace XLS
......
......@@ -36,8 +36,6 @@
namespace XLS
{
// Logical representation of DBQUERYEXT union of records
class DBQUERYEXT: public CompositeObject
{
BASE_OBJECT_DEFINE_CLASS_NAME(DBQUERYEXT)
......@@ -49,6 +47,11 @@ public:
virtual const bool loadContent(BinProcessor& proc);
BaseObjectPtr m_TxtQry;
BaseObjectPtr m_DBQueryExt;
BaseObjectPtr m_ExtString;
std::vector<BaseObjectPtr> m_arExtString;
};
} // namespace XLS
......
......@@ -31,10 +31,11 @@
*/
#include "DBQUERYEXT.h"
#include <Logic/Biff_records/DBQueryExt.h>
#include <Logic/Biff_records/ExtString.h>
#include <Logic/Biff_records/OleDbConn.h>
#include <Logic/Biff_records/TxtQry.h>
#include "../Biff_records/DBQueryExt.h"
#include "../Biff_records/ExtString.h"
#include "../Biff_records/OleDbConn.h"
#include "../Biff_records/TxtQry.h"
namespace XLS
{
......@@ -84,11 +85,30 @@ const bool DBQUERYEXT::loadContent(BinProcessor& proc)
{
return false;
}
proc.optional<ExtString>();
proc.repeated<Parenthesis_DBQUERYEXT_1>(0, 4);
m_DBQueryExt = elements_.back();
elements_.pop_back();
if (proc.optional<ExtString>())
{
m_ExtString = elements_.back();
elements_.pop_back();
}
int count = proc.repeated<Parenthesis_DBQUERYEXT_1>(0, 4);
//....
if(proc.optional<TxtQry>())
{
proc.repeated<ExtString>(0, 0);
m_TxtQry = elements_.back();
elements_.pop_back();
int count = proc.repeated<ExtString>(0, 0);
while(count--)
{
m_arExtString.insert(m_arExtString.begin(), elements_.back());
elements_.pop_back();
}
}
return true;
......
......@@ -189,6 +189,7 @@ int FDB::serialize(std::wostream & strm)
if (fdb_type->wTypeSql > 0)
{
CP_XML_ATTR(L"numFmtId", fdb_type->wTypeSql);
//CP_XML_ATTR(L"sqlType", fdb_type->wTypeSql); //in db
}
if (m_arSRCSXOPER.empty() && m_arGRPSXOPER.empty() == false)
{
......
......@@ -54,7 +54,6 @@ BaseObjectPtr SXSRC::clone()
return BaseObjectPtr(new SXSRC(*this));
}
// SXSRC = DREF / SXTBL / DBQUERY
const bool SXSRC::loadContent(BinProcessor& proc)
{
......
......@@ -31,11 +31,12 @@
*/
#include "XFS.h"
#include <Logic/Biff_records/XF.h>
#include <Logic/Biff_records/XFCRC.h>
#include <Logic/Biff_records/XFExt.h>
#include <Logic/Biff_structures/ExtProp.h>
#include "../Biff_records/XF.h"
#include "../Biff_records/XFCRC.h"
#include "../Biff_records/XFExt.h"
#include "../Biff_structures/ExtProp.h"
namespace XLS
{
......
......@@ -114,6 +114,8 @@ GlobalWorkbookInfo::GlobalWorkbookInfo(const unsigned short code_page, XlsConver
cellStyleXfs_count = 0;
cellStyleDxfs_count = 0;
connectionId = 0;
defaultDigitFontSize = std::pair<float, float>(0, 0);
applicationFonts = NULL;
}
......
......@@ -142,6 +142,9 @@ public:
int cellStyleDxfs_count;
std::wstringstream users_Dxfs_stream;
std::wstringstream connections_stream;
int connectionId;
XlsConverter *xls_converter;
......
......@@ -218,7 +218,6 @@ XlsConverter::XlsConverter(const std::wstring & xls_file, const std::wstring & _
xls_global_info->mapPivotCache.insert(std::make_pair(index, pivot_cache));
}
}
}
catch(...)
{
......@@ -533,6 +532,7 @@ void XlsConverter::convert(XLS::GlobalsSubstream* global)
{
convert((XLS::PIVOTCACHEDEFINITION*)global->m_arPIVOTCACHEDEFINITION[i].get());
}
xlsx_context->get_pivots_context().add_connections(xls_global_info->connections_stream.str());
}
typedef boost::unordered_map<XLS::FillInfo, int> mapFillInfo;
......
......@@ -293,8 +293,14 @@ void xlsx_conversion_context::end_document()
output_document_->get_xl_files().add_pivot_table(content);
}
}
}
if (xlsx_pivots_context_.is_connections())
{
std::wstringstream strm;
xlsx_pivots_context_.write_connections_to(strm);
output_document_->get_xl_files().set_connections( package::simple_element::create(L"connections.xml", strm.str()) );
}
}
output_document_->get_xl_files().set_workbook( package::simple_element::create(L"workbook.xml", strm_workbook.str()) );
output_document_->content_type().set_media(get_mediaitems());
......@@ -308,9 +314,7 @@ void xlsx_conversion_context::end_document()
package::xl_comments_ptr comments = package::xl_comments::create(xlsx_comments_context_handle_.content());
output_document_->get_xl_files().set_comments(comments);
}
}
}
......@@ -53,7 +53,6 @@ xlsx_content_types_file::xlsx_content_types_file()
content_type_.add_override(L"/_rels/.rels", L"application/vnd.openxmlformats-package.relationships+xml");
content_type_.add_override(L"/xl/_rels/workbook.xml.rels", L"application/vnd.openxmlformats-package.relationships+xml");
content_type_.add_override(L"/xl/sharedStrings.xml", L"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml");
content_type_.add_override(L"/xl/workbook.xml", L"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml");
content_type_.add_override(L"/xl/styles.xml", L"application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml");
content_type_.add_override(L"/docProps/app.xml", L"application/vnd.openxmlformats-officedocument.extended-properties+xml");
......@@ -194,6 +193,18 @@ void xl_files::write(const std::wstring & RootPath)
{
sharedStrings_->write(path);
rels_files_.add( relationship( L"shId1", L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings", L"sharedStrings.xml" ) );
content_type & contentTypes = this->get_main_document()->content_type().get_content_type();
contentTypes.add_override(L"/xl/sharedStrings.xml", L"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml");
}
if (connections_)
{
connections_->write(path);
rels_files_.add( relationship( L"cnId1", L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/connections", L"connections.xml" ) );
content_type & contentTypes = this->get_main_document()->content_type().get_content_type();
contentTypes.add_override(L"/xl/connections.xml", L"application/vnd.openxmlformats-officedocument.spreadsheetml.connections+xml");
}
if (styles_)
......@@ -255,6 +266,10 @@ void xl_files::set_sharedStrings(element_ptr Element)
{
sharedStrings_ = Element;
}
void xl_files::set_connections(element_ptr Element)
{
connections_ = Element;
}
void xl_files::add_sheet(sheet_content_ptr sheet)
{
......
......@@ -223,6 +223,7 @@ public:
void set_workbook (element_ptr Element);
void set_styles (element_ptr Element);
void set_sharedStrings (element_ptr Element);
void set_connections (element_ptr Element);
void add_sheet (sheet_content_ptr sheet);
void set_media (external_items & _Mediaitems);
void set_drawings (element_ptr Element);
......@@ -241,6 +242,7 @@ private:
element_ptr theme_;
element_ptr workbook_;
element_ptr connections_;
element_ptr styles_;
element_ptr sharedStrings_;
element_ptr media_;
......
......@@ -54,6 +54,7 @@ public:
std::vector<_pivot_cache> caches_;
std::vector<_pivot_view> views_;
std::wstring connections_;
};
xlsx_pivots_context::xlsx_pivots_context() : impl_(new xlsx_pivots_context::Impl())
......@@ -70,7 +71,10 @@ int xlsx_pivots_context::get_cache_count()
{
return (int)impl_->caches_.size();
}
bool xlsx_pivots_context::is_connections()
{
return !impl_->connections_.empty();
}
void xlsx_pivots_context::dump_rels_cache(int index, rels & Rels)
{
if (impl_->caches_[index].recordsData_.empty() == false)
......@@ -93,6 +97,18 @@ void xlsx_pivots_context::write_cache_definitions_to(int index, std::wostream &
{
strm << impl_->caches_[index].definitionsData_;
}
void xlsx_pivots_context::write_connections_to(std::wostream & strm)
{
CP_XML_WRITER(strm)
{
CP_XML_NODE(L"connections")
{
CP_XML_ATTR(L"xmlns", L"http://schemas.openxmlformats.org/spreadsheetml/2006/main");
CP_XML_STREAM() << impl_->connections_;
}
}
}
void xlsx_pivots_context::write_cache_records_to(int index, std::wostream & strm)
{
......@@ -112,6 +128,13 @@ int xlsx_pivots_context::add_view(std::wstring table_view, int indexCache)
return (int)impl_->views_.size();
}
void xlsx_pivots_context::add_connections(std::wstring connections)
{
if (connections.empty()) return;
impl_->connections_ = connections;
}
int xlsx_pivots_context::get_view_count()
{
return (int)impl_->views_.size();
......
......@@ -51,11 +51,16 @@ public:
void write_cache_definitions_to (int index, std::wostream & strm);
void write_cache_records_to (int index, std::wostream & strm);
void write_connections_to (std::wostream & strm);
void write_table_view_to (int index, std::wostream & strm);
void dump_rels_cache(int index, rels & Rels);
void dump_rels_view (int index, rels & Rels);
void add_connections(std::wstring connections);
bool is_connections();
private:
class Impl;
_CP_PTR(Impl) impl_;
......
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