첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 icodebroker@naver.com으로 보내주시면 감사합니다.
블로그 자료는 자유롭게 사용하세요.

■ PivotGridControl 클래스 : 피벗 데이터 구하기

------------------------------------------------------------------------------------------------------------------------

using System.Collections.Generic;

using System.Text;

 

using DevExpress.XtraPivotGrid;

 

#region CSV 데이터 구하기 - GetCSVData(pivotGridControl)

 

/// <summary>

/// CSV 데이터 구하기

/// </summary>

/// <param name="pivotGridControl">피벗 그리드 컨트롤</param>

/// <returns>CSV 데이터</returns>

public string GetCSVData(PivotGridControl pivotGridControl)

{

    StringBuilder stringBuilder = new StringBuilder();

 

    PivotGridCells cells = pivotGridControl.Cells;

 

    List<PivotGridField> columnFieldList = pivotGridControl.GetFieldsByArea(PivotArea.ColumnArea);

    List<PivotGridField> rowFieldList    = pivotGridControl.GetFieldsByArea(PivotArea.RowArea   );

 

    if(cells.RowCount > 0)

    {

        #region 컬럼 필드 값을 출력한다.

 

        for(int y = 0; y < columnFieldList.Count; y++)

        {

            for(int x = 0; x < cells.ColumnCount; x++)

            {

                PivotCellEventArgs e = pivotGridControl.Cells.GetCellInfo(x, 0);

 

                if(x == 0)

                {

                    #region 행 필드 값을 출력한다.

 

                    for(int z = 0; z < rowFieldList.Count; z++)

                    {

                        if(z > 0)

                        {

                            stringBuilder.Append(",");

                        }

                    }

 

                    #endregion

                }

 

                stringBuilder.Append(",");

 

                PivotGridField columnField = columnFieldList[y];

 

                if(columnField == null)

                {

                    continue;

                }

 

                object columnValue = e.GetFieldValue(columnField);

 

                if(columnValue != null)

                {

                    stringBuilder.Append(columnValue);

                }

            }

 

            stringBuilder.AppendLine();

        }

 

        #endregion

    }

 

    for(int y = 0; y < cells.RowCount; y++)

    {

        for(int x = 0; x < cells.ColumnCount; x++)

        {

            #region 셀 값을 출력한다.

 

            PivotCellEventArgs e = pivotGridControl.Cells.GetCellInfo(x, y);

 

            if(x == 0)

            {

                #region 해당 셀의 행 필드 값을 출력한다.

 

                for(int z = 0; z < rowFieldList.Count; z++)

                {

                    if(z > 0)

                    {

                        stringBuilder.Append(",");

                    }

 

                    PivotGridField rowField = rowFieldList[z];

 

                    if(rowField == null)

                    {

                        continue;

                    }

 

                    object rowValue = e.GetFieldValue(rowField, y);

 

                    if(rowValue != null)

                    {

                        stringBuilder.Append(rowValue);

                    }

                }

 

                #endregion

            }

 

            stringBuilder.Append(",");

 

            if(e.Value != null)

            {

                stringBuilder.Append(e.Value.ToString());

            }

 

            #endregion

        }

 

        stringBuilder.AppendLine();

    }

 

    return stringBuilder.ToString();

}

 

#endregion

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요