본문 바로가기
UiPath

[UiPath] Lookup Data Table 과제

by 린앤율맘 2023. 9. 27.

차량구매현황 파일에서 빈칸으로 남아 있는 등록일자(Reg_date)에 정보를 입력하여 파일을 업데이트하려고 합니다. 제공한 판매실적 파일을 이용하여 파일을 업데이트하세요. 개발에 들어가기 전에 제공해 드린 차량구매현황파일과 판매실적파일을 프로젝트 내에 저장하세요.

 

개발가이드

 

1. 두 파일을 읽어 데이터테이블을 만드세요. 데이터테이블을 읽을 때 ‘Get Workbook Sheet’ 액티

    비티를 사용하세요.

2. 판매실적 파일에서 참조할 수 있는 컬럼은 CellPhone입니다. CellPhone 참조하여 Reg_Date

   등록일자를 입력하세요. 만약 CellPhone 컬럼에 해당 핸드폰번호가 없으면 빈칸으로 남겨두세요.

3. 프로젝트 폴더 내에 ‘Data’폴더를 만들고 ‘Result.xlsx’ 이름으로 저장하세요.

 

[Tip]

 

Excel Application Scope + Write Range 이용시, 휴대폰 번호 출력시 0이 없어짐

Write Range Workbook 이용 시, 휴대폰 번호 출력시 0 없어지는 이슈 해소 가능

 

[Tip]

년 yyyy

월 MM

일 dd

시간 hh

분 mm

초 ss

 

[Tip]

Generic Value를 Datetime으로 변환Datetime.Parse(yourvariable)

 

 

 

1. 두 엑셀 파일을 읽어 데이터 테이블 생성 

    데이터 테이블을 담을 변수 생성 

   

    Excel Application Scope + Get Workbook Sheet + Read Range (변수 dtGuest)

    Excel Application Scope + Get Workbook Sheet + Read Range (변수 dtSales)

 

2. For Each Row in Datatable을 지속시키기 위한 idx 변수 생성 

    Assign

    idx(int 변수) = 0(초기값)

 

3. For Each Row in Datatable 내에서 dtGuest 시트내에 Reg_date 없는 지를 판단 후 없는 경우 Lookup을 통해 dtSales 내에 있는 Reg_date를 불러오도록

    Datatable: dtGuest

 

    Body

 

    If

    Condition: CurrentRow.Item("Reg_date").ToString.Equals("")

                      "Reg_date"행이 비어있을 경우 

    Then

    Lookup Data Table

       

         Input > DataTable       dtSales

                     Lookupvalue  currentRow.Item("CellPhone").ToString

 

        Lookup Column > Column Name     "CellPhone"

        Output > CellValue     Result 

                                           (Reg_date를 담을 변수)

                    > RowIndex    RowIndex 

                                            (int변수)

         Target Column >  Column Name     "Reg_date"

  

 Assign 

   Currentrow.item("Reg_date") = Result

 

Else

 

Assign 

idx  = idx +1

 

 

4. 결과 데이터를 엑셀에 저장 

Write Range  - 속성 값에서 Add Headers 체크 

"Result.xlsx"

"Sheet1"

dtGuest

 

5. 프로젝트 내 Data 폴더 생성 후 엑셀 파일 저장 

 

  해당 폴더 경로가 있는 지 확인 

  Path Exist

  Path Type : Folder

  Path: "C:\Users\yeji.kwon\Documents\UiPath\0925과제\Data\"  (경로 설명 및 폴더명)

 

  If

  Condition: blFolderExsits (bl변수)

  

  Then

  Delete Folder

  Folder Name: "C:\Users\yeji.kwon\Documents\UiPath\0925과제\Data\"  

 

 

  Create Folder 

  Folder Namg: "C:\Users\yeji.kwon\Documents\UiPath\0925과제\Data\"

 

 

  Else

  Create Folder: "C:\Users\yeji.kwon\Documents\UiPath\0925과제\Data\"

 

 

 

 

[참고]

convertDate = Datetime.Parse(addReg_date)

row("Reg_date") = convertData.ToString("yyyy-MM-dd")

                               년, 월, 일 순서로 String화 해줘라