밥탄이 기록일지
CheckMate RPA C# DataTable ColumnName 변경 본문
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Text;
public partial class CustomScript
{
public void Execute_Code()
{
//DataTable dt = new DataTable();
// 데이터 테이블 생성
//DataTable dt = new DataTable();
// 데이터 테이블 리셋
DataTable_Test.Reset(); // 리셋
DataTable_Test.AcceptChanges(); // 저장
// 데이터테이블 행 (column) 생성
DataTable_Test.Columns.Add("순번", typeof(string));
DataTable_Test.Columns.Add("이름", typeof(string));
DataTable_Test.Columns.Add("나이", typeof(string));
DataTable_Test.Columns.Add("생년월일", typeof(string));
string[,] arr = new string[,]{ {"1","Kim","20","2003-01-01"},
{"2","Park","30","1993-01-01"},
{"3","Lee","40","1983-01-01"}};
PrintLog("배열 첫번째 : " + arr.GetLength(0).ToString());
PrintLog("배열 두번째 : " + arr.GetLength(1).ToString());
for(int i=0; i < arr.GetLength(0); i++)
{
DataRow row = DataTable_Test.NewRow();
PrintLog("회전 : ");
for (int j = 0; j < arr.GetLength(1); j++)
{
row [j] = arr [i, j].ToString();
PrintLog(arr [i, j].ToString() + " , ");
}
PrintLog("종료");
DataTable_Test.Rows.Add(row);
}
// DataTable ColumnName 변경
DataTable_Test.Columns ["순번"].ColumnName = "번호정렬";
DataTable_Test.Columns [2].ColumnName = "OLD";
}
}
C# DataTable 의 경우 ColumnName을 변경할 수 있는데
두가지 방법이 가능하다.
1. 특정 컬럼명을 지정하여 변경하는 경우
2. 인덱스의 컬럼을 지정하여 변경하는 경우
인덱스의 경우 수집하는 값에 따라 바뀔 가능성이 있어 가공이 필요하다면 특정 컬럼명으로 하는편이 좋다.
예시의 경우 "순번"의 컬럼명을 "번호정렬" 로, 0,1,2,3 컬럼 중 2 의 인덱스를 가진 컬럼의 명을 "OLD" 로 변경
결과보기
더보기

컬럼명 변경 전

컬럼명 변경 후


'CheckMate RPA' 카테고리의 다른 글
CheckMate RPA C# DataTable LinQ 적용하기 (System.Data.DataSetExtensions.dll) (0) | 2023.04.07 |
---|---|
CheckMate RPA C# DataTable RowFilter 적용하기 (0) | 2023.04.07 |
CheckMate RPA C# DataTable 생성하기 (DataTable) (0) | 2023.04.07 |
CheckMate RPA C# PDF to Excel 변환하기 (Spire.pdf) (0) | 2023.02.06 |
CheckMate RPA C# Delay (0) | 2023.02.06 |