Reorganize cellset to datatable

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.