Commit a4d7f6aa authored by konovalovsergey's avatar konovalovsergey

open/save xlsx SheetView selection

parent 441499af
......@@ -2453,5 +2453,83 @@ namespace SimpleTypes
SimpleType_Operator_Equal (ST_OleUpdate)
};
enum EActivePane
{
activepaneBottomLeft = 0,
activepaneBottomRight = 1,
activepaneTopLeft = 2,
activepaneTopRight = 3
};
template<EActivePane eDefValue = activepaneTopLeft>
class CActivePane : public CSimpleType<EActivePane, eDefValue>
{
public:
CActivePane() {}
virtual EActivePane FromString(CString &sValue)
{
if ( _T("bottomLeft") == sValue ) this->m_eValue = activepaneBottomLeft;
else if ( _T("bottomRight") == sValue ) this->m_eValue = activepaneBottomRight;
else if ( _T("topLeft") == sValue ) this->m_eValue = activepaneTopLeft;
else if ( _T("topRight") == sValue ) this->m_eValue = activepaneTopRight;
else this->m_eValue = eDefValue;
return this->m_eValue;
}
virtual CString ToString () const
{
switch(this->m_eValue)
{
case activepaneBottomLeft : return _T("bottomLeft");
case activepaneBottomRight : return _T("bottomRight");
case activepaneTopLeft : return _T("topLeft");
case activepaneTopRight : return _T("topRight");
default : return _T("topLeft");
}
}
SimpleType_FromString (EActivePane)
SimpleType_Operator_Equal (CActivePane)
};
enum EPaneState
{
panestateFrozen = 0,
panestateFrozenSplit = 1,
panestateSplit = 2
};
template<EPaneState eDefValue = panestateFrozen>
class СPaneState : public CSimpleType<EPaneState, eDefValue>
{
public:
СPaneState() {}
virtual EPaneState FromString(CString &sValue)
{
if ( _T("frozen") == sValue ) this->m_eValue = panestateFrozen;
else if ( _T("frozenSplit") == sValue ) this->m_eValue = panestateFrozenSplit;
else if ( _T("split") == sValue ) this->m_eValue = panestateSplit;
else this->m_eValue = eDefValue;
return this->m_eValue;
}
virtual CString ToString () const
{
switch(this->m_eValue)
{
case panestateFrozen : return _T("frozen");
case panestateFrozenSplit : return _T("frozenSplit");
case panestateSplit : return _T("split");
default : return _T("frozen");
}
}
SimpleType_FromString (EPaneState)
SimpleType_Operator_Equal (СPaneState)
};
};// Spreadsheet
} // SimpleTypes
......@@ -459,10 +459,17 @@ namespace OOX
virtual void toXML(XmlUtils::CStringWriter& writer) const
{
writer.WriteString(_T("<pane"));
if (m_oActivePane.IsInit())
{
writer.WriteString(L" activePane=\"");
writer.WriteString(m_oActivePane->ToString());
writer.WriteString(L"\"");
}
if (m_oState.IsInit())
{
CString sVal; sVal.Format(_T(" state=\"%ls\""), m_oState.get());
writer.WriteString(sVal);
writer.WriteString(L" state=\"");
writer.WriteString(m_oState->ToString());
writer.WriteString(L"\"");
}
if (m_oTopLeftCell.IsInit())
{
......@@ -510,8 +517,8 @@ namespace OOX
}
public:
nullable<CString> m_oActivePane;
nullable<CString> m_oState; // frozen - закреплены; split - разделены на 2 одинаковые части; frozenSplit - сначала разделены, а потом закреплены (после снятия закрепления, будут снова разделены)
nullable<SimpleTypes::Spreadsheet::CActivePane<>> m_oActivePane;
nullable<SimpleTypes::Spreadsheet::СPaneState<>> m_oState;
nullable<CString> m_oTopLeftCell;
nullable<SimpleTypes::CDouble> m_oXSplit;
nullable<SimpleTypes::CDouble> m_oYSplit;
......@@ -553,8 +560,9 @@ namespace OOX
}
if (m_oPane.IsInit())
{
CString sVal; sVal.Format(_T(" pane=\"%ls\""), m_oPane.get());
writer.WriteString(sVal);
writer.WriteString(L" pane=\"");
writer.WriteString(m_oPane->ToString());
writer.WriteString(L"\"");
}
writer.WriteString(_T("/>"));
}
......@@ -589,13 +597,13 @@ namespace OOX
nullable<CString> m_oActiveCell;
nullable<SimpleTypes::CUnsignedDecimalNumber<>> m_oActiveCellId;
nullable<CString> m_oSqref;
nullable<CString> m_oPane; //bottomLeft, bottomRight, topLeft, topRight
nullable<SimpleTypes::Spreadsheet::CActivePane<>> m_oPane;
};
//необработано:
//<extLst>
//<pivotSelection>
class CSheetView : public WritingElement
class CSheetView : public WritingElementWithChilds<CSelection>
{
public:
WritingElementSpreadsheet_AdditionConstructors(CSheetView)
......@@ -714,8 +722,10 @@ namespace OOX
if (m_oPane.IsInit())
m_oPane->toXML(writer);
if (m_oSelection.IsInit())
m_oSelection->toXML(writer);
for(size_t i = 0 ; i < m_arrItems.size(); ++i)
{
m_arrItems[i]->toXML(writer);
}
writer.WriteString(_T("</sheetView>"));
}
......@@ -734,7 +744,10 @@ namespace OOX
if (_T("pane") == sName)
m_oPane = oReader;
if (_T("selection") == sName)
m_oSelection = oReader; }
{
m_arrItems.push_back(new CSelection(oReader));
}
}
}
virtual EElementType getType () const
......@@ -774,7 +787,6 @@ namespace OOX
public:
nullable<CPane> m_oPane;
nullable<CSelection> m_oSelection;
nullable<SimpleTypes::CUnsignedDecimalNumber<>> m_oColorId;
nullable<SimpleTypes::COnOff<>> m_oDefaultGridColor;
......@@ -937,4 +949,4 @@ namespace OOX
} //Spreadsheet
} // namespace OOX
#endif // OOX_WORKSHEETCHILDSOTHER_FILE_INCLUDE_H_
\ No newline at end of file
#endif // OOX_WORKSHEETCHILDSOTHER_FILE_INCLUDE_H_
......@@ -725,15 +725,24 @@ namespace BinXlsxRW
ZoomScalePageLayoutView = 17,
ZoomScaleSheetLayoutView = 18,
Pane = 19
Pane = 19,
Selection = 20
};}
namespace c_oSer_Pane{enum c_oSer_Pane
{
ActivePane = 0,
State = 1,
// State = 1,
TopLeftCell = 2,
XSplit = 3,
YSplit = 4
YSplit = 4,
State = 5
};}
namespace c_oSer_Selection{enum c_oSer_Selection
{
ActiveCell = 0,
ActiveCellId = 1,
Sqref = 2,
Pane = 3
};}
namespace c_oSer_CellStyle{enum c_oSer_CellStyle
{
......
......@@ -1934,35 +1934,150 @@ namespace BinXlsxRW {
void WriteSheetView(const OOX::Spreadsheet::CSheetView& oSheetView)
{
int nCurPos = 0;
if (oSheetView.m_oColorId.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_SheetView::ColorId);
m_oBcw.m_oStream.WriteLONG(oSheetView.m_oColorId->GetValue());
m_oBcw.WriteItemEnd(nCurPos);
}
if (oSheetView.m_oDefaultGridColor.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_SheetView::DefaultGridColor);
m_oBcw.m_oStream.WriteBOOL(oSheetView.m_oDefaultGridColor->ToBool());
m_oBcw.WriteItemEnd(nCurPos);
}
if (oSheetView.m_oRightToLeft.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_SheetView::RightToLeft);
m_oBcw.m_oStream.WriteBOOL(oSheetView.m_oRightToLeft->ToBool());
m_oBcw.WriteItemEnd(nCurPos);
}
if (oSheetView.m_oShowFormulas.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_SheetView::ShowFormulas);
m_oBcw.m_oStream.WriteBOOL(oSheetView.m_oShowFormulas->ToBool());
m_oBcw.WriteItemEnd(nCurPos);
}
if (oSheetView.m_oShowGridLines.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_SheetView::ShowGridLines);
m_oBcw.m_oStream.WriteBOOL(oSheetView.m_oShowGridLines->ToBool());
m_oBcw.WriteItemEnd(nCurPos);
}
if (oSheetView.m_oShowOutlineSymbols.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_SheetView::ShowOutlineSymbols);
m_oBcw.m_oStream.WriteBOOL(oSheetView.m_oShowOutlineSymbols->ToBool());
m_oBcw.WriteItemEnd(nCurPos);
}
if (oSheetView.m_oShowRowColHeaders.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_SheetView::ShowRowColHeaders);
m_oBcw.m_oStream.WriteBOOL(oSheetView.m_oShowRowColHeaders->ToBool());
m_oBcw.WriteItemEnd(nCurPos);
}
if (oSheetView.m_oShowRuler.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_SheetView::ShowRuler);
m_oBcw.m_oStream.WriteBOOL(oSheetView.m_oShowRuler->ToBool());
m_oBcw.WriteItemEnd(nCurPos);
}
if (oSheetView.m_oShowWhiteSpace.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_SheetView::ShowWhiteSpace);
m_oBcw.m_oStream.WriteBOOL(oSheetView.m_oShowWhiteSpace->ToBool());
m_oBcw.WriteItemEnd(nCurPos);
}
if (oSheetView.m_oShowZeros.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_SheetView::ShowZeros);
m_oBcw.m_oStream.WriteBOOL(oSheetView.m_oShowZeros->ToBool());
m_oBcw.WriteItemEnd(nCurPos);
}
if (oSheetView.m_oTabSelected.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_SheetView::TabSelected);
m_oBcw.m_oStream.WriteBOOL(oSheetView.m_oTabSelected->ToBool());
m_oBcw.WriteItemEnd(nCurPos);
}
if (oSheetView.m_oTopLeftCell.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_SheetView::TopLeftCell);
m_oBcw.m_oStream.WriteStringW3(oSheetView.m_oTopLeftCell.get2());
m_oBcw.WriteItemEnd(nCurPos);
}
if (oSheetView.m_oView.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_SheetView::View);
m_oBcw.m_oStream.WriteBYTE(oSheetView.m_oView->GetValue());
m_oBcw.WriteItemEnd(nCurPos);
}
if (oSheetView.m_oWindowProtection.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_SheetView::WindowProtection);
m_oBcw.m_oStream.WriteBOOL(oSheetView.m_oWindowProtection->ToBool());
m_oBcw.WriteItemEnd(nCurPos);
}
if (oSheetView.m_oWorkbookViewId.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_SheetView::WorkbookViewId);
m_oBcw.m_oStream.WriteLONG(oSheetView.m_oWorkbookViewId->GetValue());
m_oBcw.WriteItemEnd(nCurPos);
}
if (oSheetView.m_oZoomScale.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_SheetView::ZoomScale);
m_oBcw.m_oStream.WriteLONG(oSheetView.m_oZoomScale->GetValue());
m_oBcw.WriteItemEnd(nCurPos);
}
if (oSheetView.m_oZoomScaleNormal.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_SheetView::ZoomScaleNormal);
m_oBcw.m_oStream.WriteLONG(oSheetView.m_oZoomScaleNormal->GetValue());
m_oBcw.WriteItemEnd(nCurPos);
}
if (oSheetView.m_oZoomScalePageLayoutView.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_SheetView::ZoomScalePageLayoutView);
m_oBcw.m_oStream.WriteLONG(oSheetView.m_oZoomScalePageLayoutView->GetValue());
m_oBcw.WriteItemEnd(nCurPos);
}
if (oSheetView.m_oZoomScaleSheetLayoutView.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_SheetView::ZoomScaleSheetLayoutView);
m_oBcw.m_oStream.WriteLONG(oSheetView.m_oZoomScaleSheetLayoutView->GetValue());
m_oBcw.WriteItemEnd(nCurPos);
}
if (oSheetView.m_oPane.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_SheetView::Pane);
WritePane(oSheetView.m_oPane.get());
m_oBcw.WriteItemEnd(nCurPos);
}
for(size_t i = 0; i < oSheetView.m_arrItems.size(); ++i)
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_SheetView::Selection);
WriteSelection(*oSheetView.m_arrItems[i]);
m_oBcw.WriteItemEnd(nCurPos);
}
}
void WritePane(const OOX::Spreadsheet::CPane& oPane)
{
int nCurPos = 0;
if (oPane.m_oActivePane.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_Pane::ActivePane);
m_oBcw.m_oStream.WriteBYTE(oPane.m_oActivePane->GetValue());
m_oBcw.WriteItemEnd(nCurPos);
}
//State
if (oPane.m_oState.IsInit())
{
m_oBcw.m_oStream.WriteBYTE(c_oSer_Pane::State);
m_oBcw.m_oStream.WriteStringW(oPane.m_oState.get2());
nCurPos = m_oBcw.WriteItemStart(c_oSer_Pane::State);
m_oBcw.m_oStream.WriteBYTE(oPane.m_oState->GetValue());
m_oBcw.WriteItemEnd(nCurPos);
}
//TopLeftCell
if (oPane.m_oTopLeftCell.IsInit())
......@@ -1985,6 +2100,34 @@ namespace BinXlsxRW {
m_oBcw.WriteItemEnd(nCurPos);
}
}
void WriteSelection(const OOX::Spreadsheet::CSelection& oSelection)
{
int nCurPos = 0;
if (oSelection.m_oActiveCell.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_Selection::ActiveCell);
m_oBcw.m_oStream.WriteStringW3(oSelection.m_oActiveCell.get());
m_oBcw.WriteItemEnd(nCurPos);
}
if (oSelection.m_oActiveCellId.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_Selection::ActiveCellId);
m_oBcw.m_oStream.WriteLONG(oSelection.m_oActiveCellId->GetValue());
m_oBcw.WriteItemEnd(nCurPos);
}
if (oSelection.m_oPane.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_Selection::Pane);
m_oBcw.m_oStream.WriteBYTE(oSelection.m_oPane->GetValue());
m_oBcw.WriteItemEnd(nCurPos);
}
if (oSelection.m_oSqref.IsInit())
{
nCurPos = m_oBcw.WriteItemStart(c_oSer_Selection::Sqref);
m_oBcw.m_oStream.WriteStringW3(oSelection.m_oSqref.get());
m_oBcw.WriteItemEnd(nCurPos);
}
}
void WriteSheetFormatPr(const OOX::Spreadsheet::CSheetFormatPr& oSheetFormatPr)
{
......
......@@ -2178,21 +2178,112 @@ namespace BinXlsxRW {
{
OOX::Spreadsheet::CSheetView* pSheetView = static_cast<OOX::Spreadsheet::CSheetView*>(poResult);
int res = c_oSerConstants::ReadOk;
if(c_oSer_SheetView::ShowGridLines == type)
if(c_oSer_SheetView::ColorId == type)
{
pSheetView->m_oColorId.Init();
pSheetView->m_oColorId->SetValue(m_oBufferedStream.GetLong());
}
else if(c_oSer_SheetView::DefaultGridColor == type)
{
pSheetView->m_oDefaultGridColor.Init();
pSheetView->m_oDefaultGridColor->FromBool(m_oBufferedStream.GetBool());
}
else if(c_oSer_SheetView::RightToLeft == type)
{
pSheetView->m_oRightToLeft.Init();
pSheetView->m_oRightToLeft->FromBool(m_oBufferedStream.GetBool());
}
else if(c_oSer_SheetView::ShowFormulas == type)
{
pSheetView->m_oShowFormulas.Init();
pSheetView->m_oShowFormulas->FromBool(m_oBufferedStream.GetBool());
}
else if(c_oSer_SheetView::ShowGridLines == type)
{
pSheetView->m_oShowGridLines.Init();
pSheetView->m_oShowGridLines->SetValue(false != m_oBufferedStream.GetBool() ? SimpleTypes::onoffTrue : SimpleTypes::onoffFalse);
pSheetView->m_oShowGridLines->FromBool(m_oBufferedStream.GetBool());
}
else if(c_oSer_SheetView::ShowOutlineSymbols == type)
{
pSheetView->m_oShowOutlineSymbols.Init();
pSheetView->m_oShowOutlineSymbols->FromBool(m_oBufferedStream.GetBool());
}
else if(c_oSer_SheetView::ShowRowColHeaders == type)
{
pSheetView->m_oShowRowColHeaders.Init();
pSheetView->m_oShowRowColHeaders->SetValue(false != m_oBufferedStream.GetBool() ? SimpleTypes::onoffTrue : SimpleTypes::onoffFalse);
pSheetView->m_oShowRowColHeaders->FromBool(m_oBufferedStream.GetBool());
}
else if(c_oSer_SheetView::ShowRuler == type)
{
pSheetView->m_oShowRuler.Init();
pSheetView->m_oShowRuler->FromBool(m_oBufferedStream.GetBool());
}
else if(c_oSer_SheetView::ShowWhiteSpace == type)
{
pSheetView->m_oShowWhiteSpace.Init();
pSheetView->m_oShowWhiteSpace->FromBool(m_oBufferedStream.GetBool());
}
else if(c_oSer_SheetView::ShowZeros == type)
{
pSheetView->m_oShowZeros.Init();
pSheetView->m_oShowZeros->FromBool(m_oBufferedStream.GetBool());
}
else if(c_oSer_SheetView::TabSelected == type)
{
pSheetView->m_oTabSelected.Init();
pSheetView->m_oTabSelected->FromBool(m_oBufferedStream.GetBool());
}
else if(c_oSer_SheetView::TopLeftCell == type)
{
pSheetView->m_oTopLeftCell.Init();
pSheetView->m_oTopLeftCell->Append(m_oBufferedStream.GetString3(length));
}
else if(c_oSer_SheetView::View == type)
{
pSheetView->m_oView.Init();
pSheetView->m_oView->SetValue((SimpleTypes::Spreadsheet::ESheetViewType)m_oBufferedStream.GetUChar());
}
else if(c_oSer_SheetView::WindowProtection == type)
{
pSheetView->m_oWindowProtection.Init();
pSheetView->m_oWindowProtection->FromBool(m_oBufferedStream.GetBool());
}
else if(c_oSer_SheetView::WorkbookViewId == type)
{
pSheetView->m_oWorkbookViewId.Init();
pSheetView->m_oWorkbookViewId->SetValue(m_oBufferedStream.GetLong());
}
else if(c_oSer_SheetView::ZoomScale == type)
{
pSheetView->m_oZoomScale.Init();
pSheetView->m_oZoomScale->SetValue(m_oBufferedStream.GetLong());
}
else if(c_oSer_SheetView::ZoomScaleNormal == type)
{
pSheetView->m_oZoomScaleNormal.Init();
pSheetView->m_oZoomScaleNormal->SetValue(m_oBufferedStream.GetLong());
}
else if(c_oSer_SheetView::ZoomScalePageLayoutView == type)
{
pSheetView->m_oZoomScalePageLayoutView.Init();
pSheetView->m_oZoomScalePageLayoutView->SetValue(m_oBufferedStream.GetLong());
}
else if(c_oSer_SheetView::ZoomScaleSheetLayoutView == type)
{
pSheetView->m_oZoomScaleSheetLayoutView.Init();
pSheetView->m_oZoomScaleSheetLayoutView->SetValue(m_oBufferedStream.GetLong());
}
else if (c_oSer_SheetView::Pane == type)
{
pSheetView->m_oPane.Init();
res = Read1(length, &BinaryWorksheetsTableReader::ReadPane, this, pSheetView->m_oPane.GetPointer());
}
else if (c_oSer_SheetView::Selection == type)
{
OOX::Spreadsheet::CSelection* pSelection = new OOX::Spreadsheet::CSelection();
res = Read1(length, &BinaryWorksheetsTableReader::ReadSelection, this, pSelection);
pSheetView->m_arrItems.push_back(pSelection);
}
else
res = c_oSerConstants::ReadUnknown;
return res;
......@@ -2201,10 +2292,15 @@ namespace BinXlsxRW {
{
OOX::Spreadsheet::CPane* pPane = static_cast<OOX::Spreadsheet::CPane*>(poResult);
int res = c_oSerConstants::ReadOk;
if(c_oSer_Pane::State == type)
if(c_oSer_Pane::ActivePane == type)
{
pPane->m_oActivePane.Init();
pPane->m_oActivePane->SetValue((SimpleTypes::Spreadsheet::EActivePane)m_oBufferedStream.GetUChar());
}
else if(c_oSer_Pane::State == type)
{
pPane->m_oState.Init();
pPane->m_oState->Append(m_oBufferedStream.GetString3(length));
pPane->m_oState->SetValue((SimpleTypes::Spreadsheet::EPaneState)m_oBufferedStream.GetUChar());
}
else if(c_oSer_Pane::TopLeftCell == type)
{
......@@ -2225,6 +2321,34 @@ namespace BinXlsxRW {
res = c_oSerConstants::ReadUnknown;
return res;
}
int ReadSelection(BYTE type, long length, void* poResult)
{
OOX::Spreadsheet::CSelection* pSelection = static_cast<OOX::Spreadsheet::CSelection*>(poResult);
int res = c_oSerConstants::ReadOk;
if(c_oSer_Selection::ActiveCell == type)
{
pSelection->m_oActiveCell.Init();
pSelection->m_oActiveCell->Append(m_oBufferedStream.GetString3(length));
}
else if(c_oSer_Selection::ActiveCellId == type)
{
pSelection->m_oActiveCellId.Init();
pSelection->m_oActiveCellId->SetValue(m_oBufferedStream.GetLong());
}
else if(c_oSer_Selection::Sqref == type)
{
pSelection->m_oSqref.Init();
pSelection->m_oSqref->Append(m_oBufferedStream.GetString3(length));
}
else if(c_oSer_Selection::Pane == type)
{
pSelection->m_oPane.Init();
pSelection->m_oPane->SetValue((SimpleTypes::Spreadsheet::EActivePane)m_oBufferedStream.GetUChar());
}
else
res = c_oSerConstants::ReadUnknown;
return res;
}
int ReadSheetPr(BYTE type, long length, void* poResult)
{
OOX::Spreadsheet::CSheetPr* pSheetPr = static_cast<OOX::Spreadsheet::CSheetPr*>(poResult);
......
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