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

■ UltraGrid 클래스 : 엑셀 파일 로드하기

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

using System.IO;

using System.Data;

 

using Infragistics.Documents.Excel;

using Infragistics.Win.UltraWinGrid;

 

private UltraGrid ultraGrid;

 

...

 

string filePath = Application.StartupPath + @"\EMPLOYEE.xls";

 

if(File.Exists(filePath))

{

    Workbook workBook = Workbook.Load(filePath);

 

    Worksheet workSheet = workBook.Worksheets[0];

 

    DataTable employeeTable = new DataTable("Employee");

 

    int rowCount    = 0;

    int columnCount = 0;

 

    foreach(WorksheetRow worksheetRow in workSheet.Rows)

    {                    

        if(rowCount == 0)

        {

            foreach(WorksheetCell worksheetCell in worksheetRow.Cells)

            {

                string cellValue = worksheetCell.Value.ToString().Trim();

 

                if(cellValue != string.Empty)

                {

                    DataColumn dataColumn = employeeTable.Columns.Add();

 

                    dataColumn.ColumnName = cellValue;

 

                    dataColumn.DataType = workSheet.Rows[rowCount + 1].Cells[columnCount].Value.GetType();

                }

                else

                {

                    break;

                }

 

                columnCount++;

            }

        }

        else

        {

            columnCount = 0;

 

            DataRow employeeRow = employeeTable.NewRow();

 

            foreach(WorksheetCell worksheetCell in worksheetRow.Cells)

            {

                object cellValue = workSheet.Rows[rowCount].Cells[columnCount].Value;

 

                if(cellValue != null)

                {

                    employeeRow[columnCount] = cellValue;                                

                }

                else

                {

                    break;

                }

                        

                columnCount++;                        

            }

 

            employeeTable.Rows.Add(employeeRow);

        }

 

        rowCount++;

    }

 

    employeeTable.AcceptChanges();

 

    this.ultraGrid.DataSource = employeeTable;

}

 

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

※ 첨부 엑셀 파일은 실행 프로그램과 동일한 폴더 내에 있다고 가정한다.

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요