The key to the conversion is to figure out the structure of the cellset and organize a graph to clearly display the structure and meaning of the object in the cellset.
In this caseCodeIt is easy to understand.
Public datatable todatatable (cellset CS)
{
Datatable dt = new datatable ();
DT. tablename = "resulttable ";
Datacolumn Dc = new datacolumn ();
Datarow DR = NULL;
// The first column: it must be a dimension description (row header)
DT. Columns. Add (New datacolumn ("Description "));
// Generate a data column object
String name;
Foreach (position P in CS. Axes [0]. positions)
{
Dc = new datacolumn ();
Name = "";
Foreach (member m in P. Members)
{
Name = Name + M. Caption + "";
}
DC. columnname = Name;
DT. Columns. Add (DC );
}
// Add row data
Int Pos = 0;
Foreach (position py in CS. Axes [1]. positions)
{
Dr = DT. newrow ();
// Dimension description column data (row header)
Name = "";
Foreach (member m in Py. Members)
{
Name = Name + M. Caption + "\ r \ n ";
}
Dr [0] = Name;
// Data column
For (INT x = 1; x <= cs. Axes [0]. Positions. Count; X ++)
{
Dr [x] = cs [POS ++]. formattedvalue;
}
DT. Rows. Add (DR );
}
Return DT;
}
Update
The enumeration of cellset is very strange. If it is an enumeration in the [] mode, it is a horizontal enumeration. If it is a foreach enumeration, It is a vertical enumeration.