# 표안에 셀 값 넣기 오류

**URL:** <https://forum.developer.hancom.com/t/topic/2342>\
**Category:** 한글 오토메이션\
**Created:** [3월 20, 2025, 5:18오전 UTC](https://forum.developer.hancom.com/t/topic/2342 "2025-03-20T05:18:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![user13](https://avatars.discourse-cdn.com/v4/letter/u/a88e57/32.png) [@user13](https://forum.developer.hancom.com/u/user13)\
**Post date:** [3월 20, 2025, 5:18오전 UTC](https://forum.developer.hancom.com/t/topic/2342/1 "2025-03-20T05:18:08Z")

</div>

```auto

def insert_cell(table_index, row, col, value):
    try:
        table_ctrl = Table[table_index]
        hwp.SetPosBySet(table_ctrl.GetAnchorPos(0))
        # hwp.FindCtrl()
        hwp.Run("SelectCtrlReverse") # 표 안에 커서 위치
        hwp.Run("ShapeObjTableSelCell") # 표 안에 커서 위치
        
        # 원하는 셀로 이동
        for _ in range(row):
            hwp.Run("TableLowerCel")
        for _ in range(col):
            hwp.Run("TableRightCell")

        hwp.Run("TableEditCell")

        # InsertText 액션 사용
        action = "InsertText"
        hwp.HAction.GetDefault(action, hwp.HParameterSet.HInsertText.HSet)
        hwp.HParameterSet.HInsertText.Text = str(value) if value is not None else ""
        hwp.HAction.Execute(action, hwp.HParameterSet.HInsertText.HSet)
        print(f"{table_index}번 표 - ({row},{col}): {value}")

    except Exception as e:
        print(f"오류 발생 (표: {table_index}, 셀: {row}, {col}): {e}")

```

표안에 셀값을 넣으려고 하는데, 표 밖에 값이 입력되는데 어떻게 해야 할까요??? ㅜㅜ 한글 2020 버전입니다.

---

<div class="post-metadata">

**Author:** ![ygyoun](https://avatars.discourse-cdn.com/v4/letter/y/b4bc9f/32.png) [@ygyoun](https://forum.developer.hancom.com/u/ygyoun)\
**Post date:** [3월 21, 2025, 7:51오전 UTC](https://forum.developer.hancom.com/t/topic/2342/2 "2025-03-21T07:51:26Z")

</div>

안녕하세요

아래 코드에 우선 오타 있습니다.

```auto
hwp.Run("TableLowerCel")

```

TableLowerCell로 변경했습니다.

Table[table\_index]는 어떻게 구현 하셨나요?  
table\_ctrl = Table[table\_index] 만 아래 코드로 변경해서 테스트 해보니 정상 동작 합니다.

```auto
def insert_cell(table_index, row, col, value):
    try:
        tblCnt = 0
        table_ctrl = hwp.HeadCtrl
        while table_ctrl :
            strId = table_ctrl.CtrlID
            if strId == "tbl" :
                tblCnt+=1
                if tblCnt == table_index :
                    break                
            table_ctrl = table_ctrl.Next

        hwp.SetPosBySet(table_ctrl.GetAnchorPos(0))
        # hwp.FindCtrl()
        hwp.Run("SelectCtrlReverse") # 표 안에 커서 위치
        hwp.Run("ShapeObjTableSelCell") # 표 안에 커서 위치
        
        # 원하는 셀로 이동
        for _ in range(row):
            hwp.Run("TableLowerCell")
        for _ in range(col):
            hwp.Run("TableRightCell")

        hwp.Run("TableEditCell")

        # InsertText 액션 사용
        action = "InsertText"
        hwp.HAction.GetDefault(action, hwp.HParameterSet.HInsertText.HSet)
        hwp.HParameterSet.HInsertText.Text = str(value) if value is not None else ""
        hwp.HAction.Execute(action, hwp.HParameterSet.HInsertText.HSet)
        print(f"{table_index}번 표 - ({row},{col}): {value}")

    except Exception as e:
        print(f"오류 발생 (표: {table_index}, 셀: {row}, {col}): {e}")

```

다시 확인해보시고 추가 문의사항 있으면 다시 말씀부탁드립니다.

참고로 저는 hwp.XHwpWindows.Active\_XHwpWindow.Visible = True 로 하고  
파이썬 코드를 한 줄 씩 디버깅하면서 한글 앱과 비교하면서 문제를 찾았습니다. 😀

감사합니다.

---

<div class="post-metadata">

**Author:** ![user13](https://avatars.discourse-cdn.com/v4/letter/u/a88e57/32.png) [@user13](https://forum.developer.hancom.com/u/user13)\
**Post date:** [3월 31, 2025, 6:19오전 UTC](https://forum.developer.hancom.com/t/topic/2342/3 "2025-03-31T06:19:02Z")

</div>

감사합니다. 많은 도움이 되었습니다. 👍 표 내용 컨트롤 하고 나서 많은 진전이 있었습니다.
