첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
------------------------------------------------------------------------------------------------------------------------------------------------------
728x90
728x170

▶ 아래 한글 테이블 삽입하기 예제

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 ' "아래 한글 문서 마지막 위치로 이동하기" 참조

 

▶ 아래 한글 테이블 삽입하기

'--------------------------------------------------
' 아래 한글 테이블 삽입하기
'--------------------------------------------------
' 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
                    
        
728x90
그리드형(광고전용)
Posted by icodebroker
,