# c# 오토메이션 함수 모음(그동안 코딩하고 있던 내용들 일부)

**URL:** <https://forum.developer.hancom.com/t/c/785>\
**Category:** 한글 오토메이션\
**Created:** [7월 7, 2023, 5:10오전 UTC](https://forum.developer.hancom.com/t/c/785 "2023-07-07T05:10:43Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nuristar](https://avatars.discourse-cdn.com/v4/letter/n/bc79bd/32.png) [@nuristar](https://forum.developer.hancom.com/u/nuristar)\
**Post date:** [7월 7, 2023, 5:10오전 UTC](https://forum.developer.hancom.com/t/c/785/1 "2023-07-07T05:10:43Z")

</div>

c#으로 만든 오토메이션 함수들

```auto
// 바탕쪽 만들기
        private void Make_MasterPage()
        {
            hwp.HAction.GetDefault("MasterPage", hwp.HParameterSet.HMasterPage.HSet);
            hwp.HParameterSet.HMasterPage.Duplicate = 0;
            hwp.HParameterSet.HMasterPage.Front = 0;
            hwp.HParameterSet.HMasterPage.Type = 0;
            hwp.HParameterSet.HMasterPage.HSet.SetItem("ApplyTo", 2);
            hwp.HAction.Execute("MasterPage", hwp.HParameterSet.HMasterPage.HSet);
        }

        // 표 만들기 (줄, 칸, 가로크기, 세로크기)
        private void CreateTable(int row, int column, double width, double height)
        {
            hwp.HAction.GetDefault("TableCreate", hwp.HParameterSet.HTableCreation.HSet);
            hwp.HParameterSet.HTableCreation.Rows = row;
            hwp.HParameterSet.HTableCreation.Cols = column;
            hwp.HParameterSet.HTableCreation.WidthType = 2; ;
            hwp.HParameterSet.HTableCreation.HeightType = 1; ;
            hwp.HParameterSet.HTableCreation.WidthValue = hwp.MiliToHwpUnit(width);
            hwp.HParameterSet.HTableCreation.HeightValue = hwp.MiliToHwpUnit(height);
            hwp.HParameterSet.HTableCreation.CreateItemArray("ColWidth", column); // 칸 수만큼 배열 생성
            for (int i = 0; i < column; i++)
            {
                hwp.HParameterSet.HTableCreation.ColWidth.item[i] = hwp.MiliToHwpUnit((width / column) - 3.6); //칸마다 폭 크기 설정
                // 칸마다 왼쪽 여백 1.8, 오른쪽 여백 1.8을 빼줘야 함
            }
            //hwp.HParameterSet.HTableCreation.ColWidth.item[0] = hwp.MiliToHwpUnit(16.0);
            //hwp.HParameterSet.HTableCreation.ColWidth.item[1] = hwp.MiliToHwpUnit(36.0);
            //hwp.HParameterSet.HTableCreation.ColWidth.item[2] = hwp.MiliToHwpUnit(46.0);
            //hwp.HParameterSet.HTableCreation.ColWidth.item[3] = hwp.MiliToHwpUnit(16.0);
            //hwp.HParameterSet.HTableCreation.ColWidth.item[4] = hwp.MiliToHwpUnit(16.0);;
            hwp.HParameterSet.HTableCreation.CreateItemArray("RowHeight", row); ; // 행 수 만큼 배열 생성
            for (int i = 0; i < row; i++)
            {
                hwp.HParameterSet.HTableCreation.RowHeight.item[i] = hwp.MiliToHwpUnit((height / row) - 1.0); // 행마다 높이 설정
            }
            //hwp.HParameterSet.HTableCreation.RowHeight.item[0] = hwp.MiliToHwpUnit(40.0);
            //hwp.HParameterSet.HTableCreation.RowHeight.item[1] = hwp.MiliToHwpUnit(20.0);
            //hwp.HParameterSet.HTableCreation.RowHeight.item[2] = hwp.MiliToHwpUnit(50.0);
            //hwp.HParameterSet.HTableCreation.RowHeight.item[3] = hwp.MiliToHwpUnit(20.0);
            //hwp.HParameterSet.HTableCreation.RowHeight.item[4] = hwp.MiliToHwpUnit(20.0);

            //hwp.HParameterSet.HTableCreation.TableProperties.HorzOffset = hwp.MiliToHwpUnit(0.0);
            //hwp.HParameterSet.HTableCreation.TableProperties.VertOffset = hwp.MiliToHwpUnit(0.0);
            hwp.HParameterSet.HTableCreation.TableProperties.Width = mm2Hu(width);
            hwp.HParameterSet.HTableCreation.TableProperties.OutsideMarginLeft = hwp.MiliToHwpUnit(0);
            hwp.HParameterSet.HTableCreation.TableProperties.OutsideMarginRight = hwp.MiliToHwpUnit(0);
            hwp.HParameterSet.HTableCreation.TableProperties.OutsideMarginTop = hwp.MiliToHwpUnit(0);
            hwp.HParameterSet.HTableCreation.TableProperties.OutsideMarginBottom = hwp.MiliToHwpUnit(0);
            hwp.HParameterSet.HTableCreation.TableProperties.TreatAsChar = 1; // # ;글자처럼 취급
            hwp.HAction.Execute("TableCreate", hwp.HParameterSet.HTableCreation.HSet);
        }

        // 표의 현재 셀 너비 변경
        private void ChangeCellWidth(double width)
        {
            hwp.HAction.GetDefault("TablePropertyDialog", hwp.HParameterSet.HShapeObject.HSet);
            hwp.HParameterSet.HShapeObject.HorzRelTo = hwp.HorzRel("Para");
            hwp.HParameterSet.HShapeObject.HSet.SetItem("ShapeType", 3);
            hwp.HParameterSet.HShapeObject.HSet.SetItem("ShapeCellSize", 1);
            hwp.HParameterSet.HShapeObject.ShapeTableCell.Width = hwp.MiliToHwpUnit(width);
            hwp.HAction.Execute("TablePropertyDialog", hwp.HParameterSet.HShapeObject.HSet);
        }

        // 선택 셀 글자크기 설정
        private void CellTextPoint(float point_size)
        {
            hwp.HAction.GetDefault("CharShape", hwp.HParameterSet.HCharShape.HSet);
            hwp.HParameterSet.HCharShape.FontTypeUser = hwp.FontType("TTF");
            hwp.HParameterSet.HCharShape.FontTypeSymbol = hwp.FontType("TTF");
            hwp.HParameterSet.HCharShape.FontTypeOther = hwp.FontType("TTF");
            hwp.HParameterSet.HCharShape.FontTypeJapanese = hwp.FontType("TTF");
            hwp.HParameterSet.HCharShape.FontTypeHanja = hwp.FontType("TTF");
            hwp.HParameterSet.HCharShape.FontTypeLatin = hwp.FontType("TTF");
            hwp.HParameterSet.HCharShape.FontTypeHangul = hwp.FontType("TTF");
            hwp.HParameterSet.HCharShape.Height = hwp.PointToHwpUnit(point_size); // 글자크기 1
            hwp.HAction.Execute("CharShape", hwp.HParameterSet.HCharShape.HSet);
        }

        // 표의 셀 배경색 넣기
        private void CellBackColor(byte[] rgb)
        {
            hwp.HAction.GetDefault("CellFill", hwp.HParameterSet.HCellBorderFill.HSet);
            hwp.HParameterSet.HCellBorderFill.FillAttr.Type = hwp.BrushType("NullBrush|WinBrush");
            hwp.HParameterSet.HCellBorderFill.FillAttr.WinBrushFaceColor = hwp.RGBColor(rgb[0], rgb[1], rgb[2]);
            hwp.HParameterSet.HCellBorderFill.FillAttr.WinBrushHatchColor = hwp.RGBColor(rgb[0], rgb[1], rgb[2]);
            hwp.HParameterSet.HCellBorderFill.FillAttr.WinBrushFaceStyle = hwp.HatchStyle("None");
            hwp.HParameterSet.HCellBorderFill.FillAttr.WindowsBrush = 1;
            hwp.HAction.Execute("CellFill", hwp.HParameterSet.HCellBorderFill.HSet);
        }

        // 테두리 선 없애기
        private void None_BoderLine()
        {
            hwp.HAction.GetDefault("CellBorder", hwp.HParameterSet.HCellBorderFill.HSet);
            hwp.HParameterSet.HCellBorderFill.BorderTypeBottom = hwp.HwpLineType("None");
            hwp.HParameterSet.HCellBorderFill.BorderTypeTop = hwp.HwpLineType("None");
            hwp.HParameterSet.HCellBorderFill.BorderTypeRight = hwp.HwpLineType("None");
            hwp.HParameterSet.HCellBorderFill.BorderTypeLeft = hwp.HwpLineType("None");
            hwp.HParameterSet.HCellBorderFill.FillAttr.GradationAlpha = 0;
            hwp.HParameterSet.HCellBorderFill.FillAttr.ImageAlpha = 0;
            hwp.HAction.Execute("CellBorder", hwp.HParameterSet.HCellBorderFill.HSet);
            //hwp.HAction.Run("Cancel"); // 선택 해제
        }

        // 글자 모양 변경(글꼴이름, 크기, 색상RGB)
        private void ChangeTextStyle(string textstyle, float point, byte[] rgb)
        {
            hwp.HAction.GetDefault("CharShape", hwp.HParameterSet.HCharShape.HSet);
            hwp.HParameterSet.HCharShape.FaceNameUser = textstyle;
            hwp.HParameterSet.HCharShape.FontTypeUser = hwp.FontType("TTF");
            hwp.HParameterSet.HCharShape.FaceNameSymbol = textstyle;
            hwp.HParameterSet.HCharShape.FontTypeSymbol = hwp.FontType("TTF");
            hwp.HParameterSet.HCharShape.FaceNameOther = textstyle;
            hwp.HParameterSet.HCharShape.FontTypeOther = hwp.FontType("TTF");
            hwp.HParameterSet.HCharShape.FaceNameJapanese = textstyle;
            hwp.HParameterSet.HCharShape.FontTypeJapanese = hwp.FontType("TTF");
            hwp.HParameterSet.HCharShape.FaceNameHanja = textstyle;
            hwp.HParameterSet.HCharShape.FontTypeHanja = hwp.FontType("TTF");
            hwp.HParameterSet.HCharShape.FaceNameLatin = textstyle;
            hwp.HParameterSet.HCharShape.FontTypeLatin = hwp.FontType("TTF");
            hwp.HParameterSet.HCharShape.FaceNameHangul = textstyle;
            hwp.HParameterSet.HCharShape.FontTypeHangul = hwp.FontType("TTF");
            hwp.HParameterSet.HCharShape.TextColor = hwp.RGBColor(rgb[0], rgb[1], rgb[2]);
            hwp.HParameterSet.HCharShape.Height = hwp.PointToHwpUnit(point);
            hwp.HAction.Execute("CharShape", hwp.HParameterSet.HCharShape.HSet);
        }

        // 글자처럼 취급
        private void ChangeLikeText()
        {
            var act = hwp.CreateAction("TablePropertyDialog");
            var set = hwp.CreateSet("ShapeObject");
            act.GetDefault(set);
            set.SetItem("TreatAsChar", 1);
            set.SetItem("Shapetype", 1);
            act.Execute(set);
        }

        // 고치기 - 위치:종이 (글자처럼 취급x)
        private void None_ChangeLiketext()
        {
            Debug.WriteLine("함수 : None_ChangeLiketext - 시작");

            // 위치 종이
            var act = hwp.CreateAction("TablePropertyDialog");
            var set = act.CreateSet();
            act.GetDefault(set);
            set.SetItem("HorzRelTo", hwp.HorzRel("Paper")); // 가로 위치 : 종이
            set.SetItem("VertRelTo", hwp.HorzRel("Paper")); // 세로 위치 : 종이
            set.SetItem("TreatAsChar", 0); // 글자취급 x
            set.SetItem("ShapeType", 6);
            set.SetItem("OutsideMarginTop", 0); // 바깥여백 : 0
            set.SetItem("OutsideMarginBottom", 0); // 바깥여백 : 0
            set.SetItem("OutsideMarginRight", 0); // 바깥여백 : 0
            set.SetItem("OutsideMarginLeft", 0); // 바깥여백 : 0
            act.Execute(set);
            Debug.WriteLine("함수 : None_ChangeLiketext - 완료");
        }

        // 글자처럼 취급 함수 연결
        private void button8_Click(object sender, EventArgs e)
        {
            Debug.WriteLine("글자처럼 취급");
            ChangeLikeText();
        }

        // 글자처럼 취급 X
        private void button15_Click(object sender, EventArgs e)
        {
            Debug.WriteLine("글자처럼 취급 X");
            hwp.Run("CloseEx"); // 표 빠져나오기

            var code = hwp.FindCtrl(); // 컨트롤(표) 선택
            if (code == "tbl" || code == "사각형")
            {
                None_ChangeLiketext();
                hwp.Run("Cancel"); // 선택된 표 선택 해제                
            }
            else { Debug.WriteLine("표 아님, 코드 : " + code); }
        }

        // 현재 커서 위치 정보 배열로 리턴 ([0]총구역, [1]현재구역, [2]쪽, [3]단, [4]줄, [5]칸, [6]컨트롤 종류)
        private int[] Cursor_Info()
        {
            hwp.KeyIndicator(out int seccnt, out int secno, out int prnpageno, out int colno, out int line, out int pos, out short over, out string ctrlname);
            int[] list = new int[6];
            list[0] = seccnt; // 총 구역
            list[1] = secno; // 구역 번호
            list[2] = prnpageno; // 페이지 번호
            list[3] = colno; // 다단 번호
            list[4] = line; // 줄 번호
            list[5] = pos; // 칸(컬럼) 번호
            //short ins_over = over; // 삽입, 수정
            return list;
        }

        private string get_Ctrl_ID()
        {
            try
            {
                hwp.KeyIndicator(out int seccnt, out int secno, out int prnpageno, out int colno, out int line, out int pos, out short over, out string ctrlname);
                return ctrlname;
            }
            catch
            {
                return null;
            }
        }

        // 표의 현재 커서 셀 위치 값 얻기 (A1 / E3 등등..)
        private string Cell_addr()
        {
            try
            {
                string cell = get_Ctrl_ID();
                cell = cell.Split('(', ')')[1];
                return cell;
            }
            catch { return null; }
        }

        // 글자 입력
        private void button1_Click(object sender, EventArgs e)
        {
            Gethwp();
            Typing(textBox1.Text);
            Cursor_Info();
        }

        // 표 안으로 들어가기
        private void in_table()
        {
            hwp.Run("ShapeObjTableSelCell");
        }

        // 표 그리기
        private void button2_Click(object sender, EventArgs e)
        {
            int row = decimal.ToInt32(numericUpDown1.Value);
            int col = decimal.ToInt32(numericUpDown2.Value);
            double[] pagesize = GetPageSize();
            double width = Hu2mm(pagesize[0] - pagesize[4] - pagesize[5]); // 가로크기 - 좌,우 여백 (hwp unit to mm)
            CreateTable(row, col, width, row * 10);
        }

        // 표 첫 줄 음영 주기
        private void button3_Click(object sender, EventArgs e)
        {
            // 색상 설정 (표 배경색 버튼 색상값)
            byte r = button76.BackColor.R;
            byte g = button76.BackColor.G;
            byte b = button76.BackColor.B;
            byte[] backcolor = { r, g, b };

            hwp.HAction.Run("Cancel"); // 표 셀 블럭 되어 있으면 해제
            hwp.HAction.Run("TableCellBlock");
            hwp.HAction.Run("TableColBegin");
            hwp.HAction.Run("TableCellBlockExtend");
            hwp.HAction.Run("TableColEnd");
            hwp.HAction.GetDefault("CellFill", hwp.HParameterSet.HCellBorderFill.HSet);
            hwp.HParameterSet.HCellBorderFill.FillAttr.Type = hwp.BrushType("NullBrush|WinBrush");
            hwp.HParameterSet.HCellBorderFill.FillAttr.WinBrushFaceColor = hwp.RGBColor(r, g, b);
            hwp.HParameterSet.HCellBorderFill.FillAttr.WinBrushHatchColor = hwp.RGBColor(153, 153, 153);
            hwp.HParameterSet.HCellBorderFill.FillAttr.WinBrushFaceStyle = hwp.HatchStyle("None");
            hwp.HParameterSet.HCellBorderFill.FillAttr.WindowsBrush = 1;
            hwp.HAction.Execute("CellFill", hwp.HParameterSet.HCellBorderFill.HSet);
            hwp.HAction.Run("Cancel");
        }

```

---

<div class="post-metadata">

**Author:** ![nuristar](https://avatars.discourse-cdn.com/v4/letter/n/bc79bd/32.png) [@nuristar](https://forum.developer.hancom.com/u/nuristar)\
**Post date:** [7월 7, 2023, 5:14오전 UTC](https://forum.developer.hancom.com/t/c/785/2 "2023-07-07T05:14:57Z")

</div>

```auto

        // 용지 크기 여백 반환(가로크기, 세로크기, 상.하.좌.우 여백, 머리말, 꼬리말)
        private double[] GetPageSize()
        {
            var act = hwp.CreateAction("PageSetup");
            var set = act.CreateSet();
            act.GetDefault(set);
            double paper_width = set.Item("PageDef").Item("PaperWidth"); // 용지 가로 크기
            double paper_height = set.Item("PageDef").Item("PaperHeight"); // 용지 세로 크기
            byte landscape = set.Item("PageDef").Item("Landscape"); // 용지 방향 (0 : 좁게, 1 : 넓게)
            double top_margin = set.Item("PageDef").Item("TopMargin"); // 위 마진
            double bottom_margin = set.Item("PageDef").Item("BottomMargin"); // 아래 마진
            double left_margin = set.Item("PageDef").Item("LeftMargin"); // 왼쪽 마진
            double right_margin = set.Item("PageDef").Item("RightMargin"); // 오른족 마진
            double header_len = set.Item("PageDef").Item("HeaderLen"); // 머리말 길이
            double footer_len = set.Item("PageDef").Item("FooterLen"); // 꼬리말 길이
            double gutter_len = set.Item("PageDef").Item("GutterLen"); // 제본 여백
            byte gutter_type = set.Item("PageDef").Item("GutterType"); // 편집 방법(0:한쪽 편집, 1: 맞쪽 편집, 2: 위로 넘기기)

            Debug.WriteLine("조판부호 보기 모드 : " + hwp.EditMode);
            Debug.WriteLine("용지 가로 크기 : " + Hu2mm(paper_width).ToString() + " mm");
            Debug.WriteLine("용지 세로 크기 : " + Hu2mm(paper_height).ToString() + " mm");
            if (landscape == 1)
            {
                Debug.WriteLine("용지방향 : 넓게(가로문서");
            }
            else
            {
                Debug.WriteLine("용지방향 : 좁게(세로문서)");
            }
            Debug.WriteLine("윗쪽 여백 : " + Hu2mm(top_margin).ToString() + " mm");
            Debug.WriteLine("아랫쪽 여백 : " + Hu2mm(bottom_margin).ToString() + " mm");
            Debug.WriteLine("왼쪽 여백 : " + Hu2mm(left_margin).ToString() + " mm");
            Debug.WriteLine("오른쪽 여백 : " + Hu2mm(right_margin).ToString() + " mm");
            Debug.WriteLine("머리말 : " + Hu2mm(header_len).ToString() + " mm");
            Debug.WriteLine("꼬리말 : " + Hu2mm(footer_len).ToString() + " mm");
            Debug.WriteLine("제본 여백 : " + Hu2mm(gutter_len).ToString() + " mm");

            if (gutter_type == 0)
            {
                Debug.WriteLine("편집 방법 : " + "한쪽 편집");
            }
            else if (gutter_type == 1)
            {
                Debug.WriteLine("편집 방법 : " + "맞쪽 편집");
            }
            else if (gutter_type == 2)
            {
                Debug.WriteLine("편집 방법 : " + "위로 넘기기");
            }
            double[] arr = new double[] { paper_width, paper_height, top_margin, bottom_margin, left_margin, right_margin, header_len, footer_len };
            // double arr = new Array[] { paper_width, paper_height, top_margin, bottom_margin, left_margin, right_margin };

            // 가져오기
            // double[] arr = new double[] { paper_width, paper_height, top_margin, bottom_margin, left_margin, right_margin, header_len, footer_len };
            // arr = GetPageSize();

            return arr;
        }

        // 바탕쪽 (홀/짝 동일) 가운데 쪽번호 만들기
        private void button24_Click(object sender, EventArgs e)
        {
            double[] pagesize;
            pagesize = GetPageSize();
            // double arr = new Array[] { paper_width, paper_height, top_margin, bottom_margin, left_margin, right_margin };
            double page_width = pagesize[0];
            double page_height = pagesize[1];
            double top_margin = pagesize[2];
            double bottom_margin = pagesize[3]; // / 100; // 나누기 100 해줘야 함.
            double left_margin = pagesize[4];
            double right_margin = pagesize[5];
            double header_len = pagesize[6];
            double footer_len = pagesize[7];

            string left_wing = textBox4.Text;
            string right_wing = textBox5.Text;

            // 양쪽 바탕쪽 만들기
            hwp.HAction.GetDefault("MasterPage", hwp.HParameterSet.HMasterPage.HSet);
            hwp.HParameterSet.HMasterPage.Duplicate = 0;
            hwp.HParameterSet.HMasterPage.Front = 0;
            hwp.HParameterSet.HMasterPage.Type = 0; // 0 : 양쪽, 1: 짝수쪽 2: 홀수쪽
            hwp.HParameterSet.HMasterPage.HSet.SetItem("ApplyTo", 2);
            hwp.HAction.Execute("MasterPage", hwp.HParameterSet.HMasterPage.HSet);
            //hwp.HAction.Run("CloseEx"); // 바탕쪽 나가기

            // 표 만들기
            CreateTable(1, 1, 30, 5); // 표 만들기
            None_ChangeLiketext(); // 글자취급 x
            in_table(); // 표 안으로 들어가기
            Typing(left_wing); // 페이지 번호 옆 날개 글자 입력
            hwp.HAction.Run("InsertCpNo"); // 쪽번호 넣기
            Typing(right_wing); // 페이지 번호 옆 날개 글자 입력
            hwp.HAction.Run("ParagraphShapeAlignCenter"); // 텍스트 가운데 정렬
            None_BoderLine(); // 표 선 없음
            hwp.HAction.Run("CloseEx"); // 표 나가기

            // 표 위치 이동 ( 종이 바깥쪽 가로 20, 세로 15)
            hwp.FindCtrl();
            var act = hwp.CreateAction("TablePropertyDialog");
            var set = act.CreateSet();
            act.GetDefault(set);
            set.SetItem("HorzRelTo", hwp.HorzRel("Paper")); // 가로 위치 : 종이
            set.SetItem("VertRelTo", hwp.HorzRel("Paper")); // 세로 위치 : 종이
            set.SetItem("TreatAsChar", 0); // 글자취급 x
            set.SetItem("ShapeType", 3);
            set.SetItem("OutsideMarginTop", 0); // 바깥여백 : 0
            set.SetItem("OutsideMarginBottom", 0); // 바깥여백 : 0
            set.SetItem("OutsideMarginRight", 0); // 바깥여백 : 0
            set.SetItem("OutsideMarginLeft", 0); // 바깥여백 : 0

            //set.SetItem("TextWrap", hwp.TextWrapType("BehindText"));            
            //set.SetItem("HorzAlign", hwp.HAlign("Center"));

            //set.SetItem("VertOffset", footer_len);
            //set.SetItem("VertAlign", hwp.VAlign("Bottom"));

            set.SetItem("TextWrap", hwp.TextWrapType("BehindText")); // 글 뒤로
            set.SetItem("HorzAlign", hwp.HAlign("Center"));
            set.SetItem("HorzRelTo", hwp.HorzRel("Paper"));
            set.SetItem("VertOffset", hwp.MiliToHwpUnit(footer_len));
            set.SetItem("VertAlign", hwp.VAlign("Bottom"));
            set.SetItem("VertRelTo", hwp.VertRel("Paper"));
            set.SetItem("TreatAsChar", 0);
            set.SetItem("ShapeType", 0);
            // Debug.WriteLine("아래 마진 : " + bottom_margin.ToString());
            act.Execute(set);

            // 표 위치 이동 ( 종이 바깥쪽 가로 20, 세로 15)
            hwp.FindCtrl();
            act = hwp.CreateAction("TablePropertyDialog");
            set = act.CreateSet();
            act.GetDefault(set);
            set.SetItem("HorzRelTo", hwp.HorzRel("Paper")); // 가로 위치 : 종이
            set.SetItem("VertRelTo", hwp.HorzRel("Paper")); // 세로 위치 : 종이
            set.SetItem("TreatAsChar", 0); // 글자취급 x
            set.SetItem("ShapeType", 6);
            set.SetItem("OutsideMarginTop", 0); // 바깥여백 : 0
            set.SetItem("OutsideMarginBottom", 0); // 바깥여백 : 0
            set.SetItem("OutsideMarginRight", 0); // 바깥여백 : 0
            set.SetItem("OutsideMarginLeft", 0); // 바깥여백 : 0
            set.SetItem("TextWrap", hwp.TextWrapType("BehindText"));
            //set.SetItem("HorzOffset", right_margin);
            set.SetItem("HorzAlign", hwp.HAlign("Left")); // <-- 표 종이 가운데 정렬도 Left 로 해야 함.. 
            set.SetItem("VertOffset", footer_len);
            set.SetItem("VertAlign", hwp.VAlign("Bottom"));
            act.Execute(set);
            hwp.HAction.Run("CloseEx"); // 바탕쪽 나가기

            //act = hwp.CreateAction("TablePropertyDialog");
            //set = act.CreateSet();
            //act.GetDefault(set);
            //set.SetItem("TextWrap", hwp.TextWrapType("BehindText"));
            //set.SetItem("HorzAlign", hwp.HAlign("Left"));
            //set.SetItem("HorzRelTo", hwp.HorzRel("Paper"));
            //set.SetItem("VertOffset", hwp.MiliToHwpUnit(footer_len));
            //set.SetItem("VertAlign", hwp.VAlign("Bottom"));
            //set.SetItem("VertRelTo", hwp.VertRel("Paper"));
            //set.SetItem("TreatAsChar", 0);
            //set.SetItem("ShapeType", 0);
            //act.Execute(set);
            ////// 가운데
            //act = hwp.CreateAction("TablePropertyDialog");
            //set = act.CreateSet();
            //act.GetDefault(set);
            //set.SetItem("HorzAlign", "Center");
            //set.SetItem("HorzOffset", 0);
            //set.SetItem("TextWrap", hwp.TextWrapType("BehindText"));
            //act.Execute(set);            
            hwp.HAction.Run("CloseEx"); // 바탕쪽 나가기
        }

```

// 으로 주석 달아놓은건 처음에 코딩했던 내용들인데 생각처럼 잘 안되서 수정한게 마지막의 코드 들입니다. 주석 달아놓은건 지울까 하다가 그래도 이렇게 하면 안되는 코드도 보시면 어떨까 해서… 지우지 않고 그대로 올립니다 ㅎㅎ

아래 내용에서 사용한 GetPageSize() 함수를 위쪽에 추가하였습니다.

---

<div class="post-metadata">

**Author:** ![cwy](https://avatars.discourse-cdn.com/v4/letter/c/a4c791/32.png) [@cwy](https://forum.developer.hancom.com/u/cwy)\
**Post date:** [7월 7, 2023, 5:42오전 UTC](https://forum.developer.hancom.com/t/c/785/3 "2023-07-07T05:42:45Z")

</div>

안녕하세요 한컴디벨로퍼입니다. 🙂  
소중한 자료 공유 감사드립니다~ 더욱 도움이 되어 드리는 한컴디벨로퍼가 되겠습니다.

---

<div class="post-metadata">

**Author:** ![nuristar](https://avatars.discourse-cdn.com/v4/letter/n/bc79bd/32.png) [@nuristar](https://forum.developer.hancom.com/u/nuristar)\
**Post date:** [7월 7, 2023, 7:21오전 UTC](https://forum.developer.hancom.com/t/c/785/4 "2023-07-07T07:21:44Z")

</div>

Visual Studio 2022 사용하고 있습니다.

일단… 먼저 솔루션 탐색기에서

1. 참조- 참조추가 - COM - HwpObject 1.0 Type Library 추가

```auto
.
.
.

using HwpObjectLib;

namespace hwp_edit_v01
{
    public partial class Form1 : Form
    {
        public HwpObject hwp = new HwpObject(); // 전역변수 선언

        public Form1()
        {
            InitializeComponent();
            Init();
        }

        private void Init()
        {
            // lb_ESC.Text = "";

            hwp.XHwpWindows.Item(0).Visible = true; // 화면 보기   
            comboBox1.Items.Add("0.1mm");
            comboBox1.Items.Add("0.12mm");
            comboBox1.Items.Add("0.15mm");
            comboBox1.Items.Add("0.2mm");
            comboBox1.Items.Add("0.25mm");
            comboBox1.Items.Add("0.3mm");
            comboBox1.Items.Add("0.4mm");
            comboBox1.Items.Add("0.5mm");
            comboBox1.Items.Add("0.6mm");
            comboBox1.Items.Add("0.7mm");
            comboBox1.Items.Add("1.0mm");
            comboBox1.Items.Add("1.5mm");
            comboBox1.Items.Add("2.0mm");
            comboBox1.Items.Add("3.0mm");
            comboBox1.Items.Add("4.0mm");
            comboBox1.Items.Add("5.0mm");
            comboBox1.SelectedIndex = 1; // 선두께 0.12 mm

            comboBox2.SelectedIndex = 0; // 실선

            // 시작위치 설정
            string cfgFile = "hwp_edit.cfg"; // config 파일이름
            FileInfo fileinfo = new FileInfo(cfgFile);

            if (fileinfo.Exists) // 환경설정 파일이 존재하면
            {              
                using (BinaryReader rdr = new BinaryReader(System.IO.File.Open(cfgFile, FileMode.Open)))
                {
                    string cfg_type = rdr.ReadString(); // "HWP_Edit_Tool" (cfg 파일 종류)
                    int x = rdr.ReadInt32(); // 마지막 윈도우 창 X 위치
                    int y = rdr.ReadInt32(); // 마지막 윈도우 창 Y 위치

                    this.StartPosition = FormStartPosition.Manual; // 폼에서 StartPosition 을 Manual로 설정해도 됨(폼이나 코드상에서 Manual로 설정해야 위치 이동가능)
                    this.Location = new System.Drawing.Point(x, y); // 창 위치 변경
                }
            }
            else
            {
                // config 파일이 존재하지 않으면 기본 위치값 지정
                this.StartPosition = FormStartPosition.Manual;
                this.Location = new System.Drawing.Point(1477, 50);
            }
        }

        // 한글 단위(hu)를 mm로 변환
        private double Hu2mm(double value) => (Math.Round(value / 283.46));

        // mm를 한글단위(hu)로 변환
        private double mm2Hu(double value) => hwp.MiliToHwpUnit(value);

        // 한글 문서에 문장 입력
        private void Typing(string sss)
        {
            var act = hwp.CreateAction("InsertText");
            var pset = act.CreateSet();
            //hwp.Run("BreakPara"); //문단 나누기(Enter)
            pset.SetItem("Text", sss);
            act.Execute(pset); // Debug.WriteLine(cursorInfo(hwp));
        }

```

글자 입력 함수 실행  
Typing(“글자 입력 테스트 입니다.”);  
hwp.Run(“BreakPara”)

바탕쪽에 표 만들고 쪽번호 넣기

```auto
// 바탕쪽 (홀/짝 동일) 가운데 쪽번호 만들기
        private void button24_Click(object sender, EventArgs e)
        {
            double[] pagesize;
            pagesize = GetPageSize();
            // double arr = new Array[] { paper_width, paper_height, top_margin, bottom_margin, left_margin, right_margin };
            double page_width = pagesize[0];
            double page_height = pagesize[1];
            double top_margin = pagesize[2];
            double bottom_margin = pagesize[3]; // / 100; // 나누기 100 해줘야 함.
            double left_margin = pagesize[4];
            double right_margin = pagesize[5];
            double header_len = pagesize[6];
            double footer_len = pagesize[7];

            string left_wing = textBox4.Text;
            string right_wing = textBox5.Text;

            // 양쪽 바탕쪽 만들기
            hwp.HAction.GetDefault("MasterPage", hwp.HParameterSet.HMasterPage.HSet);
            hwp.HParameterSet.HMasterPage.Duplicate = 0;
            hwp.HParameterSet.HMasterPage.Front = 0;
            hwp.HParameterSet.HMasterPage.Type = 0; // 0 : 양쪽, 1: 짝수쪽 2: 홀수쪽
            hwp.HParameterSet.HMasterPage.HSet.SetItem("ApplyTo", 2);
            hwp.HAction.Execute("MasterPage", hwp.HParameterSet.HMasterPage.HSet);
            //hwp.HAction.Run("CloseEx"); // 바탕쪽 나가기

            // 표 만들기
            CreateTable(1, 1, 30, 5); // 표 만들기
            None_ChangeLiketext(); // 글자취급 x
            in_table(); // 표 안으로 들어가기
            Typing(left_wing); // 페이지 번호 옆 날개 글자 입력
            hwp.HAction.Run("InsertCpNo"); // 쪽번호 넣기
            Typing(right_wing); // 페이지 번호 옆 날개 글자 입력
            hwp.HAction.Run("ParagraphShapeAlignCenter"); // 텍스트 가운데 정렬
            None_BoderLine(); // 표 선 없음
            hwp.HAction.Run("CloseEx"); // 표 나가기

            // 표 위치 이동 ( 종이 바깥쪽 가로 20, 세로 15)
            hwp.FindCtrl();
            var act = hwp.CreateAction("TablePropertyDialog");
            var set = act.CreateSet();
            act.GetDefault(set);
            set.SetItem("HorzRelTo", hwp.HorzRel("Paper")); // 가로 위치 : 종이
            set.SetItem("VertRelTo", hwp.HorzRel("Paper")); // 세로 위치 : 종이
            set.SetItem("TreatAsChar", 0); // 글자취급 x
            set.SetItem("ShapeType", 3);
            set.SetItem("OutsideMarginTop", 0); // 바깥여백 : 0
            set.SetItem("OutsideMarginBottom", 0); // 바깥여백 : 0
            set.SetItem("OutsideMarginRight", 0); // 바깥여백 : 0
            set.SetItem("OutsideMarginLeft", 0); // 바깥여백 : 0

            //set.SetItem("TextWrap", hwp.TextWrapType("BehindText"));            
            //set.SetItem("HorzAlign", hwp.HAlign("Center"));

            //set.SetItem("VertOffset", footer_len);
            //set.SetItem("VertAlign", hwp.VAlign("Bottom"));

            set.SetItem("TextWrap", hwp.TextWrapType("BehindText")); // 글 뒤로
            set.SetItem("HorzAlign", hwp.HAlign("Center"));
            set.SetItem("HorzRelTo", hwp.HorzRel("Paper"));
            set.SetItem("VertOffset", hwp.MiliToHwpUnit(footer_len));
            set.SetItem("VertAlign", hwp.VAlign("Bottom"));
            set.SetItem("VertRelTo", hwp.VertRel("Paper"));
            set.SetItem("TreatAsChar", 0);
            set.SetItem("ShapeType", 0);
            // Debug.WriteLine("아래 마진 : " + bottom_margin.ToString());
            act.Execute(set);

            // 표 위치 이동 ( 종이 바깥쪽 가로 20, 세로 15)
            hwp.FindCtrl();
            act = hwp.CreateAction("TablePropertyDialog");
            set = act.CreateSet();
            act.GetDefault(set);
            set.SetItem("HorzRelTo", hwp.HorzRel("Paper")); // 가로 위치 : 종이
            set.SetItem("VertRelTo", hwp.HorzRel("Paper")); // 세로 위치 : 종이
            set.SetItem("TreatAsChar", 0); // 글자취급 x
            set.SetItem("ShapeType", 6);
            set.SetItem("OutsideMarginTop", 0); // 바깥여백 : 0
            set.SetItem("OutsideMarginBottom", 0); // 바깥여백 : 0
            set.SetItem("OutsideMarginRight", 0); // 바깥여백 : 0
            set.SetItem("OutsideMarginLeft", 0); // 바깥여백 : 0
            set.SetItem("TextWrap", hwp.TextWrapType("BehindText"));
            //set.SetItem("HorzOffset", right_margin);
            set.SetItem("HorzAlign", hwp.HAlign("Left")); // <-- 표 종이 가운데 정렬도 Left 로 해야 함.. 
            set.SetItem("VertOffset", footer_len);
            set.SetItem("VertAlign", hwp.VAlign("Bottom"));
            act.Execute(set);
            hwp.HAction.Run("CloseEx"); // 바탕쪽 나가기

            //act = hwp.CreateAction("TablePropertyDialog");
            //set = act.CreateSet();
            //act.GetDefault(set);
            //set.SetItem("TextWrap", hwp.TextWrapType("BehindText"));
            //set.SetItem("HorzAlign", hwp.HAlign("Left"));
            //set.SetItem("HorzRelTo", hwp.HorzRel("Paper"));
            //set.SetItem("VertOffset", hwp.MiliToHwpUnit(footer_len));
            //set.SetItem("VertAlign", hwp.VAlign("Bottom"));
            //set.SetItem("VertRelTo", hwp.VertRel("Paper"));
            //set.SetItem("TreatAsChar", 0);
            //set.SetItem("ShapeType", 0);
            //act.Execute(set);
            ////// 가운데
            //act = hwp.CreateAction("TablePropertyDialog");
            //set = act.CreateSet();
            //act.GetDefault(set);
            //set.SetItem("HorzAlign", "Center");
            //set.SetItem("HorzOffset", 0);
            //set.SetItem("TextWrap", hwp.TextWrapType("BehindText"));
            //act.Execute(set);            
            hwp.HAction.Run("CloseEx"); // 바탕쪽 나가기
        }

```

---

<div class="post-metadata">

**Author:** ![user63](https://avatars.discourse-cdn.com/v4/letter/u/49beb7/32.png) [@user63](https://forum.developer.hancom.com/u/user63)\
**Post date:** [7월 7, 2023, 7:26오전 UTC](https://forum.developer.hancom.com/t/c/785/5 "2023-07-07T07:26:27Z")

</div>

감사합니다.  
단비 같은 내용이네요.  
저도 부족하지만 작성중인 코드 완료되면 공유하겠습니다.

---

<div class="post-metadata">

**Author:** ![user16](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.developer.hancom.com/user16/32/785_2.png) [@user16](https://forum.developer.hancom.com/u/user16)\
**Post date:** [7월 19, 2023, 2:23오전 UTC](https://forum.developer.hancom.com/t/c/785/6 "2023-07-19T02:23:37Z")

</div>

하트를 하나 밖에 드릴 수 없어 넘 아쉽습니다.  
귀한 내용 공유해 주셔서 깊이 감사드립니다.  
행복한 하루 되세요!^^

---

<div class="post-metadata">

**Author:** ![nuristar](https://avatars.discourse-cdn.com/v4/letter/n/bc79bd/32.png) [@nuristar](https://forum.developer.hancom.com/u/nuristar)\
**Post date:** [8월 3, 2023, 6:51오전 UTC](https://forum.developer.hancom.com/t/c/785/7 "2023-08-03T06:51:15Z")

</div>

엇… 이제보니 일상의 코딩 블로그 운영자님이셨네요…  
여기서 이렇게 뵈니 너무 반갑네요 ㅎㅎ  
저에게 있어서는 파이썬-아래한글 컨트롤의 첫 스승님이십니다 ㅎㅎ  
님께 배운내용으로 c#으로 적용하면서 공부 중 입니다 ^^

---

<div class="post-metadata">

**Author:** ![nuristar](https://avatars.discourse-cdn.com/v4/letter/n/bc79bd/32.png) [@nuristar](https://forum.developer.hancom.com/u/nuristar)\
**Post date:** [8월 3, 2023, 7:02오전 UTC](https://forum.developer.hancom.com/t/c/785/8 "2023-08-03T07:02:06Z")

</div>

내용중에 GetPageSize 함수가 있는데 그건 빼먹어서  
내용 추가하였습니다.  
(내용의 위쪽에 추가하였습니다.)
