Commit 3c58cd96 authored by Sergey Konovalov's avatar Sergey Konovalov

for bug 27765

parent e50864fa
...@@ -1092,6 +1092,13 @@ namespace OOX ...@@ -1092,6 +1092,13 @@ namespace OOX
et_x_SheetPr, et_x_SheetPr,
et_x_Pane, et_x_Pane,
et_x_ExternalBook, et_x_ExternalBook,
et_x_ExternalSheetNames,
et_x_ExternalDefinedNames,
et_x_ExternalDefinedName,
et_x_ExternalSheetDataSet,
et_x_ExternalSheetData,
et_x_ExternalRow,
et_x_ExternalCell,
et_x_Selection, et_x_Selection,
et_x_LegacyDrawingWorksheet, et_x_LegacyDrawingWorksheet,
et_x_LegacyDrawingHFWorksheet, et_x_LegacyDrawingHFWorksheet,
......
...@@ -187,7 +187,8 @@ namespace BinXlsxRW ...@@ -187,7 +187,8 @@ namespace BinXlsxRW
ExternalReferences = 5, ExternalReferences = 5,
ExternalReference = 6, ExternalReference = 6,
PivotCaches = 7, PivotCaches = 7,
PivotCache = 8 PivotCache = 8,
ExternalBook = 9
};} };}
namespace c_oSerWorkbookPrTypes{enum c_oSerWorkbookPrTypes namespace c_oSerWorkbookPrTypes{enum c_oSerWorkbookPrTypes
{ {
...@@ -819,6 +820,27 @@ namespace BinXlsxRW ...@@ -819,6 +820,27 @@ namespace BinXlsxRW
cacheId = 3, cacheId = 3,
table = 4 table = 4
};} };}
namespace c_oSer_ExternalLinkTypes{enum c_oSer_ExternalLinkTypes
{
Id = 0,
SheetNames = 1,
SheetName = 2,
DefinedNames = 3,
DefinedName = 4,
DefinedNameName = 5,
DefinedNameRefersTo = 6,
DefinedNameSheetId = 7,
SheetDataSet = 8,
SheetData = 9,
SheetDataSheetId = 10,
SheetDataRefreshError = 11,
SheetDataRow = 12,
SheetDataRowR = 13,
SheetDataRowCell = 14,
SheetDataRowCellRef = 15,
SheetDataRowCellType = 16,
SheetDataRowCellValue = 17
};}
} }
#endif // #endif //
...@@ -1583,13 +1583,13 @@ namespace BinXlsxRW ...@@ -1583,13 +1583,13 @@ namespace BinXlsxRW
if(pExternalReference->m_oRid.IsInit()) if(pExternalReference->m_oRid.IsInit())
{ {
smart_ptr<OOX::File> pFile = workbook.Find( OOX::RId(pExternalReference->m_oRid->GetValue())); smart_ptr<OOX::File> pFile = workbook.Find( OOX::RId(pExternalReference->m_oRid->GetValue()));
if (pFile.IsInit() && OOX::Spreadsheet::FileTypes::ExternalLinks == pFile->type()) if (pFile.IsInit() && OOX::Spreadsheet::FileTypes::ExternalLinks == pFile->type())
{ {
OOX::Spreadsheet::CExternalLink* pExternalLink = static_cast<OOX::Spreadsheet::CExternalLink*>(pFile.operator ->()); OOX::Spreadsheet::CExternalLink* pExternalLink = static_cast<OOX::Spreadsheet::CExternalLink*>(pFile.operator ->());
if ((pExternalLink) && (pExternalLink->m_oExternalBook.IsInit())) if ((pExternalLink) && (pExternalLink->m_oExternalBook.IsInit()))
{ {
std::wstring sLink; std::wstring sLink;
if (pExternalLink->m_oExternalBook->m_oRid.IsInit()) if (pExternalLink->m_oExternalBook->m_oRid.IsInit())
{ {
smart_ptr<OOX::File> pFile = pExternalLink->Find( OOX::RId(pExternalLink->m_oExternalBook->m_oRid.get().GetValue())); smart_ptr<OOX::File> pFile = pExternalLink->Find( OOX::RId(pExternalLink->m_oExternalBook->m_oRid.get().GetValue()));
...@@ -1597,12 +1597,12 @@ namespace BinXlsxRW ...@@ -1597,12 +1597,12 @@ namespace BinXlsxRW
{ {
OOX::Spreadsheet::ExternalLinkPath* pLinkFile = static_cast<OOX::Spreadsheet::ExternalLinkPath*>(pFile.operator ->()); OOX::Spreadsheet::ExternalLinkPath* pLinkFile = static_cast<OOX::Spreadsheet::ExternalLinkPath*>(pFile.operator ->());
sLink = pLinkFile->Uri().GetPath(); sLink = pLinkFile->Uri().GetPath();
} }
} }
if(!sLink.empty()) if(!sLink.empty())
{ {
nCurPos = m_oBcw.WriteItemStart(c_oSerWorkbookTypes::ExternalReference); nCurPos = m_oBcw.WriteItemStart(c_oSerWorkbookTypes::ExternalBook);
m_oBcw.m_oStream.WriteStringW3(sLink); WriteExternalBook(pExternalLink->m_oExternalBook.get(), sLink);
m_oBcw.WriteItemWithLengthEnd(nCurPos); m_oBcw.WriteItemWithLengthEnd(nCurPos);
} }
} }
...@@ -1610,7 +1610,144 @@ namespace BinXlsxRW ...@@ -1610,7 +1610,144 @@ namespace BinXlsxRW
} }
} }
}; };
void WriteExternalBook(const OOX::Spreadsheet::CExternalBook& externalBook, const std::wstring& sLink)
{
int nCurPos = 0;
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::Id);
m_oBcw.m_oStream.WriteStringW3(sLink);
m_oBcw.WriteItemWithLengthEnd(nCurPos);
if (externalBook.m_oSheetNames.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::SheetNames);
WriteExternalSheetNames(externalBook.m_oSheetNames.get());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
if (externalBook.m_oDefinedNames.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::DefinedNames);
WriteExternalDefinedNames(externalBook.m_oDefinedNames.get());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
if (externalBook.m_oSheetDataSet.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::SheetDataSet);
WriteExternalSheetDataSet(externalBook.m_oSheetDataSet.get());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
}
void WriteExternalSheetNames(const OOX::Spreadsheet::CExternalSheetNames& sheetNames)
{
int nCurPos = 0;
for (size_t i = 0, length = sheetNames.m_arrItems.size(); i < length; ++i)
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::SheetName);
m_oBcw.m_oStream.WriteStringW3(sheetNames.m_arrItems[i]->ToString2());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
}
void WriteExternalDefinedNames(const OOX::Spreadsheet::CExternalDefinedNames& definedNames)
{
int nCurPos = 0;
for (size_t i = 0, length = definedNames.m_arrItems.size(); i < length; ++i)
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::DefinedName);
WriteExternalDefinedName(*definedNames.m_arrItems[i]);
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
}
void WriteExternalDefinedName(const OOX::Spreadsheet::CExternalDefinedName& definedName)
{
int nCurPos = 0;
if (definedName.m_oName.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::DefinedNameName);
m_oBcw.m_oStream.WriteStringW3(definedName.m_oName.get());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
if (definedName.m_oRefersTo.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::DefinedNameRefersTo);
m_oBcw.m_oStream.WriteStringW3(definedName.m_oRefersTo.get());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
if (definedName.m_oSheetId.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::DefinedNameSheetId);
m_oBcw.m_oStream.WriteULONG(definedName.m_oSheetId->GetValue());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
}
void WriteExternalSheetDataSet(const OOX::Spreadsheet::CExternalSheetDataSet& sheetDataSet)
{
int nCurPos = 0;
for (size_t i = 0, length = sheetDataSet.m_arrItems.size(); i < length; ++i)
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::SheetData);
WriteExternalSheetData(*sheetDataSet.m_arrItems[i]);
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
}
void WriteExternalSheetData(const OOX::Spreadsheet::CExternalSheetData& sheetData)
{
int nCurPos = 0;
if(sheetData.m_oSheetId.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::SheetDataSheetId);
m_oBcw.m_oStream.WriteULONG(sheetData.m_oSheetId->GetValue());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
if(sheetData.m_oRefreshError.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::SheetDataRefreshError);
m_oBcw.m_oStream.WriteBOOL(sheetData.m_oRefreshError->ToBool());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
for (size_t i = 0, length = sheetData.m_arrItems.size(); i < length; ++i)
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::SheetDataRow);
WriteExternalRow(*sheetData.m_arrItems[i]);
m_oBcw.WriteItemEnd(nCurPos);
}
}
void WriteExternalRow(const OOX::Spreadsheet::CExternalRow& row)
{
int nCurPos = 0;
if(row.m_oR.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::SheetDataRowR);
m_oBcw.m_oStream.WriteULONG(row.m_oR->GetValue());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
for (size_t i = 0, length = row.m_arrItems.size(); i < length; ++i)
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::SheetDataRowCell);
WriteExternalCell(*row.m_arrItems[i]);
m_oBcw.WriteItemEnd(nCurPos);
}
}
void WriteExternalCell(const OOX::Spreadsheet::CExternalCell& cell)
{
int nCurPos = 0;
if(cell.m_oRef.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::SheetDataRowCellRef);
m_oBcw.m_oStream.WriteStringW3(cell.m_oRef.get());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
if(cell.m_oType.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::SheetDataRowCellType);
m_oBcw.m_oStream.WriteBYTE(cell.m_oType->GetValue());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
if(cell.m_oValue.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_ExternalLinkTypes::SheetDataRowCellValue);
m_oBcw.m_oStream.WriteStringW3(cell.m_oValue->ToString());
m_oBcw.WriteItemWithLengthEnd(nCurPos);
}
}
void WriteDefinedName(const OOX::Spreadsheet::CDefinedName& definedName) void WriteDefinedName(const OOX::Spreadsheet::CDefinedName& definedName)
{ {
int nCurPos = 0; int nCurPos = 0;
......
...@@ -1592,34 +1592,27 @@ namespace BinXlsxRW { ...@@ -1592,34 +1592,27 @@ namespace BinXlsxRW {
int ReadExternalReferences(BYTE type, long length, void* poResult) int ReadExternalReferences(BYTE type, long length, void* poResult)
{ {
int res = c_oSerConstants::ReadOk; int res = c_oSerConstants::ReadOk;
if(c_oSerWorkbookTypes::ExternalReference == type) if(c_oSerWorkbookTypes::ExternalBook == type)
{ {
std::wstring sName(m_oBufferedStream.GetString3(length)); OOX::Spreadsheet::CExternalLink *extLink = new OOX::Spreadsheet::CExternalLink();
extLink->m_oExternalBook.Init();
if (sName.empty() == false) res = Read1(length, &BinaryWorkbookTableReader::ReadExternalBook, this, extLink);
if (extLink->m_oExternalBook->m_oRid.IsInit())
{ {
OOX::Spreadsheet::CExternalReference* pExternalReference = new OOX::Spreadsheet::CExternalReference(); OOX::Spreadsheet::CExternalReference* pExternalReference = new OOX::Spreadsheet::CExternalReference();
OOX::Spreadsheet::CExternalLink *extLink= new OOX::Spreadsheet::CExternalLink();
smart_ptr<OOX::File> oCurFile(extLink);
const OOX::RId oRId = m_oWorkbook.Add(oCurFile);
pExternalReference->m_oRid.Init();
pExternalReference->m_oRid->SetValue(oRId.get());
extLink->m_oExternalBook.Init(); smart_ptr<OOX::File> oCurFile(extLink);
const OOX::RId oRId = m_oWorkbook.Add(oCurFile);
OOX::Spreadsheet::ExternalLinkPath *link = new OOX::Spreadsheet::ExternalLinkPath(sName);
smart_ptr<OOX::File> oLinkFile(link);
const OOX::RId oRIdLink = extLink->Add(oLinkFile);
extLink->m_oExternalBook->m_oRid.Init(); pExternalReference->m_oRid.Init();
extLink->m_oExternalBook->m_oRid->SetValue(oRIdLink.get()); pExternalReference->m_oRid->SetValue(oRId.get());
m_oWorkbook.m_oExternalReferences->m_arrItems.push_back(pExternalReference); m_oWorkbook.m_oExternalReferences->m_arrItems.push_back(pExternalReference);
}
else
{
RELEASEOBJECT(extLink)
} }
} }
else else
...@@ -1672,6 +1665,174 @@ namespace BinXlsxRW { ...@@ -1672,6 +1665,174 @@ namespace BinXlsxRW {
res = c_oSerConstants::ReadUnknown; res = c_oSerConstants::ReadUnknown;
return res; return res;
}; };
int ReadExternalBook(BYTE type, long length, void* poResult)
{
OOX::Spreadsheet::CExternalLink* extLink = static_cast<OOX::Spreadsheet::CExternalLink*>(poResult);
OOX::Spreadsheet::CExternalBook* pExternalBook = extLink->m_oExternalBook.GetPointer();
int res = c_oSerConstants::ReadOk;
if(c_oSer_ExternalLinkTypes::Id == type)
{
std::wstring sName(m_oBufferedStream.GetString3(length));
OOX::Spreadsheet::ExternalLinkPath *link = new OOX::Spreadsheet::ExternalLinkPath(sName);
smart_ptr<OOX::File> oLinkFile(link);
const OOX::RId oRIdLink = extLink->Add(oLinkFile);
pExternalBook->m_oRid.Init();
pExternalBook->m_oRid->SetValue(oRIdLink.get());
}
else if(c_oSer_ExternalLinkTypes::SheetNames == type)
{
pExternalBook->m_oSheetNames.Init();
res = Read1(length, &BinaryWorkbookTableReader::ReadExternalSheetNames, this, pExternalBook->m_oSheetNames.GetPointer());
}
else if(c_oSer_ExternalLinkTypes::DefinedNames == type)
{
pExternalBook->m_oDefinedNames.Init();
res = Read1(length, &BinaryWorkbookTableReader::ReadExternalDefinedNames, this, pExternalBook->m_oDefinedNames.GetPointer());
}
else if(c_oSer_ExternalLinkTypes::SheetDataSet == type)
{
pExternalBook->m_oSheetDataSet.Init();
res = Read1(length, &BinaryWorkbookTableReader::ReadExternalSheetDataSet, this, pExternalBook->m_oSheetDataSet.GetPointer());
}
else
res = c_oSerConstants::ReadUnknown;
return res;
};
int ReadExternalSheetNames(BYTE type, long length, void* poResult)
{
OOX::Spreadsheet::CExternalSheetNames* pSheetNames = static_cast<OOX::Spreadsheet::CExternalSheetNames*>(poResult);
int res = c_oSerConstants::ReadOk;
if(c_oSer_ExternalLinkTypes::SheetName == type)
{
ComplexTypes::Spreadsheet::String* pSheetName = new ComplexTypes::Spreadsheet::String();
pSheetName->m_sVal.Init();
pSheetName->m_sVal->append(m_oBufferedStream.GetString4(length));
pSheetNames->m_arrItems.push_back(pSheetName);
}
else
res = c_oSerConstants::ReadUnknown;
return res;
};
int ReadExternalDefinedNames(BYTE type, long length, void* poResult)
{
OOX::Spreadsheet::CExternalDefinedNames* pDefinedNames = static_cast<OOX::Spreadsheet::CExternalDefinedNames*>(poResult);
int res = c_oSerConstants::ReadOk;
if(c_oSer_ExternalLinkTypes::DefinedName == type)
{
OOX::Spreadsheet::CExternalDefinedName* pDefinedName = new OOX::Spreadsheet::CExternalDefinedName();
res = Read1(length, &BinaryWorkbookTableReader::ReadExternalDefinedName, this, pDefinedName);
pDefinedNames->m_arrItems.push_back(pDefinedName);
}
else
res = c_oSerConstants::ReadUnknown;
return res;
};
int ReadExternalDefinedName(BYTE type, long length, void* poResult)
{
OOX::Spreadsheet::CExternalDefinedName* pDefinedName = static_cast<OOX::Spreadsheet::CExternalDefinedName*>(poResult);
int res = c_oSerConstants::ReadOk;
if(c_oSer_ExternalLinkTypes::DefinedNameName == type)
{
pDefinedName->m_oName.Init();
pDefinedName->m_oName->append(m_oBufferedStream.GetString3(length));
}
else if(c_oSer_ExternalLinkTypes::DefinedNameRefersTo == type)
{
pDefinedName->m_oRefersTo.Init();
pDefinedName->m_oRefersTo->append(m_oBufferedStream.GetString3(length));
}
else if(c_oSer_ExternalLinkTypes::DefinedNameSheetId == type)
{
pDefinedName->m_oSheetId.Init();
pDefinedName->m_oSheetId->SetValue(m_oBufferedStream.GetULong());
}
else
res = c_oSerConstants::ReadUnknown;
return res;
};
int ReadExternalSheetDataSet(BYTE type, long length, void* poResult)
{
OOX::Spreadsheet::CExternalSheetDataSet* pSheetDataSet = static_cast<OOX::Spreadsheet::CExternalSheetDataSet*>(poResult);
int res = c_oSerConstants::ReadOk;
if(c_oSer_ExternalLinkTypes::SheetData == type)
{
OOX::Spreadsheet::CExternalSheetData* pSheetData = new OOX::Spreadsheet::CExternalSheetData();
res = Read1(length, &BinaryWorkbookTableReader::ReadExternalSheetData, this, pSheetData);
pSheetDataSet->m_arrItems.push_back(pSheetData);
}
else
res = c_oSerConstants::ReadUnknown;
return res;
};
int ReadExternalSheetData(BYTE type, long length, void* poResult)
{
OOX::Spreadsheet::CExternalSheetData* pSheetData = static_cast<OOX::Spreadsheet::CExternalSheetData*>(poResult);
int res = c_oSerConstants::ReadOk;
if(c_oSer_ExternalLinkTypes::SheetDataSheetId == type)
{
pSheetData->m_oSheetId.Init();
pSheetData->m_oSheetId->SetValue(m_oBufferedStream.GetULong());
}
else if(c_oSer_ExternalLinkTypes::SheetDataRefreshError == type)
{
pSheetData->m_oRefreshError.Init();
pSheetData->m_oRefreshError->FromBool(m_oBufferedStream.GetBool());
}
else if(c_oSer_ExternalLinkTypes::SheetDataRow == type)
{
OOX::Spreadsheet::CExternalRow* pRow = new OOX::Spreadsheet::CExternalRow();
res = Read1(length, &BinaryWorkbookTableReader::ReadExternalRow, this, pRow);
pSheetData->m_arrItems.push_back(pRow);
}
else
res = c_oSerConstants::ReadUnknown;
return res;
};
int ReadExternalRow(BYTE type, long length, void* poResult)
{
OOX::Spreadsheet::CExternalRow* pRow = static_cast<OOX::Spreadsheet::CExternalRow*>(poResult);
int res = c_oSerConstants::ReadOk;
if(c_oSer_ExternalLinkTypes::SheetDataRowR == type)
{
pRow->m_oR.Init();
pRow->m_oR->SetValue(m_oBufferedStream.GetULong());
}
else if(c_oSer_ExternalLinkTypes::SheetDataRowCell == type)
{
OOX::Spreadsheet::CExternalCell* pCell = new OOX::Spreadsheet::CExternalCell();
res = Read1(length, &BinaryWorkbookTableReader::ReadExternalCell, this, pCell);
pRow->m_arrItems.push_back(pCell);
}
else
res = c_oSerConstants::ReadUnknown;
return res;
};
int ReadExternalCell(BYTE type, long length, void* poResult)
{
OOX::Spreadsheet::CExternalCell* pCell = static_cast<OOX::Spreadsheet::CExternalCell*>(poResult);
int res = c_oSerConstants::ReadOk;
if(c_oSer_ExternalLinkTypes::SheetDataRowCellRef == type)
{
pCell->m_oRef.Init();
pCell->m_oRef->append(m_oBufferedStream.GetString3(length));
}
else if(c_oSer_ExternalLinkTypes::SheetDataRowCellType == type)
{
pCell->m_oType.Init();
pCell->m_oType->SetValue((SimpleTypes::Spreadsheet::ECellTypeType)m_oBufferedStream.GetUChar());
}
else if(c_oSer_ExternalLinkTypes::SheetDataRowCellValue == type)
{
pCell->m_oValue.Init();
pCell->m_oValue->m_sText.append(m_oBufferedStream.GetString3(length));
}
else
res = c_oSerConstants::ReadUnknown;
return res;
};
int ReadPivotCaches(BYTE type, long length, void* poResult) int ReadPivotCaches(BYTE type, long length, void* poResult)
{ {
int res = c_oSerConstants::ReadOk; int res = c_oSerConstants::ReadOk;
......
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