Compare commits

...

2 Commits

29 changed files with 313 additions and 66 deletions

View File

@ -140,8 +140,14 @@ namespace NSStringUtils
AddSize(1);
*m_pDataCur++ = _c;
++m_lSizeCur;
}
}
void CStringBuilderA::AddChar2Safe(const char& _c1, const char& _c2)
{
AddSize(2);
*m_pDataCur++ = _c1;
*m_pDataCur++ = _c2;
m_lSizeCur += 2;
}
size_t CStringBuilderA::GetCurSize()
{
return m_lSizeCur;

View File

@ -63,6 +63,7 @@ namespace NSStringUtils
void AddCharNoSafe(const char& _c);
void AddCharSafe(const char& _c);
void AddChar2Safe(const char& _c1, const char& _c2);
size_t GetCurSize();
void SetCurSize(size_t lCurSize);

View File

@ -116,6 +116,7 @@ namespace XmlUtils
void GetTextWithHHHH(bool bPreserve, wchar_t*& sBuffer, long& nSize, long& nLen);
std::wstring GetTextWithHHHH(bool bPreserve);
std::string GetOuterXmlA();
std::wstring GetOuterXml();
std::wstring GetInnerXml();

View File

@ -206,8 +206,11 @@ namespace XmlUtils
std::wstring CXmlLiteReader::GetTextWithHHHH(bool bPreserve)
{
return m_pInternal->GetTextWithHHHH(bPreserve);
}
}
std::string CXmlLiteReader::GetOuterXmlA()
{
return m_pInternal->GetOuterXmlA();
}
std::wstring CXmlLiteReader::GetOuterXml()
{
return m_pInternal->GetOuterXml();

View File

@ -635,6 +635,10 @@ namespace XmlUtils
GetTextWithHHHH(bPreserve, pUnicodes, nSize, nLen);
return std::wstring(pUnicodes, nLen);
}
inline std::string GetOuterXmlA()
{
return GetXmlA(false);
}
inline std::wstring GetOuterXml()
{
return GetXml(false);
@ -700,6 +704,64 @@ namespace XmlUtils
}
private:
inline std::string GetXmlA(bool bInner)
{
if (!IsValid())
return "";
NSStringUtils::CStringBuilderA oResult;
if (false == bInner)
WriteElement(oResult);
int nDepth = GetDepth();
if (0 == xmlTextReaderIsEmptyElement(reader))
{
XmlNodeType eNodeType = XmlNodeType_None;
int nCurDepth = -1;
while (true)
{
if (1 != xmlTextReaderRead(reader))
break;
int nTempType = xmlTextReaderNodeType(reader);
if (-1 == nTempType)
break;
eNodeType = (XmlNodeType)nTempType;
nCurDepth = GetDepth();
if (eNodeType == XmlNodeType_Text ||
eNodeType == XmlNodeType_Whitespace ||
eNodeType == XmlNodeType_SIGNIFICANT_WHITESPACE ||
eNodeType == XmlNodeType_CDATA)
{
oResult.WriteString(GetTextA().c_str());
}
else if (eNodeType == XmlNodeType_Element)
{
WriteElement(oResult);
}
else if (eNodeType == XmlNodeType_EndElement)
{
if (false == bInner || nCurDepth != nDepth)
{
oResult.AddChar2Safe(char('<'), char('/'));
oResult.WriteString(GetNameA().c_str());
oResult.AddCharSafe(char('>'));
}
}
nCurDepth = GetDepth();
if (nCurDepth < nDepth)
break;
if (XmlNodeType_EndElement == eNodeType && nCurDepth == nDepth)
break;
}
}
return oResult.GetData();
}
inline std::wstring GetXml(bool bInner)
{
if (!IsValid())
@ -781,6 +843,33 @@ namespace XmlUtils
else
oResult.AddCharSafe(wchar_t('>'));
}
void WriteElement(NSStringUtils::CStringBuilderA& oResult)
{
oResult.AddCharSafe((char)'<');
oResult.WriteString(GetNameA().c_str());
if (GetAttributesCount() > 0)
{
MoveToFirstAttribute();
std::wstring sName = GetName();
while (!sName.empty())
{
oResult.AddCharSafe(char(' '));
oResult.WriteString(GetNameA().c_str());
oResult.AddChar2Safe(char('='), char('\"'));
oResult.WriteString(GetTextA().c_str());
oResult.AddCharSafe(char('\"'));
if (!MoveToNextAttribute())
break;
sName = GetName();
}
MoveToElement();
}
if (IsEmptyNode())
oResult.AddChar2Safe(char('/'), char('>'));
else
oResult.AddCharSafe(char('>'));
}
};
}

