■ 아래 한글의 테이블을 삽입하는 방법을 보여준다.
▶ 아래 한글 테이블 삽입하기 예제 (VB)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
Dim pRowHeightArray As Variant Dim pColumnWidthArray As Variant pRowHeightArray = Array(1) pColumnWidthArray = Array(30, 50) HWPInsertTable pHwpCtrl, "Table1", pRowHeightArray, pColumnWidthArray HWPSetRowCellValueArray pHwpCtrl, Array("항목", "설명") HWPSetRowCellAlignmentArray pHwpCtrl, Array("center", "center") HWPAppendTableRowWithCellValue pHwpCtrl, "Table1", Array("개발 도구", "Visual Studio 2013") HWPSetRowCellAlignmentArray pHwpCtrl, Array("left", "left") HWPAppendTableRowWithCellValue pHwpCtrl, "Table1", Array("데이터베이스", "MS SQL Server") HWPSetRowCellAlignmentArray pHwpCtrl, Array("left", "left") HWPAppendTableRowWithCellValue pHwpCtrl, "Table1", Array("3자 컴포넌트", "DevExpress, TeeChart") HWPSetRowCellAlignmentArray pHwpCtrl, Array("left", "left") HWPAppendTableRowWithCellValue pHwpCtrl, "Table1", Array("개발 언어", "C#.NET") HWPSetRowCellAlignmentArray pHwpCtrl, Array("left", "left") HWPMoveLast pHwpCtrl ' "아래 한글 문서 마지막 위치로 이동하기" 참조 |
▶ 아래 한글 테이블 삽입하기 (VB)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
'-------------------------------------------------- ' 아래 한글 테이블 삽입하기 '-------------------------------------------------- ' pHwpCtrl : HwpCtrl OCX ' strTableID : 테이블 ID ' pRowHeightArray : 행 높이 배열 (인덱스는 0부터 시작) ' pColumnWidthArray : 컬럼 너비 배열 (인덱스는 0부터 시작) '-------------------------------------------------- Private Sub HWPInsertTable(pHwpCtrl As HwpCtrl, strTableID As String, pRowHeightArray As Variant, pColumnWidthArray As Variant) Dim pHwpAction As HwpAction Dim pHwpParameterSet As HwpParameterSet Dim pHwpParameterArray As HwpParameterArray Dim I As Integer Dim nRowHeightArrayCount As Integer Dim nColumnWidthArrayCount As Integer nRowHeightArrayCount = UBound(pRowHeightArray) + 1 nColumnWidthArrayCount = UBound(pColumnWidthArray) + 1 Set pHwpAction = pHwpCtrl.CreateAction("TableCreate") Set pHwpParameterSet = pHwpAction.CreateSet() pHwpParameterSet.SetItem "Rows", nRowHeightArrayCount pHwpParameterSet.SetItem "Cols", nColumnWidthArrayCount pHwpParameterSet.SetItem "WidthType", 2 pHwpParameterSet.SetItem "HeightType", 1 pHwpParameterSet.CreateItemSet "TableProperties", "Table" Set pHwpParameterArray = pHwpParameterSet.CreateItemArray("RowHeight", nRowHeightArrayCount) For I = 0 To nRowHeightArrayCount - 1 pHwpParameterArray.SetItem I, HWPGetUnit(CDbl(pRowHeightArray(I))) ' "아래 한글 단위 구하기" 참조 Next Set pHwpParameterArray = pHwpParameterSet.CreateItemArray("ColWidth", nColumnWidthArrayCount) For I = 0 To nColumnWidthArrayCount - 1 pHwpParameterArray.SetItem I, HWPGetUnit(CDbl(pColumnWidthArray(I))) ' "아래 한글 단위 구하기" 참조 Next pHwpAction.Execute pHwpParameterSet pHwpCtrl.SetCurFieldName strTableID, 1, 0, 0 Set pHwpParameterArray = Nothing Set pHwpParameterSet = Nothing Set pHwpAction = Nothing End Sub '-------------------------------------------------- ' 아래 한글 테이블 행 추가하기 '-------------------------------------------------- ' pHwpCtrl : HwpCtrl OCX ' pRowCellValueArray : 행 셀 값 배열 (인덱스는 0부터 시작) '-------------------------------------------------- Public Function HWPSetRowCellValueArray(pHwpCtrl As HwpCtrl, pRowCellValueArray As Variant) If pHwpCtrl.ParentCtrl.ctrlid = "tbl" Then Dim pHwpAction As HwpAction Dim pHwpParameterSet As HwpParameterSet Dim nRowValueArrayCount As Integer Dim I As Integer Set pHwpAction = pHwpCtrl.CreateAction("InsertText") Set pHwpParameterSet = pHwpAction.CreateSet() nRowValueArrayCount = UBound(pRowCellValueArray) + 1 For I = 0 To nRowValueArrayCount - 1 pHwpParameterSet.SetItem "Text", CStr(pRowCellValueArray(I)) pHwpAction.Execute pHwpParameterSet pHwpCtrl.Run "TableRightCell" Next HWPSetRowCellValueArray = True Set pHwpParameterSet = Nothing Set pHwpAction = Nothing Else HWPSetRowCellValueArray = False End If End Function '-------------------------------------------------- ' 아래 한글 셀 값을 갖는 테이블 행 추가하기 '-------------------------------------------------- ' pHwpCtrl : HwpCtrl OCX ' strTableID : 테이블 ID ' pRowCellValueArray : 행 셀 값 배열 (인덱스는 0부터 시작) '-------------------------------------------------- Public Sub HWPAppendTableRowWithCellValue(pHwpCtrl As HwpCtrl, strTableID As String, pRowCellValueArray As Variant) HWPAppendTableRow pHwpCtrl, strTableID ' "아래 한글 테이블 행 추가하기" 참조 HWPSetRowCellValueArray pHwpCtrl, pRowCellValueArray End Sub '-------------------------------------------------- ' 아래 한글 행 셀 정렬 배열 설정하기 '-------------------------------------------------- ' pHwpCtrl : HwpCtrl OCX ' pRowCellAlignmentArray : 행 셀 정렬 배열 (인덱스는 0부터 시작) '-------------------------------------------------- Public Sub HWPSetRowCellAlignmentArray(pHwpCtrl As HwpCtrl, pRowCellAlignmentArray As Variant) Dim nRowCellAlignmentArrayCount As Integer Dim strAlignment As String nRowCellAlignmentArrayCount = UBound(pRowCellAlignmentArray) + 1 pHwpCtrl.Run "TableColBegin" For I = 0 To nRowCellAlignmentArrayCount - 1 strAlignment = CStr(pRowCellAlignmentArray(I)) If strAlignment = "left" Then pHwpCtrl.Run "ParagraphShapeAlignLeft" ElseIf strAlignment = "center" Then pHwpCtrl.Run "ParagraphShapeAlignCenter" Else pHwpCtrl.Run "ParagraphShapeAlignRight" End If If I < nRowCellAlignmentArrayCount - 1 Then pHwpCtrl.Run "TableRightCell" End If Next I pHwpCtrl.Run "TableColBegin" End Sub |