Commit 00596f43 authored by ElenaSubbotina's avatar ElenaSubbotina

XlsFormat - fix bugs, add ColorScale

parent b49b8246
...@@ -95,6 +95,7 @@ void CFStream::write(const void* buf, const size_t size) ...@@ -95,6 +95,7 @@ void CFStream::write(const void* buf, const size_t size)
str << L"Only " << num_written << L" unsigned chars were saved instead of " << size << L" unsigned chars requested."; str << L"Only " << num_written << L" unsigned chars were saved instead of " << size << L" unsigned chars requested.";
throw;// EXCEPT::RT::CompoundFileFormatError(str.str(), hres); throw;// EXCEPT::RT::CompoundFileFormatError(str.str(), hres);
} }
stream_->flush();
// Tipa successful // Tipa successful
} }
......
...@@ -53,14 +53,17 @@ bool CompoundFile::isError() ...@@ -53,14 +53,17 @@ bool CompoundFile::isError()
return true; return true;
} }
bool CompoundFile::Open(const std::wstring & file_path, const ReadWriteMode mode)
CompoundFile::CompoundFile(const std::wstring & file_path, const ReadWriteMode mode)
: rwMode(mode)
{ {
if (storage_) delete storage_;
storage_ = NULL;
rwMode = mode;
unsigned int grfMode = 0; unsigned int grfMode = 0;
storage_ = new POLE::Storage(file_path.c_str()); storage_ = new POLE::Storage(file_path.c_str());
if (storage_ == NULL) return; if (storage_ == NULL) return false;
switch(rwMode) switch(rwMode)
{ {
...@@ -82,6 +85,16 @@ CompoundFile::CompoundFile(const std::wstring & file_path, const ReadWriteMode m ...@@ -82,6 +85,16 @@ CompoundFile::CompoundFile(const std::wstring & file_path, const ReadWriteMode m
} }
}break; }break;
} }
if (storage_ == NULL) return false;
return true;
}
CompoundFile::CompoundFile(const std::wstring & file_path, const ReadWriteMode mode)
{
storage_ = NULL;
Open(file_path, mode);
} }
...@@ -108,6 +121,11 @@ CFStreamPtr CompoundFile::createWorkbookStream() ...@@ -108,6 +121,11 @@ CFStreamPtr CompoundFile::createWorkbookStream()
return createNamedStream("Workbook"); return createNamedStream("Workbook");
} }
void CompoundFile::closeWorkbookStream()
{
return closeNamedStream("Workbook");
}
// Opens "SummaryInformation" stream and returns the only reference // Opens "SummaryInformation" stream and returns the only reference
CFStreamPtr CompoundFile::getSummaryInformationStream() CFStreamPtr CompoundFile::getSummaryInformationStream()
...@@ -147,7 +165,7 @@ CFStreamPtr CompoundFile::createDocumentSummaryInformationStream() ...@@ -147,7 +165,7 @@ CFStreamPtr CompoundFile::createDocumentSummaryInformationStream()
// Closes "SummaryInformation" stream // Closes "SummaryInformation" stream
void CompoundFile::closeDocumentSummaryInformationStream() void CompoundFile::closeDocumentSummaryInformationStream()
{ {
closeNamedStream("DocumentSummaryInformation"); return closeNamedStream("DocumentSummaryInformation");
} }
......
...@@ -53,11 +53,14 @@ public: ...@@ -53,11 +53,14 @@ public:
public: public:
CompoundFile(const std::wstring & file_path, const ReadWriteMode mode); CompoundFile(const std::wstring & file_path, const ReadWriteMode mode);
~CompoundFile(); ~CompoundFile();
bool Open(const std::wstring & file_path, const ReadWriteMode mode);
bool isError(); bool isError();
CFStreamPtr getWorkbookStream(); CFStreamPtr getWorkbookStream();
CFStreamPtr createWorkbookStream(); CFStreamPtr createWorkbookStream();
void closeWorkbookStream();
CFStreamPtr getSummaryInformationStream(); CFStreamPtr getSummaryInformationStream();
CFStreamPtr createSummaryInformationStream(); CFStreamPtr createSummaryInformationStream();
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <Logic/Biff_structures/CFMultistate.h> #include <Logic/Biff_structures/CFMultistate.h>
#include <Logic/Biff_structures/CFDatabar.h> #include <Logic/Biff_structures/CFDatabar.h>
#include <Logic/Biff_structures/CFGradient.h>
#include <utils.h> #include <utils.h>
namespace XLS namespace XLS
...@@ -98,14 +99,15 @@ void CF12::readFields(CFRecord& record) ...@@ -98,14 +99,15 @@ void CF12::readFields(CFRecord& record)
switch(ct) switch(ct)
{ {
case 0x03: case 0x03:
//rgbCT = BiffStructurePtr(new CFGradient); rgbCT = BiffStructurePtr(new CFGradient);
//rgbCT->load(record); rgbCT->load(record);
break; break;
case 0x04: case 0x04:
rgbCT = BiffStructurePtr(new CFDatabar); rgbCT = BiffStructurePtr(new CFDatabar);
rgbCT->load(record); rgbCT->load(record);
break; break;
case 0x05: case 0x05:
//todooo
//rgbCT = BiffStructurePtr(new CFFilter); //rgbCT = BiffStructurePtr(new CFFilter);
//rgbCT->load(record); //rgbCT->load(record);
break; break;
...@@ -117,9 +119,10 @@ void CF12::readFields(CFRecord& record) ...@@ -117,9 +119,10 @@ void CF12::readFields(CFRecord& record)
ipriority_ = ++record.getGlobalWorkbookInfo()->cmt_rules; ipriority_ = ++record.getGlobalWorkbookInfo()->cmt_rules;
dxf.serialize(record.getGlobalWorkbookInfo()->users_Dxfs_stream); if ( 0 == dxf.serialize(record.getGlobalWorkbookInfo()->users_Dxfs_stream))
dxfId_ = global_info->cellStyleDxfs_count++; dxfId_ = global_info->cellStyleDxfs_count++;
else
dxfId_ = -1;
} }
int CF12::serialize(std::wostream & stream) int CF12::serialize(std::wostream & stream)
{ {
...@@ -135,6 +138,7 @@ int CF12::serialize(std::wostream & stream) ...@@ -135,6 +138,7 @@ int CF12::serialize(std::wostream & stream)
{ {
case 1: CP_XML_ATTR(L"type", L"cellIs"); break; case 1: CP_XML_ATTR(L"type", L"cellIs"); break;
case 2: CP_XML_ATTR(L"type", L"expression"); break; case 2: CP_XML_ATTR(L"type", L"expression"); break;
case 3: CP_XML_ATTR(L"type", L"colorScale"); break;
case 4: CP_XML_ATTR(L"type", L"dataBar"); break; case 4: CP_XML_ATTR(L"type", L"dataBar"); break;
case 6: CP_XML_ATTR(L"type", L"iconSet"); break; case 6: CP_XML_ATTR(L"type", L"iconSet"); break;
} }
...@@ -155,8 +159,52 @@ int CF12::serialize(std::wostream & stream) ...@@ -155,8 +159,52 @@ int CF12::serialize(std::wostream & stream)
CP_XML_ATTR(L"priority", ipriority_); CP_XML_ATTR(L"priority", ipriority_);
CP_XML_ATTR(L"stopIfTrue", fStopIfTrue); CP_XML_ATTR(L"stopIfTrue", fStopIfTrue);
CP_XML_ATTR(L"dxfId", dxfId_); if (dxfId_ >= 0)
CP_XML_ATTR(L"dxfId", dxfId_);
if (ct == 3)
{
CFGradient *gradient = dynamic_cast<CFGradient*>(rgbCT.get());
CP_XML_NODE(L"colorScale")
{
for (int i = 0; i < gradient->rgInterp.size(); i ++)
{
CP_XML_NODE(L"cfvo")
{
CFVO & cfvo = gradient->rgInterp[i]->cfvo;
switch(cfvo.cfvoType)
{
case 2: CP_XML_ATTR(L"type", L"min"); break;
case 3: CP_XML_ATTR(L"type", L"max"); break;
case 7: CP_XML_ATTR(L"type", L"formule"); break;
case 4: CP_XML_ATTR(L"type", L"percent"); break;
case 5: CP_XML_ATTR(L"type", L"percentile"); break;
default:
CP_XML_ATTR(L"type", L"percentile"); break;
}
if (cfvo.cfvoType == 7)
CP_XML_ATTR(L"val", cfvo.fmla.getAssembledFormula());
else
CP_XML_ATTR(L"val", cfvo.numValue);
}
}
for (int i = 0; i < gradient->rgCurve.size(); i ++)
{
CP_XML_NODE(L"color")
{
CFColor & color = gradient->rgCurve[i]->color;
switch(color.type)
{
case 1: CP_XML_ATTR(L"indexed", color.icv); break;
case 2: CP_XML_ATTR(L"rgb", color.rgb.strARGB); break;
case 3: CP_XML_ATTR(L"theme", color.theme);
CP_XML_ATTR(L"tint", color.numTint); break;
default: CP_XML_ATTR(L"auto", true);
}
}
}
}
}
if (ct == 4) if (ct == 4)
{ {
CFDatabar *dataBar = dynamic_cast<CFDatabar*>(rgbCT.get()); CFDatabar *dataBar = dynamic_cast<CFDatabar*>(rgbCT.get());
......
...@@ -91,7 +91,8 @@ void CalcMode::readFields(CFRecord& record) ...@@ -91,7 +91,8 @@ void CalcMode::readFields(CFRecord& record)
fAutoRecalc = std::wstring (L"autoNoTable"); fAutoRecalc = std::wstring (L"autoNoTable");
break; break;
default: default:
throw;// EXCEPT::RT::WrongBiffRecord("Unsupported value of fAutoRecalc.", record.getTypeString()); fAutoRecalc = std::wstring (L"auto");
// EXCEPT::RT::WrongBiffRecord("Unsupported value of fAutoRecalc.", record.getTypeString());
} }
} }
......
...@@ -69,6 +69,8 @@ void XFExt::readFields(CFRecord& record) ...@@ -69,6 +69,8 @@ void XFExt::readFields(CFRecord& record)
record >> cexts; record >> cexts;
while(!record.isEOF()) while(!record.isEOF())
{ {
if(record.getRdPtr() + 8 < record.getDataSize())
break;// 8 = миним размер структуры
ExtPropPtr element(new ExtProp); ExtPropPtr element(new ExtProp);
record >> *element; record >> *element;
rgExt.push_back(element); rgExt.push_back(element);
......
...@@ -47,7 +47,6 @@ CFColor::CFColor(CFRecord& record) ...@@ -47,7 +47,6 @@ CFColor::CFColor(CFRecord& record)
load(record); load(record);
} }
BiffStructurePtr CFColor::clone() BiffStructurePtr CFColor::clone()
{ {
return BiffStructurePtr(new CFColor(*this)); return BiffStructurePtr(new CFColor(*this));
...@@ -58,7 +57,6 @@ void CFColor::store(CFRecord& record) ...@@ -58,7 +57,6 @@ void CFColor::store(CFRecord& record)
{ {
} }
void CFColor::load(CFRecord& record) void CFColor::load(CFRecord& record)
{ {
record >> xclrType; record >> xclrType;
......
...@@ -46,7 +46,7 @@ class CFDatabar : public BiffStructure ...@@ -46,7 +46,7 @@ class CFDatabar : public BiffStructure
public: public:
BiffStructurePtr clone(); BiffStructurePtr clone();
static const ElementType type = typeCFMultistate;//todoooo static const ElementType type = typeCFDatabar;
virtual void load(CFRecord& record); virtual void load(CFRecord& record);
virtual void store(CFRecord& record); virtual void store(CFRecord& record);
......
/*
* (c) Copyright Ascensio System SIA 2010-2016
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#include "CFGradient.h"
#include <Binary/CFRecord.h>
namespace XLS
{
BiffStructurePtr CFGradientInterpItem::clone()
{
return BiffStructurePtr(new CFGradientInterpItem(*this));
}
void CFGradientInterpItem::store(CFRecord& record)
{
}
void CFGradientInterpItem::load(CFRecord& record)
{
cfvo.load(record);
record >> numDomain;
//record.skipNunBytes(8);
//int val;
//record >> val; numDomain = val << 32;
//record >> val; numDomain = val;
}
//---------------------------------------------------------------------------------------------
BiffStructurePtr CFGradientItem::clone()
{
return BiffStructurePtr(new CFGradientItem(*this));
}
void CFGradientItem::store(CFRecord& record)
{
}
void CFGradientItem::load(CFRecord& record)
{
//int val;
//record >> val; numGrange = val << 32;
//record >> val; numGrange = val;
//record.skipNunBytes(8);
color.load(record);
record >> numGrange;
}
//--------------------------------------------------------------------------------------------
BiffStructurePtr CFGradient::clone()
{
return BiffStructurePtr(new CFGradient(*this));
}
void CFGradient::store(CFRecord& record)
{
}
void CFGradient::load(CFRecord& record)
{
record.skipNunBytes(2); // unused
record.skipNunBytes(1); // reserved
record >> cInterpCurve;
record >> cGradientCurve;
unsigned char flags;
record >> flags;
fClamp = GETBIT(flags, 0);
fBackground = GETBIT(flags, 1);
for (int i = 0; i < cInterpCurve; i++)
{
CFGradientInterpItemPtr item = CFGradientInterpItemPtr(new CFGradientInterpItem());
item->load(record);
//item.cfvo.load(record);
//record >> val; item.numDomain = val << 32;
//record >> val; item.numDomain += val;
rgInterp.push_back(item);
}
for (int i = 0; i < cGradientCurve; i++)
{
CFGradientItemPtr item = CFGradientItemPtr(new CFGradientItem());
item->load(record);
//record >> val; item.numGrange = val << 32;
//record >> val; item.numGrange += val;
////record >> item.numGrange;
//item.color.load(record);
rgCurve.push_back(item);
}
}
} // namespace XLS
/*
* (c) Copyright Ascensio System SIA 2010-2016
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#pragma once
#include "BiffStructure.h"
#include "CFVO.h"
#include "CFColor.h"
namespace XLS
{
class CFRecord;
struct CFGradientInterpItem : public BiffStructure
{
BASE_STRUCTURE_DEFINE_CLASS_NAME(CFGradientInterpItem)
public:
BiffStructurePtr clone();
static const ElementType type = typeAnyObject;
virtual void load(CFRecord& record);
virtual void store(CFRecord& record);
CFVO cfvo;
double numDomain;
};
typedef boost::shared_ptr<CFGradientInterpItem> CFGradientInterpItemPtr;
struct CFGradientItem : public BiffStructure
{
BASE_STRUCTURE_DEFINE_CLASS_NAME(CFGradientItem)
public:
BiffStructurePtr clone();
static const ElementType type = typeAnyObject;
virtual void load(CFRecord& record);
virtual void store(CFRecord& record);
double numGrange;
CFColor color;
};
typedef boost::shared_ptr<CFGradientItem> CFGradientItemPtr;
class CFGradient : public BiffStructure
{
BASE_STRUCTURE_DEFINE_CLASS_NAME(CFGradient)
public:
BiffStructurePtr clone();
static const ElementType type = typeCFGradient;
virtual void load(CFRecord& record);
virtual void store(CFRecord& record);
unsigned char cInterpCurve; //MUST be 0x2 or 0x3.
unsigned char cGradientCurve; // == cInterpCurve
bool fClamp;
bool fBackground;
std::vector<CFGradientInterpItemPtr>rgInterp;
std::vector<CFGradientItemPtr> rgCurve;
};
typedef boost::shared_ptr<CFGradient> CFGradientPtr;
} // namespace XLS
...@@ -91,7 +91,7 @@ void DXFN12::load(CFRecord& record) ...@@ -91,7 +91,7 @@ void DXFN12::load(CFRecord& record)
int DXFN12::serialize(std::wostream & stream) int DXFN12::serialize(std::wostream & stream)
{ {
if (!dxfn) return 0; if (!dxfn) return -1;
if (!xfext) if (!xfext)
{ {
......
...@@ -46,7 +46,7 @@ public: ...@@ -46,7 +46,7 @@ public:
BiffStructurePtr clone(); BiffStructurePtr clone();
static const ElementType type = typeDXFPat; static const ElementType type = typeDXFPat;
virtual void load(CFRecord& record); virtual void load(CFRecord& record);
virtual void store(CFRecord& record); virtual void store(CFRecord& record);
......
...@@ -186,7 +186,6 @@ const bool BinReaderProcessor::getNextSubstreamType(unsigned short& type) ...@@ -186,7 +186,6 @@ const bool BinReaderProcessor::getNextSubstreamType(unsigned short& type)
} }
if(rt_BOF != record->getTypeId()) if(rt_BOF != record->getTypeId())
{ {
//throw XLS::RequestedRecordNotFound(rt_BOF, record->getTypeId());
return false; return false;
} }
unsigned short vers; unsigned short vers;
......
...@@ -263,6 +263,7 @@ const bool GlobalsSubstream::loadContent(BinProcessor& proc) ...@@ -263,6 +263,7 @@ const bool GlobalsSubstream::loadContent(BinProcessor& proc)
case rt_UsesELFs: proc.optional<UsesELFs>(); break; case rt_UsesELFs: proc.optional<UsesELFs>(); break;
case rt_RecalcId: proc.optional<RecalcId>(); break; case rt_RecalcId: proc.optional<RecalcId>(); break;
case rt_Font: case rt_Font:
case rt_XFCRC:
{ {
if (proc.mandatory<FORMATTING>()) if (proc.mandatory<FORMATTING>())
{ {
......
...@@ -522,6 +522,8 @@ enum ElementType ...@@ -522,6 +522,8 @@ enum ElementType
typeCFExTemplateParams, typeCFExTemplateParams,
typeCFMStateItem, typeCFMStateItem,
typeCFMultistate, typeCFMultistate,
typeCFDatabar,
typeCFGradient,
typeCFVO, typeCFVO,
typeCondFmtStructure, typeCondFmtStructure,
typeControlInfo, typeControlInfo,
......
...@@ -131,7 +131,31 @@ XlsConverter::XlsConverter(const std::wstring & xls_file, const std::wstring & _ ...@@ -131,7 +131,31 @@ XlsConverter::XlsConverter(const std::wstring & xls_file, const std::wstring & _
try{ try{
XLS::CompoundFile cfile(xls_file, XLS::CompoundFile::cf_ReadMode); XLS::CompoundFile cfile(xls_file, XLS::CompoundFile::cf_ReadMode);
if (cfile.isError())return; if (cfile.isError())
{
//if (0 <= xls_file.rfind(L".xls"))//todooo lower
//{
// unsigned char* fileData = NULL;
// DWORD fileSize = 0;
// if (!NSFile::CFileBinary::ReadAllBytes(xls_file, &fileData, fileSize)) return;
// if (!fileData) return;
// //test/open as list
// std::wstring xls_file_new = _xlsx_path + FILE_SEPARATOR_STR + L"temp.xls";
// if (cfile.Open(xls_file_new, XLS::CompoundFile::cf_WriteMode))
// {
// XLS::CFStreamPtr stream = cfile.createWorkbookStream();
// if (stream)
// stream->write(fileData, fileSize);
// cfile.closeWorkbookStream();
// }
// delete []fileData;
// if (!cfile.Open(xls_file_new, XLS::CompoundFile::cf_ReadMode))
// return;
//}else
return;
}
XLS::CFStreamPtr summary; XLS::CFStreamPtr summary;
XLS::CFStreamPtr doc_summary; XLS::CFStreamPtr doc_summary;
......
...@@ -3169,6 +3169,14 @@ ...@@ -3169,6 +3169,14 @@
RelativePath="..\XlsFormat\Logic\Biff_structures\CFExTemplateParams.h" RelativePath="..\XlsFormat\Logic\Biff_structures\CFExTemplateParams.h"
> >
</File> </File>
<File
RelativePath="..\XlsFormat\Logic\Biff_structures\CFGradient.cpp"
>
</File>
<File
RelativePath="..\XlsFormat\Logic\Biff_structures\CFGradient.h"
>
</File>
<File <File
RelativePath="..\XlsFormat\Logic\Biff_structures\CFMStateItem.cpp" RelativePath="..\XlsFormat\Logic\Biff_structures\CFMStateItem.cpp"
> >
......
...@@ -144,6 +144,11 @@ bool COfficeFileFormatChecker::isXlsFormatFile (POLE::Storage * storage) ...@@ -144,6 +144,11 @@ bool COfficeFileFormatChecker::isXlsFormatFile (POLE::Storage * storage)
if (stream2.read(buffer,10) >0) if (stream2.read(buffer,10) >0)
return true; return true;
POLE::Stream stream3(storage, "WORKBOOK");
if (stream3.read(buffer,10) >0)
return true;
return false; return false;
} }
bool COfficeFileFormatChecker::isPptFormatFile (POLE::Storage * storage) bool COfficeFileFormatChecker::isPptFormatFile (POLE::Storage * storage)
......
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