View File

@ -483,7 +483,7 @@ void CFRecord::resetPointerToBegin()
rdPtr = 0;
}
void CFRecord::save(NSBinPptxRW::CXlsbBinaryWriter& writer)
void CFRecord::save(NSBinPptxRW::CXlsyBinaryWriter& writer)
{
writer.XlsbStartRecord(type_id_, rdPtr);
writer.WriteBYTEArray((BYTE*)&intData[0], rdPtr);

View File

@ -90,7 +90,7 @@ public:
void resetPointerToBegin();
//save record to stream
void save(NSBinPptxRW::CXlsbBinaryWriter& writer);
void save(NSBinPptxRW::CXlsyBinaryWriter& writer);
void save(CFStreamPtr& writer);
template<class T>

View File

@ -93,7 +93,7 @@ const size_t CFStreamCacheWriter::writeToStream(const size_t num_of_records_min_
}
//---------------------------------------------------------------------------------------------------------
BinaryStreamCacheWriter::BinaryStreamCacheWriter(boost::shared_ptr<NSBinPptxRW::CXlsbBinaryWriter> binaryStream, GlobalWorkbookInfoPtr global_info)
BinaryStreamCacheWriter::BinaryStreamCacheWriter(boost::shared_ptr<NSBinPptxRW::CXlsyBinaryWriter> binaryStream, GlobalWorkbookInfoPtr global_info)
: StreamCacheWriter(global_info), binaryStream_(binaryStream)
{

View File

@ -71,7 +71,7 @@ protected:
class CFStreamCacheWriter : public StreamCacheWriter
{
public:
CFStreamCacheWriter(CFStreamPtr stream, const GlobalWorkbookInfoPtr global_info);
CFStreamCacheWriter(CFStreamPtr stream, const GlobalWorkbookInfoPtr global_info);
~CFStreamCacheWriter();
// Return the next new CFRecord
@ -92,13 +92,13 @@ private:
class BinaryStreamCacheWriter : public StreamCacheWriter
{
public:
BinaryStreamCacheWriter(boost::shared_ptr<NSBinPptxRW::CXlsbBinaryWriter> binaryStream, const GlobalWorkbookInfoPtr global_info);
BinaryStreamCacheWriter(boost::shared_ptr<NSBinPptxRW::CXlsyBinaryWriter> binaryStream, const GlobalWorkbookInfoPtr global_info);
~BinaryStreamCacheWriter();
const size_t GetRecordPosition()override{return 0;}
private:
const size_t writeToStream(const size_t num_of_records_min_necessary) override;
boost::shared_ptr<NSBinPptxRW::CXlsbBinaryWriter> binaryStream_;
boost::shared_ptr<NSBinPptxRW::CXlsyBinaryWriter> binaryStream_;
};
} // namespace XLS

View File

@ -1485,10 +1485,10 @@ namespace NSBinPptxRW
CBinaryFileWriter::WriteReserved(lCount);
}
CXlsbBinaryWriter::CXlsbBinaryWriter(size_t bufferSize) : CStreamBinaryWriter(bufferSize)
CXlsyBinaryWriter::CXlsyBinaryWriter(size_t bufferSize) : CStreamBinaryWriter(bufferSize)
{
}
void CXlsbBinaryWriter::XlsbStartRecord(_INT16 lType, _INT32 nLen)
void CXlsyBinaryWriter::XlsbStartRecord(_INT16 lType, _INT32 nLen)
{
//Type
if (lType < 0x80)
@ -1516,7 +1516,7 @@ namespace NSBinPptxRW
}
}
}
void CXlsbBinaryWriter::XlsbEndRecord()
void CXlsyBinaryWriter::XlsbEndRecord()
{
}

View File

