Commit e12281c6 authored by ElenaSubbotina's avatar ElenaSubbotina Committed by Alexander Trofimov

XlsFormat - улучшение работы со стилями

parent bb85d380
...@@ -39,18 +39,16 @@ const CellRef Blank::getLocation() const ...@@ -39,18 +39,16 @@ const CellRef Blank::getLocation() const
int Blank::serialize(std::wostream & stream) int Blank::serialize(std::wostream & stream)
{ {
CP_XML_WRITER(stream) int row = cell.rw;
{ int st = (int)cell.ixfe - global_info_->cellStyleXfs_count;
int row = cell.rw;
if (cell.ixfe > global_info_->cellStyleXfs_count)
std::wstring ref = cell.getLocation().toString();// getColRowRef(i, row); {
CP_XML_NODE(L"c") CP_XML_WRITER(stream)
{ {
CP_XML_ATTR(L"r", ref); CP_XML_NODE(L"c")
int st = (int)cell.ixfe - global_info_->cellStyleXfs_count;
if (cell.ixfe > global_info_->cellStyleXfs_count)
{ {
CP_XML_ATTR(L"r", cell.getLocation().toString());
CP_XML_ATTR(L"s", cell.ixfe - global_info_->cellStyleXfs_count); CP_XML_ATTR(L"s", cell.ixfe - global_info_->cellStyleXfs_count);
} }
} }
......
...@@ -53,6 +53,7 @@ void Row::writeFields(CFRecord& record) ...@@ -53,6 +53,7 @@ void Row::writeFields(CFRecord& record)
void Row::readFields(CFRecord& record) void Row::readFields(CFRecord& record)
{ {
global_info_ = record.getGlobalWorkbookInfo();
record >> rw >> colMic >> colMac >> miyRw; record >> rw >> colMic >> colMac >> miyRw;
record.skipNunBytes(4); // reserved / unused record.skipNunBytes(4); // reserved / unused
...@@ -74,5 +75,57 @@ void Row::readFields(CFRecord& record) ...@@ -74,5 +75,57 @@ void Row::readFields(CFRecord& record)
fPhonetic = GETBIT(flags, 14); fPhonetic = GETBIT(flags, 14);
} }
int Row::serialize(std::wostream &stream)
{
CP_XML_WRITER(stream)
{
CP_XML_NODE(L"row")
{
CP_XML_ATTR(L"r", rw + 1);
bool xf_set = true;
if (fGhostDirty == false) xf_set = false;
if (ixfe_val && xf_set)
{
int xf = ixfe_val > global_info_->cellStyleXfs_count ? ixfe_val - global_info_->cellStyleXfs_count : ixfe_val;
if (xf < global_info_->cellXfs_count)
{
CP_XML_ATTR(L"s", xf);
CP_XML_ATTR(L"customFormat", true);
}
}
if (miyRw > 0/* && std::abs(miyRw/20. - sheet_info.defaultRowHeight) > 0.01*/)
{
CP_XML_ATTR(L"ht", miyRw / 20.);
CP_XML_ATTR(L"customHeight", true);
}
if (iOutLevel > 0)
{
CP_XML_ATTR(L"outlineLevel", iOutLevel);
}
if (fCollapsed)
{
CP_XML_ATTR(L"collapsed", fCollapsed);
}
if (fExAsc)
{
CP_XML_ATTR(L"thickTop", true);
}
if (fExDes)
{
CP_XML_ATTR(L"thickBot", true);
}
if (fDyZero)
{
CP_XML_ATTR(L"hidden", true);
}
}
}
return 0;
}
} // namespace XLS } // namespace XLS
...@@ -20,8 +20,12 @@ public: ...@@ -20,8 +20,12 @@ public:
void writeFields(CFRecord& record); void writeFields(CFRecord& record);
void readFields(CFRecord& record); void readFields(CFRecord& record);
int serialize(std::wostream & stream);
static const ElementType type = typeRow; static const ElementType type = typeRow;
GlobalWorkbookInfoPtr global_info_;
//----------------------------- //-----------------------------
Rw rw; Rw rw;
BackwardOnlyParam<unsigned short> colMic; BackwardOnlyParam<unsigned short> colMic;
......
...@@ -145,17 +145,16 @@ int FillInfo::serialize(std::wostream & stream) ...@@ -145,17 +145,16 @@ int FillInfo::serialize(std::wostream & stream)
bool BorderInfo::operator == (const BorderInfo & rVal) const bool BorderInfo::operator == (const BorderInfo & rVal) const
{ {
const bool res = const bool res =
dgBottom == rVal.dgBottom && ((dgBottom == rVal.dgBottom && icvBottom == rVal.icvBottom) || (dgBottom == 0 && rVal.dgBottom == 0))&&
dgDiag == rVal.dgDiag && ((dgLeft == rVal.dgLeft && icvLeft == rVal.icvLeft) || (dgLeft == 0 && rVal.dgLeft == 0)) &&
dgLeft == rVal.dgLeft && ((dgRight == rVal.dgRight && icvRight == rVal.icvRight) || (dgRight == 0 && rVal.dgRight == 0)) &&
dgRight == rVal.dgRight && ((dgTop == rVal.dgTop && icvTop == rVal.icvTop) || (dgTop == 0 && rVal.dgTop == 0)) &&
dgTop == rVal.dgTop &&
grbitDiag == rVal.grbitDiag && (( dgDiag == rVal.dgDiag &&
icvBottom == rVal.icvBottom && grbitDiag == rVal.grbitDiag && icvDiag == rVal.icvDiag) ||
icvDiag == rVal.icvDiag && (dgDiag == 0 && rVal.dgDiag == 0 && grbitDiag == 0 && rVal.grbitDiag== 0))
icvLeft == rVal.icvLeft &&
icvRight == rVal.icvRight && ;
icvTop == rVal.icvTop;
return res; return res;
} }
...@@ -184,15 +183,15 @@ static std::wstring border_type[]= ...@@ -184,15 +183,15 @@ static std::wstring border_type[]=
void serialize1(std::wostream & _stream, unsigned char type, unsigned color, const std::wstring & name) void serialize1(std::wostream & _stream, unsigned char type, unsigned color, const std::wstring & name)
{ {
if (type < 1 || type > 13) return; if (type < 0 || type > 13) return;
CP_XML_WRITER(_stream) CP_XML_WRITER(_stream)
{ {
CP_XML_NODE(name) CP_XML_NODE(name)
{ {
CP_XML_ATTR(L"style", border_type[type]); if (type > 0) CP_XML_ATTR(L"style", border_type[type]);
if (color > 0) if (color > 0 && type > 0)
{ {
CP_XML_NODE(L"color") CP_XML_NODE(L"color")
{ {
...@@ -204,15 +203,15 @@ void serialize1(std::wostream & _stream, unsigned char type, unsigned color, con ...@@ -204,15 +203,15 @@ void serialize1(std::wostream & _stream, unsigned char type, unsigned color, con
} }
void serialize1(std::wostream & _stream, unsigned char type, FillInfoExt & color, const std::wstring & name) void serialize1(std::wostream & _stream, unsigned char type, FillInfoExt & color, const std::wstring & name)
{ {
if (type < 1 || type > 13) return; if (type < 0 || type > 13) return;
CP_XML_WRITER(_stream) CP_XML_WRITER(_stream)
{ {
CP_XML_NODE(name) CP_XML_NODE(name)
{ {
CP_XML_ATTR(L"style", border_type[type]); if (type > 0) CP_XML_ATTR(L"style", border_type[type]);
if (color.enabled) if (color.enabled && type > 0)
{ {
CP_XML_NODE(L"color") CP_XML_NODE(L"color")
{ {
......
...@@ -70,7 +70,7 @@ struct BorderInfo ...@@ -70,7 +70,7 @@ struct BorderInfo
FillInfoExt topFillInfo_; FillInfoExt topFillInfo_;
FillInfoExt bottomFillInfo_; FillInfoExt bottomFillInfo_;
BorderInfo(){} BorderInfo() : dgLeft(0), dgRight(0), dgTop(0), dgBottom(0), dgDiag(0), grbitDiag(0) {}
BorderInfo( const unsigned char dgLeft_set, const unsigned char dgRight_set, const unsigned char dgTop_set, BorderInfo( const unsigned char dgLeft_set, const unsigned char dgRight_set, const unsigned char dgTop_set,
const unsigned char dgBottom_set, const unsigned char dgDiag_set, const unsigned char grbitDiag_set, const unsigned char dgBottom_set, const unsigned char dgDiag_set, const unsigned char grbitDiag_set,
......
...@@ -42,7 +42,7 @@ public: ...@@ -42,7 +42,7 @@ public:
while(count > 0) while(count > 0)
{ {
Row* row = dynamic_cast<Row*>(elements_.back().get()); Row* row = dynamic_cast<Row*>(elements_.front().get());
if (row) if (row)
{ {
if (row->miyRw > 0 && std::abs(row->miyRw/20. - sheet_info.defaultRowHeight) > 0.001) if (row->miyRw > 0 && std::abs(row->miyRw/20. - sheet_info.defaultRowHeight) > 0.001)
...@@ -50,8 +50,8 @@ public: ...@@ -50,8 +50,8 @@ public:
sheet_info.customRowsHeight.insert(std::pair<int, double>(row->rw, row->miyRw / 20.)); sheet_info.customRowsHeight.insert(std::pair<int, double>(row->rw, row->miyRw / 20.));
} }
} }
m_rows.insert(m_rows.begin(), elements_.back()); m_rows.push_back(elements_.front());
elements_.pop_back(); elements_.pop_front();
count--; count--;
} }
} }
...@@ -59,10 +59,30 @@ public: ...@@ -59,10 +59,30 @@ public:
//------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------
CELL cell(shared_formulas_locations_ref_); CELL cell(shared_formulas_locations_ref_);
int count_cells = proc.repeated(cell, 0, 0); int count_cells = count = proc.repeated(cell, 0, 0);
while(count > 0)
count = proc.repeated<DBCell>(0, 0); // OpenOffice Calc stored files workaround (DBCell must be present at least once according to [MS-XLS]) {
CELL * cell = dynamic_cast<CELL *>(elements_.front().get());
if (cell)
{
std::map<int, std::list<BaseObjectPtr>>::iterator it = m_cells.find(cell->RowNumber);
if (it == m_cells.end())
{
std::list<BaseObjectPtr> c;
c.push_back(elements_.front());
m_cells.insert(std::pair<int, std::list<BaseObjectPtr>>(cell->RowNumber, c));
}
else
{
it->second.push_back(elements_.front());
}
}
elements_.pop_front();
count--;
}
count = proc.repeated<DBCell>(0, 0);
// OpenOffice Calc stored files workaround (DBCell must be present at least once according to [MS-XLS])
while(count > 0) while(count > 0)
{ {
m_DBCells.insert(m_DBCells.begin(), elements_.back()); m_DBCells.insert(m_DBCells.begin(), elements_.back());
...@@ -71,12 +91,15 @@ public: ...@@ -71,12 +91,15 @@ public:
} }
if (count_cells > 0 || count_row > 0) return true; if (count_cells > 0 || count_row > 0) return true;
else return false; else return false;
}; }
int serialize(std::wostream & stream); int serialize(std::wostream & stream);
static const ElementType type = typeCELL_GROUP; static const ElementType type = typeCELL_GROUP;
std::list<BaseObjectPtr> m_rows; //---------------------------------------------------------------------------
std::list<BaseObjectPtr> m_DBCells; std::map<int, std::list<BaseObjectPtr>> m_cells;
std::list<BaseObjectPtr> m_rows;
std::list<BaseObjectPtr> m_DBCells;
private: private:
std::vector<CellRangeRef>& shared_formulas_locations_ref_; std::vector<CellRangeRef>& shared_formulas_locations_ref_;
...@@ -125,154 +148,45 @@ int CELL_GROUP::serialize(std::wostream & stream) ...@@ -125,154 +148,45 @@ int CELL_GROUP::serialize(std::wostream & stream)
XLS::GlobalWorkbookInfo::_sheet_size_info & sheet_info = global_info_->current_sheet >=0 ? XLS::GlobalWorkbookInfo::_sheet_size_info & sheet_info = global_info_->current_sheet >=0 ?
global_info_->sheet_size_info[global_info_->current_sheet - 1] : zero; global_info_->sheet_size_info[global_info_->current_sheet - 1] : zero;
elements_.sort(CompareRowCell);// .. todooo (rownumb, list<cells> - )
CP_XML_WRITER(stream) CP_XML_WRITER(stream)
{ {
std::list<XLS::BaseObjectPtr>::iterator current_cell_start = elements_.begin(); std::list<XLS::BaseObjectPtr>::iterator current_row = m_rows.begin();
std::list<XLS::BaseObjectPtr>::iterator current_row = m_rows.begin();
for (std::map<int, std::list<BaseObjectPtr>>::iterator it_row = m_cells.begin(); it_row != m_cells.end(); it_row++)
int current_row_number = 0;
while(current_row_number == 0)
{ {
CP_XML_NODE(L"row") it_row->second.sort(CompareColumCell);
{
std::list<XLS::BaseObjectPtr>::iterator it_cell = current_cell_start; Row * row = NULL;
while(true) if (current_row != m_rows.end())
{ {
if (it_cell == elements_.end()) row = dynamic_cast<Row *>(current_row->get());
{
current_cell_start = it_cell;
current_row_number = -1;
break;
}
CELL * cell = dynamic_cast<CELL *>(it_cell->get());
if (cell == NULL)
{
it_cell++;
continue;
}
if (current_row_number < 1) //
{
current_row_number = cell->RowNumber + 1; //
bool skip_cells = false;
if (current_row != m_rows.end()) while ((row) && (row->rw < it_row->first))
{ {//skip cells
Row * row = dynamic_cast<Row *>(current_row->get()); row->serialize(stream);
current_row++;
int row_n = row->rw; row = dynamic_cast<Row *>(current_row->get());
if (row->rw + 1 < current_row_number)
{
current_row_number = row->rw + 1;
skip_cells = true;
}
CP_XML_ATTR(L"r", current_row_number);
if (row->rw + 1 == current_row_number)
{
bool xf_set = true;
if (row->fGhostDirty == false) xf_set = false;
if (row->ixfe_val && xf_set)
{
if (row->ixfe_val > global_info_->cellStyleXfs_count)
{
CP_XML_ATTR(L"s", row->ixfe_val - global_info_->cellStyleXfs_count);
}
else
{
CP_XML_ATTR(L"s", row->ixfe_val);
}
CP_XML_ATTR(L"customFormat", true);
}
if (row->miyRw > 0/* && std::abs(row->miyRw/20. - sheet_info.defaultRowHeight) > 0.01*/)
{
CP_XML_ATTR(L"ht", row->miyRw / 20.);
CP_XML_ATTR(L"customHeight", true);
}
if (row->iOutLevel > 0)
{
CP_XML_ATTR(L"outlineLevel", row->iOutLevel);
}
if (row->fCollapsed)
{
CP_XML_ATTR(L"collapsed", row->fCollapsed);
}
if (row->fExAsc)
{
CP_XML_ATTR(L"thickTop", true);
}
if (row->fExDes)
{
CP_XML_ATTR(L"thickBot", true);
}
if (row->fDyZero)
{
CP_XML_ATTR(L"hidden", true);
}
}
if (row->rw + 1 <= current_row_number)
{
current_row++;
}
}
else
{
CP_XML_ATTR(L"r", current_row_number);
}
if (skip_cells)
{
current_row_number = 0;
break;
}
}
if (cell->RowNumber + 1 > current_row_number)
{
current_cell_start = it_cell;
current_row_number = 0;
break;
}
cell->serialize(CP_XML_STREAM());
it_cell++;
} }
} }
} CP_XML_NODE(L"row")
if ( current_row != m_rows.end()) {
{ CP_XML_ATTR(L"r", it_row->first + 1);
for (std::list<XLS::BaseObjectPtr>::iterator it_row = current_row; it_row != m_rows.end(); it_row++) if ((row) && (row->rw == it_row->first))
{ {
Row * row = dynamic_cast<Row *>(it_row->get());
if (row == NULL) continue;
CP_XML_NODE(L"row")
{
current_row_number = row->rw + 1;
CP_XML_ATTR(L"r", current_row_number);
bool xf_set = true; bool xf_set = true;
if (row->fGhostDirty == false) xf_set = false; if (row->fGhostDirty == false) xf_set = false;
if (xf_set) if (row->ixfe_val && xf_set)
{ {
if (row->ixfe_val > global_info_->cellStyleXfs_count) int xf = ixfe_val > global_info_->cellStyleXfs_count ? row->ixfe_val - global_info_->cellStyleXfs_count : row->ixfe_val;
{
CP_XML_ATTR(L"s", row->ixfe_val - global_info_->cellStyleXfs_count); if (xf < global_info_->cellXfs_count)
}
else
{ {
CP_XML_ATTR(L"s", row->ixfe_val); CP_XML_ATTR(L"s", xf);
CP_XML_ATTR(L"customFormat", true);
} }
CP_XML_ATTR(L"customFormat", true);
} }
if (row->miyRw > 0/* && std::abs(row->miyRw/20. - sheet_info.defaultRowHeight) > 0.01*/)
if (row->miyRw > 0 /*&& std::abs(row->miyRw/20. - sheet_info.defaultRowHeight) > 0.01*/)
{ {
CP_XML_ATTR(L"ht", row->miyRw / 20.); CP_XML_ATTR(L"ht", row->miyRw / 20.);
CP_XML_ATTR(L"customHeight", true); CP_XML_ATTR(L"customHeight", true);
...@@ -285,10 +199,39 @@ int CELL_GROUP::serialize(std::wostream & stream) ...@@ -285,10 +199,39 @@ int CELL_GROUP::serialize(std::wostream & stream)
{ {
CP_XML_ATTR(L"collapsed", row->fCollapsed); CP_XML_ATTR(L"collapsed", row->fCollapsed);
} }
if (row->fExAsc)
{
CP_XML_ATTR(L"thickTop", true);
}
if (row->fExDes)
{
CP_XML_ATTR(L"thickBot", true);
}
if (row->fDyZero)
{
CP_XML_ATTR(L"hidden", true);
}
row = NULL;
current_row++;
if (current_row != m_rows.end())
row = dynamic_cast<Row *>(current_row->get());
}
for ( std::list<BaseObjectPtr>::iterator it_cell = it_row->second.begin(); it_cell != it_row->second.end(); it_cell++)
{
(*it_cell)->serialize(CP_XML_STREAM());
} }
} }
} }
while (current_row != m_rows.end())
{//skip cells ... last rows
(*current_row)->serialize(stream);
current_row++;
}
} }
return 0; return 0;
} }
......
...@@ -32,7 +32,8 @@ const bool XFS::loadContent(BinProcessor& proc) ...@@ -32,7 +32,8 @@ const bool XFS::loadContent(BinProcessor& proc)
{ {
GlobalWorkbookInfoPtr global_info = proc.getGlobalWorkbookInfo(); GlobalWorkbookInfoPtr global_info = proc.getGlobalWorkbookInfo();
global_info->cellStyleXfs_count = 0; global_info->cellStyleXfs_count = 0;
global_info->cellXfs_count = 0;
XF xf(cell_xf_current_id, style_xf_current_id); XF xf(cell_xf_current_id, style_xf_current_id);
int count = proc.repeated(xf ,16, 0); int count = proc.repeated(xf ,16, 0);
...@@ -53,6 +54,7 @@ const bool XFS::loadContent(BinProcessor& proc) ...@@ -53,6 +54,7 @@ const bool XFS::loadContent(BinProcessor& proc)
else else
{ {
m_arCellXFs.push_back(elements_.front()); m_arCellXFs.push_back(elements_.front());
global_info->cellXfs_count++;
} }
elements_.pop_front(); elements_.pop_front();
......
...@@ -18,6 +18,10 @@ GlobalWorkbookInfo::GlobalWorkbookInfo(const unsigned short code_page, XlsConver ...@@ -18,6 +18,10 @@ GlobalWorkbookInfo::GlobalWorkbookInfo(const unsigned short code_page, XlsConver
startAddedSharedStrings = 0; startAddedSharedStrings = 0;
current_sheet = 0; current_sheet = 0;
cmt_rules = 0; cmt_rules = 0;
cellXfs_count = 0;
cellStyleXfs_count = 0;
cellStyleDxfs_count = 0;
} }
......
...@@ -85,6 +85,7 @@ public: ...@@ -85,6 +85,7 @@ public:
int Version; int Version;
int cmt_rules; int cmt_rules;
int cellXfs_count;
int cellStyleXfs_count; int cellStyleXfs_count;
int cellStyleDxfs_count; int cellStyleDxfs_count;
......
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