Commit f7bbdfba authored by Sergey.Konovalov's avatar Sergey.Konovalov Committed by Alexander Trofimov

(1.0.0.110): XlsxSerializerCom

Bug 23773 - Экспортируется только один комментарий из нескольких, добавленных к документу.
больше не инициализируются default значение chart при открытии и сохранении.

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@55470 954022d7-b5bf-4e40-9824-e11837661b57
parent fa3fdd7f
......@@ -2467,19 +2467,23 @@ namespace BinXlsxRW {
if(pPair->m_value->IsValid())
{
OOX::Spreadsheet::CCommentItem& oComment = *pPair->m_value;
SerializeCommon::CommentData* pSavedData = getSavedComment(oComment);
CAtlArray<SerializeCommon::CommentData*> aCommentDatas;
getSavedComment(oComment, aCommentDatas);
nCurPos = m_oBcw.WriteItemStart(c_oSerWorksheetsTypes::Comment);
// , , , Excel
WriteComment(oComment, pSavedData, oComment.m_oText);
WriteComment(oComment, aCommentDatas, oComment.m_oText);
m_oBcw.WriteItemEnd(nCurPos);
RELEASEOBJECT(pSavedData);
for(int i = 0, length = aCommentDatas.GetCount(); i < length; ++i)
{
RELEASEOBJECT(aCommentDatas[i]);
}
aCommentDatas.RemoveAll();
}
}
};
SerializeCommon::CommentData* getSavedComment(OOX::Spreadsheet::CCommentItem& oComment)
void getSavedComment(OOX::Spreadsheet::CCommentItem& oComment, CAtlArray<SerializeCommon::CommentData*>& aDatas)
{
SerializeCommon::CommentData* pCommentData = NULL;
if(oComment.m_sGfxdata.IsInit())
{
const CString& sGfxData = oComment.m_sGfxdata.get2();
......@@ -2501,17 +2505,15 @@ namespace BinXlsxRW {
oBufferedStream.SetBuffer(&oBuffer);
oBufferedStream.Create((BYTE*)(pBuffer + nSignatureSize + nDataLengthSize), nLength);
pCommentData = new SerializeCommon::CommentData();
BinaryCommentReader oBinaryCommentReader(oBufferedStream, NULL);
oBinaryCommentReader.ReadCommentDataExternal(nLength, pCommentData);
oBinaryCommentReader.ReadExternal(nLength, &aDatas);
}
sGfxDataA.ReleaseBuffer();
RELEASEARRAYOBJECTS(pBuffer);
}
}
return pCommentData;
}
void WriteComment(OOX::Spreadsheet::CCommentItem& oComment, SerializeCommon::CommentData* pCommentData, nullable<OOX::Spreadsheet::CSi>& oCommentText)
void WriteComment(OOX::Spreadsheet::CCommentItem& oComment, CAtlArray<SerializeCommon::CommentData*>& aCommentDatas, nullable<OOX::Spreadsheet::CSi>& oCommentText)
{
int nCurPos = 0;
int nRow = 0;
......@@ -2533,7 +2535,7 @@ namespace BinXlsxRW {
m_oBcw.m_oStream.WriteByte(c_oSer_Comments::CommentDatas);
m_oBcw.m_oStream.WriteByte(c_oSerPropLenType::Variable);
nCurPos = m_oBcw.WriteItemWithLengthStart();
WriteCommentData(oComment, pCommentData, oCommentText);
WriteCommentData(oComment, aCommentDatas, oCommentText);
m_oBcw.WriteItemWithLengthEnd(nCurPos);
if(oComment.m_nLeft.IsInit())
......@@ -2621,12 +2623,27 @@ namespace BinXlsxRW {
m_oBcw.m_oStream.WriteBool(oComment.m_bSize.get());
}
}
void WriteCommentData(OOX::Spreadsheet::CCommentItem& oComment, SerializeCommon::CommentData* pCommentData, nullable<OOX::Spreadsheet::CSi>& oCommentText)
void WriteCommentData(OOX::Spreadsheet::CCommentItem& oComment, CAtlArray<SerializeCommon::CommentData*>& aCommentDatas, nullable<OOX::Spreadsheet::CSi>& oCommentText)
{
int nCurPos = 0;
nCurPos = m_oBcw.WriteItemStart(c_oSer_Comments::CommentData);
WriteCommentDataContent(&oComment, pCommentData, &oCommentText);
m_oBcw.WriteItemEnd(nCurPos);
if(aCommentDatas.GetCount() > 0)
{
for(int i = 0, length = aCommentDatas.GetCount(); i < length; ++i)
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_Comments::CommentData);
if(0 == i)
WriteCommentDataContent(&oComment, aCommentDatas[i], &oCommentText);
else
WriteCommentDataContent(NULL, aCommentDatas[i], NULL);
m_oBcw.WriteItemEnd(nCurPos);
}
}
else
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_Comments::CommentData);
WriteCommentDataContent(&oComment, NULL, &oCommentText);
m_oBcw.WriteItemEnd(nCurPos);
}
}
void WriteCommentDataContent(OOX::Spreadsheet::CCommentItem* pComment, SerializeCommon::CommentData* pCommentData, nullable<OOX::Spreadsheet::CSi>* pCommentText)
{
......@@ -2637,16 +2654,13 @@ namespace BinXlsxRW {
m_oBcw.m_oStream.WriteByte(c_oSer_CommentData::Text);
m_oBcw.m_oStream.WriteString2(sText);
}
else if(NULL != pCommentData && !pCommentData->sText.IsEmpty())
{
m_oBcw.m_oStream.WriteByte(c_oSer_CommentData::Text);
m_oBcw.m_oStream.WriteString2(pCommentData->sText);
}
if(NULL != pCommentData)
{
if(NULL == pCommentText)
{
if(!pCommentData->sText.IsEmpty())
{
m_oBcw.m_oStream.WriteByte(c_oSer_CommentData::Text);
m_oBcw.m_oStream.WriteString2(pCommentData->sText);
}
}
if(!pCommentData->sTime.IsEmpty())
{
m_oBcw.m_oStream.WriteByte(c_oSer_CommentData::Time);
......
......@@ -1524,9 +1524,23 @@ namespace BinXlsxRW {
{
return Read1(length, &BinaryCommentReader::ReadComments, this, poResult);
}
int ReadCommentDataExternal(long length, void* poResult)
int ReadExternal(long length, void* poResult)
{
return Read1(length, &BinaryCommentReader::ReadCommentData, this, poResult);
return Read1(length, &BinaryCommentReader::ReadCommentDatasExternal, this, poResult);
}
int ReadCommentDatasExternal(BYTE type, long length, void* poResult)
{
int res = c_oSerConstants::ReadOk;
CAtlArray<SerializeCommon::CommentData*>* pCommentDatas = static_cast<CAtlArray<SerializeCommon::CommentData*>*>(poResult);
if ( c_oSer_Comments::CommentData == type )
{
SerializeCommon::CommentData* oCommentData = new SerializeCommon::CommentData();
res = Read1(length, &BinaryCommentReader::ReadCommentData, this, oCommentData);
pCommentDatas->Add(oCommentData);
}
else
res = c_oSerConstants::ReadUnknown;
return res;
}
int ReadComments(BYTE type, long length, void* poResult)
{
......@@ -1557,7 +1571,46 @@ namespace BinXlsxRW {
else if ( c_oSer_Comments::Col == type )
pNewComment->m_nCol = m_oBufferedStream.ReadLong();
else if ( c_oSer_Comments::CommentDatas == type )
{
if(!pNewComment->m_sGfxdata.IsInit())
{
int nStartPos = m_oBufferedStream.GetPosition();
BYTE* pSourceBuffer = m_oBufferedStream.ReadPointer(length);
m_oBufferedStream.Seek(nStartPos);
CStringA sSignature(_T("XLST"));
int nSignatureSize = sSignature.GetLength();
int nDataLengthSize = sizeof(long);
int nJunkSize = 2;
int nWriteBufferLength = nSignatureSize + nDataLengthSize + length + nJunkSize;
BYTE* pWriteBuffer = new BYTE[nWriteBufferLength];
memcpy(pWriteBuffer, sSignature.GetBuffer(), nSignatureSize);
sSignature.ReleaseBuffer();
memcpy(pWriteBuffer + nSignatureSize, &length, nDataLengthSize);
memcpy(pWriteBuffer + nSignatureSize + nDataLengthSize, pSourceBuffer, length);
// 0, Excel .
memset(pWriteBuffer + nSignatureSize + nDataLengthSize + length, 0, nJunkSize);
int nBase64BufferLen = Base64::Base64EncodeGetRequiredLength(nWriteBufferLength, Base64::B64_BASE64_FLAG_NONE);
BYTE* pbBase64Buffer = new BYTE[nBase64BufferLen];
CString sGfxdata;
if(TRUE == Base64::Base64Encode(pWriteBuffer, nWriteBufferLength, (LPSTR)pbBase64Buffer, &nBase64BufferLen, Base64::B64_BASE64_FLAG_NONE))
{
sGfxdata = CString((LPSTR)pbBase64Buffer, nBase64BufferLen);
// Excel
sGfxdata.Append(_T("\r\n"));
}
RELEASEARRAYOBJECTS(pbBase64Buffer);
RELEASEARRAYOBJECTS(pWriteBuffer);
if(!sGfxdata.IsEmpty())
{
pNewComment->m_sGfxdata.Init();
pNewComment->m_sGfxdata->Append(sGfxdata);
}
}
res = Read1(length, &BinaryCommentReader::ReadCommentDatas, this, pNewComment);
}
else if ( c_oSer_Comments::Left == type )
pNewComment->m_nLeft = m_oBufferedStream.ReadLong();
else if ( c_oSer_Comments::Top == type )
......@@ -1596,43 +1649,6 @@ namespace BinXlsxRW {
OOX::Spreadsheet::CCommentItem* pNewComment = static_cast<OOX::Spreadsheet::CCommentItem*>(poResult);
if ( c_oSer_Comments::CommentData == type )
{
if(!pNewComment->m_sGfxdata.IsInit())
{
int nStartPos = m_oBufferedStream.GetPosition();
BYTE* pSourceBuffer = m_oBufferedStream.ReadPointer(length);
m_oBufferedStream.Seek(nStartPos);
CStringA sSignature(_T("XLST"));
int nSignatureSize = sSignature.GetLength();
int nDataLengthSize = sizeof(long);
int nJunkSize = 2;
int nWriteBufferLength = nSignatureSize + nDataLengthSize + length + nJunkSize;
BYTE* pWriteBuffer = new BYTE[nWriteBufferLength];
memcpy(pWriteBuffer, sSignature.GetBuffer(), nSignatureSize);
sSignature.ReleaseBuffer();
memcpy(pWriteBuffer + nSignatureSize, &length, nDataLengthSize);
memcpy(pWriteBuffer + nSignatureSize + nDataLengthSize, pSourceBuffer, length);
// 0, Excel .
memset(pWriteBuffer + nSignatureSize + nDataLengthSize + length, 0, nJunkSize);
int nBase64BufferLen = Base64::Base64EncodeGetRequiredLength(nWriteBufferLength, Base64::B64_BASE64_FLAG_NONE);
BYTE* pbBase64Buffer = new BYTE[nBase64BufferLen];
CString sGfxdata;
if(TRUE == Base64::Base64Encode(pWriteBuffer, nWriteBufferLength, (LPSTR)pbBase64Buffer, &nBase64BufferLen, Base64::B64_BASE64_FLAG_NONE))
{
sGfxdata = CString((LPSTR)pbBase64Buffer, nBase64BufferLen);
// Excel
sGfxdata.Append(_T("\r\n"));
}
RELEASEARRAYOBJECTS(pbBase64Buffer);
RELEASEARRAYOBJECTS(pWriteBuffer);
if(!sGfxdata.IsEmpty())
{
pNewComment->m_sGfxdata.Init();
pNewComment->m_sGfxdata->Append(sGfxdata);
}
}
if(!pNewComment->m_oText.IsInit())
{
SerializeCommon::CommentData oCommentData;
......
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