@ -460,10 +460,10 @@ namespace NSBinPptxRW
void WriteReserved(size_t lCount);
};
class CXlsbBinaryWriter : public CStreamBinaryWriter
class CXlsyBinaryWriter : public CStreamBinaryWriter
{
public:
CXlsbBinaryWriter(size_t bufferSize = 16777216);
CXlsyBinaryWriter(size_t bufferSize = 16777216);
void XlsbStartRecord(_INT16 lType, _INT32 nLen);
void XlsbEndRecord();

View File

@ -474,7 +474,7 @@ namespace BinXlsxRW
DataValidations = 32,
QueryTable = 33,
Controls = 34,
XlsbPos = 35,
XlsyBinaryPos = 35,
SortState = 36,
Slicers = 37,
SlicersExt = 38,
@ -490,7 +490,8 @@ namespace BinXlsxRW
TimelinesList = 48,
Timelines = 49,
Timeline = 50,
TableSingleCells = 51
TableSingleCells = 51,
XlsyDelayedId = 52
};}
namespace c_oSerWorksheetProtection {enum c_oSerWorksheetPropTypes
{

View File

@ -5950,9 +5950,15 @@ void BinaryWorksheetTableWriter::WriteMergeCells(const OOX::Spreadsheet::CMergeC
void BinaryWorksheetTableWriter::WriteSheetData(const OOX::Spreadsheet::CSheetData& oSheetData)
{
int nCurPos;
if(oSheetData.m_oXlsbPos.IsInit())
if (oSheetData.m_nDelayedStep.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSerWorksheetsTypes::XlsbPos);
nCurPos = m_oBcw.WriteItemStart(c_oSerWorksheetsTypes::XlsyDelayedId);
m_oBcw.m_oStream.WriteULONG(*oSheetData.m_nDelayedId);
m_oBcw.WriteItemEnd(nCurPos);
}
else if(oSheetData.m_oXlsbPos.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSerWorksheetsTypes::XlsyBinaryPos);
m_oBcw.m_oStream.WriteLONG(oSheetData.m_oXlsbPos->GetValue());
m_oBcw.WriteItemEnd(nCurPos);
}
@ -9123,7 +9129,9 @@ NSBinPptxRW::CDrawingConverter* pOfficeDrawingConverter, const std::wstring& sXM
pXlsx = new OOX::Spreadsheet::CXlsx();
pXlsx->m_bNeedCalcChain = false;
NSBinPptxRW::CXlsbBinaryWriter oXlsbWriter;
pXlsx->m_bNeedToDelayedRead = true;
NSBinPptxRW::CXlsyBinaryWriter oXlsbWriter;
oXlsbWriter.CreateFileW(sFileDst);
//write dummy header and main table
oXlsbWriter.WriteStringUtf8(WriteFileHeader(0, g_nFormatVersionNoBase64));
@ -9139,12 +9147,12 @@ NSBinPptxRW::CDrawingConverter* pOfficeDrawingConverter, const std::wstring& sXM
if (fileType == 1)
{
pXlsx->m_pXlsbWriter = &oXlsbWriter; // todooo xlsb -> xlst without xlsx write folder
pXlsx->m_pXlsyBinWriter = &oXlsbWriter; // todooo xlsb -> xlst without xlsx write folder
}
//parse
pXlsx->Read(OOX::CPath(sInputDir));
pXlsx->m_pXlsbWriter = NULL;
pXlsx->m_pXlsyBinWriter = NULL;
oXlsbWriter.CloseFile();
m_nLastFilePosOffset = oXlsbWriter.GetPositionAbsolute() - nDataStartPos;
}
@ -9229,6 +9237,59 @@ NSBinPptxRW::CDrawingConverter* pOfficeDrawingConverter, const std::wstring& sXM
//write other records
oFile.WriteFile(pbBinBuffer + nMidPoint, nBinBufferLen - nMidPoint);
oFile.CloseFile();
if (pXlsx)
{
for (const auto& delayed : pXlsx->m_mapXlsyDelayed)
{
XmlUtils::CXmlLiteReader oSubReader;
oSubReader.FromStringA(delayed.second.second);
oSubReader.ReadNextNode();//root
oSubReader.ReadNextNode();
OOX::Spreadsheet::CSheetData* sheetData = dynamic_cast<OOX::Spreadsheet::CSheetData*>(delayed.second.first);
if (sheetData)
{
if (fileType == 1)
{
NSBinPptxRW::CXlsyBinaryWriter oXlsbWriter1;
oXlsbWriter1.CreateFileW(sFileDst + std::to_wstring(delayed.first));
pXlsx->m_pXlsyBinWriter = &oXlsbWriter1; // todooo xlsb -> xlst without xlsx write folder
sheetData->fromXML(oSubReader);
pXlsx->m_pXlsyBinWriter = NULL;
oXlsbWriter1.CloseFile();
}
else
{
sheetData->fromXML(oSubReader);
NSBinPptxRW::CDrawingConverter oOfficeDrawingConverter;
NSBinPptxRW::CBinaryFileWriter& oBufferedStream = *oOfficeDrawingConverter.m_pBinaryWriter;
RELEASEOBJECT(m_oBcw);
m_oBcw = new BinaryCommonWriter(oBufferedStream);
BinaryWorksheetTableWriter oBinaryWorksheetTableWriter(m_oBcw->m_oStream, pEmbeddedFontsManager, NULL, pXlsx->GetTheme(), m_oFontProcessor, &oOfficeDrawingConverter);
oBinaryWorksheetTableWriter.WriteSheetData(*sheetData);
BYTE* pbBinBuffer = oBufferedStream.GetBuffer();
int nBinBufferLen = oBufferedStream.GetPosition();
oFile.CreateFileW(sFileDst + std::to_wstring(delayed.first));
oFile.WriteFile(pbBinBuffer, nBinBufferLen);
oFile.CloseFile();
}
}
else
{
}
}
}
}
else
{

View File

@ -6874,7 +6874,10 @@ int BinaryWorksheetsTableReader::ReadPos(BYTE type, long length, void* poResult)
int BinaryWorksheetsTableReader::ReadSheetData(BYTE type, long length, void* poResult)
{
int res = c_oSerConstants::ReadOk;
if (c_oSerWorksheetsTypes::XlsbPos == type)
if (c_oSerWorksheetsTypes::XlsyDelayedId == type)
{
}
else if (c_oSerWorksheetsTypes::XlsyBinaryPos == type)
{
int nOldPos = m_oBufferedStream.GetPos();
m_oBufferedStream.Seek(m_oBufferedStream.GetULong());

View File

@ -31,21 +31,38 @@
*/
#include "File.h"
#include "../../DesktopEditor/common/File.h"
namespace OOX
{
#define _SIZE_FOR_DELAYED_READ_ 10000000
File::File()
{
m_bDoNotAddRels = false;
m_pMainDocument = NULL;
m_bNeedToDelayedRead = false;
}
File::File(OOX::Document *pMain) : m_pMainDocument(pMain)
{
m_bDoNotAddRels = false;
m_bNeedToDelayedRead = false;
}
File::~File()
{
}
void File::TestDelayedRead(const std::wstring & file_path)
{
NSFile::CFileBinary fileTest;
if (fileTest.OpenFile(file_path) != false)
{
if (_SIZE_FOR_DELAYED_READ_ < fileTest.GetFileSize())
{
m_bNeedToDelayedRead = true;
}
fileTest.CloseFile();
}
}
FileGlobalEnumerated::FileGlobalEnumerated(OOX::Document* pMain) : File(pMain)
{
m_nGlobalNumber = 0;

View File

@ -47,17 +47,22 @@ namespace OOX
File(OOX::Document *pMain);
virtual ~File();
virtual void read(const CPath& filename) = 0;
virtual void read(const CPath& filename) = 0;
virtual void write(const CPath& filename, const CPath& directory, CContentTypes& content) const = 0;
virtual const OOX::FileType type() const = 0;
virtual const CPath DefaultDirectory() const = 0;
virtual const CPath DefaultFileName() const = 0;
std::wstring m_sOutputFilename;
bool m_bDoNotAddRels;
std::wstring m_sOutputFilename;
bool m_bDoNotAddRels;
OOX::Document *m_pMainDocument;
OOX::Document *m_pMainDocument = NULL;
//---------------------------------------------------------------------------------
bool m_bNeedToDelayedRead = false;
void TestDelayedRead(const std::wstring& file_path);
nullable_uint m_nDelayedPosition;
};
class FileGlobalEnumerated : public File

View File

@ -430,7 +430,7 @@ namespace PPTX
BinXlsxRW::BinaryFileWriter xlsxBinaryWriter(oFontProcessor);
OOX::Spreadsheet::CXlsx *pXlsxEmbedded = NULL;
NSBinPptxRW::CXlsbBinaryWriter oXlsbWriter;
NSBinPptxRW::CXlsyBinaryWriter oXlsbWriter;
if (office_checker.nFileType == AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSB)
pXlsxEmbedded = new OOX::Spreadsheet::CXlsb();
@ -440,7 +440,7 @@ namespace PPTX
oXlsbWriter.WriteReserved(xlsxBinaryWriter.GetMainTableSize());
unsigned int nXlsbWriterStartPos = oXlsbWriter.GetPositionAbsolute();
pXlsxEmbedded->m_pXlsbWriter = &oXlsbWriter;
pXlsxEmbedded->m_pXlsyBinWriter = &oXlsbWriter;
pXlsxEmbedded->m_bNeedCalcChain = false;
pXlsxEmbedded->Read(oox_unpacked);
@ -463,7 +463,7 @@ namespace PPTX
xlsxBinaryWriter.WriteContent(pXlsxEmbedded, NULL, &oDrawingConverter);
xlsxBinaryWriter.WriteMainTableEnd();
pXlsxEmbedded->m_pXlsbWriter = NULL;
pXlsxEmbedded->m_pXlsyBinWriter = NULL;
delete pXlsxEmbedded;
}

View File

@ -554,7 +554,7 @@ namespace PPTX
//----------------------------
BinXlsxRW::BinaryFileWriter xlsxBinaryWriter(oFontProcessor);
OOX::Spreadsheet::CXlsx *pXlsxEmbedded = NULL;
NSBinPptxRW::CXlsbBinaryWriter oXlsbWriter;
NSBinPptxRW::CXlsyBinaryWriter oXlsbWriter;
if (office_checker.nFileType == AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSB)
pXlsxEmbedded = new OOX::Spreadsheet::CXlsb();
@ -566,7 +566,7 @@ namespace PPTX
oXlsbWriter.WriteReserved(xlsxBinaryWriter.GetMainTableSize());
unsigned int nXlsbWriterStartPos = oXlsbWriter.GetPositionAbsolute();
pXlsxEmbedded->m_pXlsbWriter = &oXlsbWriter;
pXlsxEmbedded->m_pXlsyBinWriter = &oXlsbWriter;
pXlsxEmbedded->m_bNeedCalcChain = false;
pXlsxEmbedded->Read(oox_unpacked);
@ -591,7 +591,7 @@ namespace PPTX
xlsxBinaryWriter.WriteContent(pXlsxEmbedded, NULL, &oDrawingConverter);
xlsxBinaryWriter.WriteMainTableEnd();
pXlsxEmbedded->m_pXlsbWriter = NULL;
pXlsxEmbedded->m_pXlsyBinWriter = NULL;
delete pXlsxEmbedded;
//------------------------------

View File

@ -69,7 +69,7 @@ void OOX::Spreadsheet::CXlsb::init()
xls_global_info = boost::shared_ptr<XLS::GlobalWorkbookInfo>(new XLS::GlobalWorkbookInfo(workbook_code_page, nullptr));
xls_global_info->Version = 0x0800;
m_binaryReader = boost::shared_ptr<NSBinPptxRW::CBinaryFileReader>(new NSBinPptxRW::CBinaryFileReader);
m_binaryWriter = boost::shared_ptr<NSBinPptxRW::CXlsbBinaryWriter>(new NSBinPptxRW::CXlsbBinaryWriter);
m_binaryWriter = boost::shared_ptr<NSBinPptxRW::CXlsyBinaryWriter>(new NSBinPptxRW::CXlsyBinaryWriter);
m_bWriteToXlsx = false;
}
bool OOX::Spreadsheet::CXlsb::ReadBin(const CPath& oFilePath, XLS::BaseObject* objStream)

View File

@ -91,7 +91,7 @@ namespace OOX
void init();
XLS::GlobalWorkbookInfoPtr xls_global_info;
boost::shared_ptr<NSBinPptxRW::CBinaryFileReader> m_binaryReader;
boost::shared_ptr<NSBinPptxRW::CXlsbBinaryWriter> m_binaryWriter;
boost::shared_ptr<NSBinPptxRW::CXlsyBinaryWriter> m_binaryWriter;
unsigned short workbook_code_page;
std::wstring m_sPath;

View File

@ -348,7 +348,7 @@ namespace OOX
}
}
}
void CSi::toXLSBExt (NSBinPptxRW::CXlsbBinaryWriter& oStream)
void CSi::toXLSBExt (NSBinPptxRW::CXlsyBinaryWriter& oStream)
{
//it's not by XLSB format
oStream.WriteULONG(m_arrItems.size());

View File

@ -37,7 +37,7 @@
namespace NSBinPptxRW
{
class CBinaryFileReader;
class CXlsbBinaryWriter;
class CXlsyBinaryWriter;
}
namespace OOX
@ -67,7 +67,7 @@ namespace OOX
XLS::BiffStructurePtr toXLS() const;
void fromXLSBExt (NSBinPptxRW::CBinaryFileReader& oStream);
void toXLSBExt (NSBinPptxRW::CXlsbBinaryWriter& oStream);
void toXLSBExt (NSBinPptxRW::CXlsyBinaryWriter& oStream);
_UINT32 getXLSBSize() const;
virtual EElementType getType () const;

View File

@ -1333,7 +1333,7 @@ namespace OOX
//oStream.Seek(nEnd);
}
void CRPr::toXLSB (NSBinPptxRW::CXlsbBinaryWriter& oStream) const
void CRPr::toXLSB (NSBinPptxRW::CXlsyBinaryWriter& oStream) const
{
//oStream.XlsbStartRecord();

View File

@ -38,7 +38,7 @@
namespace NSBinPptxRW
{
class CBinaryFileReader;
class CXlsbBinaryWriter;
class CXlsyBinaryWriter;
}
namespace SimpleTypes
@ -308,7 +308,7 @@ namespace OOX
void fromFont(CFont* font);
CFont* toFont();
void fromXLSB (NSBinPptxRW::CBinaryFileReader& oStream, _UINT16 nType);
void toXLSB (NSBinPptxRW::CXlsbBinaryWriter& oStream) const;
void toXLSB (NSBinPptxRW::CXlsyBinaryWriter& oStream) const;
_UINT32 getXLSBSize() const;
virtual EElementType getType () const;

View File

@ -94,6 +94,8 @@
#define MININT32 ((int32_t)~MAXINT32)
#endif
#define _MAX_COUNT_DELAYED_READ_ 200
using namespace XLS;
namespace OOX
@ -495,7 +497,7 @@ namespace OOX
}
return nLen;
}
_UINT16 CFormulaXLSB::toXLSB(NSBinPptxRW::CXlsbBinaryWriter& oStream, bool bIsBlankFormula)
_UINT16 CFormulaXLSB::toXLSB(NSBinPptxRW::CXlsyBinaryWriter& oStream, bool bIsBlankFormula)
{
_UINT16 nFlags = 0;
if(m_oCa.ToBool())
@ -555,7 +557,7 @@ namespace OOX
}
return nFlagsExt;
}
void CFormulaXLSB::toXLSBExt(NSBinPptxRW::CXlsbBinaryWriter& oStream)
void CFormulaXLSB::toXLSBExt(NSBinPptxRW::CXlsyBinaryWriter& oStream)
{
if(!m_bIsInit)
return;
@ -645,7 +647,7 @@ namespace OOX
WritingElement_ReadAttributes_EndChar( oReader )
}
void CCellXLSB::toXLSB(NSBinPptxRW::CXlsbBinaryWriter& oStream)
void CCellXLSB::toXLSB(NSBinPptxRW::CXlsyBinaryWriter& oStream)
{
_INT16 nType = XLSB::rt_CellBlank;
if(m_oFormula.m_bIsInit && SimpleTypes::Spreadsheet::celltypeSharedString == m_oType.GetValue())
@ -802,7 +804,7 @@ namespace OOX
m_oThickTop.FromBool(false);
m_oPh.FromBool(false);
}
void CRowXLSB::fromXMLToXLSB(XmlUtils::CXmlLiteReader& oReader, NSBinPptxRW::CXlsbBinaryWriter& oStream, CCellXLSB& oCell)
void CRowXLSB::fromXMLToXLSB(XmlUtils::CXmlLiteReader& oReader, NSBinPptxRW::CXlsyBinaryWriter& oStream, CCellXLSB& oCell)
{
ReadAttributes( oReader );
@ -828,7 +830,7 @@ namespace OOX
}
}
}
void CRowXLSB::toXLSB(NSBinPptxRW::CXlsbBinaryWriter& oStream)
void CRowXLSB::toXLSB(NSBinPptxRW::CXlsyBinaryWriter& oStream)
{
oStream.XlsbStartRecord(XLSB::rt_RowHdr, 17);
oStream.WriteULONG(m_nR & 0xFFFFF);
@ -4836,13 +4838,13 @@ namespace OOX
{
xlsx_flat->m_nLastReadRow = 0;
}
if (xlsx && xlsx->m_pXlsbWriter)
if (xlsx && xlsx->m_pXlsyBinWriter)
{
int nLastRow = -1;
CRowXLSB oRow;
oRow.m_nR = nLastRow;
CCellXLSB oCell;
NSBinPptxRW::CXlsbBinaryWriter& oStream = *xlsx->m_pXlsbWriter;
NSBinPptxRW::CXlsyBinaryWriter& oStream = *xlsx->m_pXlsyBinWriter;
m_oXlsbPos.Init();
m_oXlsbPos->SetValue(oStream.GetPositionAbsolute());
@ -4850,31 +4852,55 @@ namespace OOX
oStream.XlsbEndRecord();
int nCurDepth = oReader.GetDepth();
_UINT32 idxRow = 0;
while( oReader.ReadNextSiblingNode( nCurDepth ) )
{
const char* sName = XmlUtils::GetNameNoNS(oReader.GetNameChar());
if (m_nDelayedStep.IsInit())
{
if (*m_nDelayedStep == 1 && idxRow > _MAX_COUNT_DELAYED_READ_ - 1)
break;
idxRow++;
if (*m_nDelayedStep == 2 && idxRow < _MAX_COUNT_DELAYED_READ_)
continue;
}
if ( strcmp("row", sName) == 0 )
{
nLastRow = oRow.m_nR;
oRow.Clean();
oRow.m_nR = nLastRow + 1;
oRow.fromXMLToXLSB(oReader, *xlsx->m_pXlsbWriter, oCell);
oRow.fromXMLToXLSB(oReader, *xlsx->m_pXlsyBinWriter, oCell);
}
}
oStream.XlsbStartRecord(XLSB::rt_EndSheetData, 0);
oStream.XlsbEndRecord();
}
else
{
int nCurDepth = oReader.GetDepth();
_UINT32 idxRow = 0;
while( oReader.ReadNextSiblingNode( nCurDepth ) )
{
const char* sName = XmlUtils::GetNameNoNS(oReader.GetNameChar());
if ( strcmp("row", sName) == 0 || strcmp("Row", sName) == 0)
{
if (m_nDelayedStep.IsInit())
{
if (*m_nDelayedStep == 1 && idxRow > _MAX_COUNT_DELAYED_READ_ - 1)
break;
idxRow++;
if (*m_nDelayedStep == 2 && idxRow < _MAX_COUNT_DELAYED_READ_)
continue;
}
CRow *pRow = new CRow(m_pMainDocument);
if (pRow)
{
@ -4910,6 +4936,8 @@ namespace OOX
}
}
}
if (m_nDelayedStep.IsInit())
m_nDelayedStep = 2;
}
void CSheetData::AfterRead()
{

View File

@ -40,7 +40,7 @@
namespace NSBinPptxRW
{
class CBinaryFileReader;
class CXlsbBinaryWriter;
class CXlsyBinaryWriter;
}
namespace NSFile
{
@ -63,8 +63,8 @@ namespace OOX
void Clean();
void fromXML(XmlUtils::CXmlLiteReader& oReader);
_UINT32 getXLSBSize();
_UINT16 toXLSB(NSBinPptxRW::CXlsbBinaryWriter& oStream, bool bIsBlankFormula);
void toXLSBExt(NSBinPptxRW::CXlsbBinaryWriter& oStream);
_UINT16 toXLSB(NSBinPptxRW::CXlsyBinaryWriter& oStream, bool bIsBlankFormula);
void toXLSBExt(NSBinPptxRW::CXlsyBinaryWriter& oStream);
bool m_bIsInit;
CStringXLSB m_oFormula;
@ -90,7 +90,7 @@ namespace OOX
CCellXLSB();
void Clean();
void fromXML(XmlUtils::CXmlLiteReader& oReader);
void toXLSB(NSBinPptxRW::CXlsbBinaryWriter& oStream);
void toXLSB(NSBinPptxRW::CXlsyBinaryWriter& oStream);
_UINT32 m_nCol;
_UINT32 m_nStyle;
@ -112,8 +112,8 @@ namespace OOX
public:
CRowXLSB();
void Clean();
void fromXMLToXLSB(XmlUtils::CXmlLiteReader& oReader, NSBinPptxRW::CXlsbBinaryWriter& oStream, CCellXLSB& oCell);
void toXLSB(NSBinPptxRW::CXlsbBinaryWriter& oStream);
void fromXMLToXLSB(XmlUtils::CXmlLiteReader& oReader, NSBinPptxRW::CXlsyBinaryWriter& oStream, CCellXLSB& oCell);
void toXLSB(NSBinPptxRW::CXlsyBinaryWriter& oStream);
public:
_UINT32 m_nR;
_UINT32 m_nS;
@ -304,9 +304,9 @@ namespace OOX
void toXMLStart(NSStringUtils::CStringBuilder& writer) const;
void toXMLEnd(NSStringUtils::CStringBuilder& writer) const;
virtual void fromXML(XmlUtils::CXmlLiteReader& oReader);
void fromXMLToXLSB(XmlUtils::CXmlLiteReader& oReader, NSBinPptxRW::CXlsbBinaryWriter& oStream, CCellXLSB& oCell);
void fromXMLToXLSB(XmlUtils::CXmlLiteReader& oReader, NSBinPptxRW::CXlsyBinaryWriter& oStream, CCellXLSB& oCell);
void fromXLSB (NSBinPptxRW::CBinaryFileReader& oStream, _UINT16 nType);
void toXLSB (NSBinPptxRW::CXlsbBinaryWriter& oStream) const;
void toXLSB (NSBinPptxRW::CXlsyBinaryWriter& oStream) const;
void fromBin(XLS::BaseObjectPtr& obj);
void fromBin(XLS::StreamCacheReaderPtr& reader);
@ -348,7 +348,7 @@ namespace OOX
{
public:
WritingElement_AdditionMethods(CSheetData)
//WritingElement_XlsbConstructors(CSheetData)
CSheetData(OOX::Document *pMain = NULL);
virtual ~CSheetData();
@ -378,6 +378,9 @@ namespace OOX
void AfterRead();
void ClearSharedFmlaRefs();
nullable_int m_nDelayedStep;
nullable_uint m_nDelayedId;
private:
void fromXLSBToXmlCell (CCell& pCell, CSVWriter* pCSVWriter, NSFile::CStreamWriter& oStreamWriter);
void fromXLSBToXmlRowStart (CRow* pRow, CSVWriter* pCSVWriter, NSFile::CStreamWriter& oStreamWriter);

View File

@ -619,7 +619,9 @@ namespace OOX
m_oReadPath = oPath;
IFileContainer::Read( oRootPath, oPath );
if( m_oReadPath.GetExtention() == _T(".bin"))
OOX::File::TestDelayedRead(oPath.GetPath());
if( m_oReadPath.GetExtention() == L".bin")
{
readBin(m_oReadPath);
}
@ -691,7 +693,33 @@ namespace OOX
else if (L"sheetData" == sName || L"Table" == sName) // 2002 XML Format
{
m_oSheetData = new CSheetData(OOX::WritingElement::m_pMainDocument);
m_oSheetData->fromXML(oReader);
CXlsx* xlsx = dynamic_cast<CXlsx*>(OOX::WritingElement::m_pMainDocument);
if (m_bNeedToDelayedRead && xlsx && xlsx->m_bNeedToDelayedRead)
{
m_oSheetData->m_nDelayedStep = 1;
m_oSheetData->m_nDelayedId = xlsx->m_mapXlsyDelayed.size() + 1;
std::string sBegin("<root \
xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" mc:Ignorable=\"x14ac xr xr2 xr3\" xmlns:x14ac=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac\" xmlns:xr=\"http://schemas.microsoft.com/office/spreadsheetml/2014/revision\" xmlns:xr2=\"http://schemas.microsoft.com/office/spreadsheetml/2015/revision2\" xmlns:xr3=\"http://schemas.microsoft.com/office/spreadsheetml/2016/revision3\">");
std::string sEnd("</root>");
_CP_LOG << L"\t\tstart outer xml"<< std::endl;
std::string delayed = sBegin + oReader.GetOuterXmlA() + sEnd;
_CP_LOG << L"\t\tend outer xml" << std::endl;
xlsx->m_mapXlsyDelayed.insert(std::make_pair(*m_oSheetData->m_nDelayedId, std::make_pair(dynamic_cast<OOX::WritingElement*>(m_oSheetData.GetPointer()), delayed)));
XmlUtils::CXmlLiteReader oSubReader;
oSubReader.FromStringA(delayed);
oSubReader.ReadNextNode();//root
oSubReader.ReadNextNode();//sheetData / Table
m_oSheetData->fromXML(oSubReader);
}
else
m_oSheetData->fromXML(oReader);
}
else if (L"WorksheetOptions" == sName) // 2002 XML Format
{

View File

@ -93,6 +93,7 @@ OOX::Spreadsheet::CXlsx::~CXlsx()
}
m_arWorksheets.clear();
m_mapWorksheets.clear();
m_mapXlsyDelayed.clear();
}
void OOX::Spreadsheet::CXlsx::init()
{
@ -108,7 +109,7 @@ void OOX::Spreadsheet::CXlsx::init()
m_pVbaProject = NULL;
m_pJsaProject = NULL;
m_pWorkbookComments = NULL;
m_pXlsbWriter = NULL;
m_pXlsyBinWriter = NULL;
m_nLastReadRow = 0;
m_nLastReadCol = -1;
m_bNeedCalcChain = true;

View File

@ -54,7 +54,6 @@ namespace OOX
class CXlsx : public OOX::Document, public OOX::IFileContainer
{
public:
CXlsx();
CXlsx(const CPath& oFilePath);
virtual ~CXlsx();
@ -92,7 +91,6 @@ namespace OOX
OOX::JsaProject* m_pJsaProject;
WorkbookComments* m_pWorkbookComments;
NSBinPptxRW::CXlsbBinaryWriter* m_pXlsbWriter;
int m_nLastReadRow;
int m_nLastReadCol;
bool m_bNeedCalcChain;// disable because it is useless but reading takes considerable time
@ -108,8 +106,10 @@ namespace OOX
bool bDeleteVbaProject;
bool bDeleteJsaProject;
bool m_bNeedToDelayedRead = false;
NSBinPptxRW::CXlsyBinaryWriter* m_pXlsyBinWriter = NULL;
std::map<unsigned int, std::pair<OOX::WritingElement*, std::string>> m_mapXlsyDelayed;
private:
void PrepareWorksheet(CWorksheet* pWorksheet);
void init();