여기서는 셀 및 표 수정을 통하여 간단한 문서 제목 서식을 만드는 것을 보이도록 하겠습니다. 앞서 표를 만드는 것을 해보았으니, 표의 속성 등을 수정하는 방법을 간략하게 보이겠습니다.
문서 제목 서식은 각 정부 부처 및 산하기관, 심지어 하위 부서마다 정말 다양합니다. 단순하고 별것 아닌 것 같아도 문서 제목 서식은 가독성 향상, 소속 조직 생산 문서의 일관성 유지 및 이미지를 강화하는 역할을 하기도 합니다.
우선 예제 코드를 보이도록 하겠습니다.
package main
import (
"github.com/b612nightsky/gohwp"
)
func main() {
hwp := gohwp.Initialize()
defer hwp.UnInitialize()
hwp.ShowWindow(true)
hwp.RegisterModule("FilePathCheckDLL", "FilePathCheckerModuleExample")
// 1행 1열 표 만들기
hwp.ActionWithParameters("TableCreate", "Cols", 1, "Rows", 1, "WidthType", 1)
hwp.ActionObject().ActionTable().TableCellBlock() // 셀 블록
hwp.ActionObject().ActionTable().TableCellBorderNo() // 테두리 안보이게 하기
hwp.ActionObject().ActionTable().TableCellBorderTop() // 상단 테두리
hwp.ActionObject().ActionTable().TableCellBorderBottom() // 하단 테두리
hwp.ActionObject().ActionEdit().Cancel() // 취소
// 상단 및 하단 테두리 선 색상 및 두께 조절
act := hwp.HAction()
set := hwp.HParameterSet().HCellBorderFill()
act.GetDefault("CellBorderFill", set.HSet())
set.BorderColorBottom(uint32(hwp.RGBColor(65, 105, 225)))
set.BorderWidthBottom(uint16(hwp.HwpLineWidth("1.0mm")))
set.BorderColorTop(uint32(hwp.RGBColor(65, 105, 225)))
set.BorderWidthTop(uint16(hwp.HwpLineWidth("1.0mm")))
act.Execute("CellBorderFill", set.HSet())
// 표 속성 조절
set2 := hwp.HParameterSet().HShapeObject()
act.GetDefault("TablePropertyDialog", set2.HSet())
set2.TreatAsChar(1) // 글자처럼 취급
set2.CellMarginTop(hwp.MiliToHwpUnit(1.5))
set2.CellMarginBottom(hwp.MiliToHwpUnit(1.5))
set2.OutsideMarginBottom(hwp.MiliToHwpUnit(4.))
act.Execute("TablePropertyDialog", set2.HSet())
// 제목 입력하기
hwp.ActionObject().ActionShape().ParagraphShapeAlignCenter()
hwp.ActionWithParameters("CharShape", "Height", hwp.PointToHwpUnit(20))
hwp.SetFont("HY헤드라인M")
hwp.InsertText("Go언어: gohwp를 이용한 한글 자동화")
// 표 아래로 내려오기
hwp.ActionObject().ActionEdit().MoveDown()
// 우측 정렬 및 부서 & 날짜 입력
hwp.ActionObject().ActionShape().ParagraphShapeAlignRight()
hwp.SetFont("휴먼명조")
hwp.ActionWithParameters("CharShape", "Height", hwp.PointToHwpUnit(12.))
hwp.InsertText("고랭 (2024.05.21)\r\n")
// 좌측 정렬 및 본문 입력
hwp.ActionObject().ActionShape().ParagraphShapeAlignLeft()
hwp.InsertText("\r\n고랭으로 제목 만들기")
}
위의 코드를 실행하면 다음과 같은 한글 화면을 볼 수 있습니다.
정말 단순한 문서 제목과 작성자(날짜), 내용 한 줄이 들어갔습니다.
이제 코드를 간략히 살펴보겠습니다.
// 1행 1열 표 만들기
hwp.ActionWithParameters("TableCreate", "Cols", 1, "Rows", 1, "WidthType", 1)
hwp.ActionObject().ActionTable().TableCellBlock() // 셀 블록
hwp.ActionObject().ActionTable().TableCellBorderNo() // 테두리 안보이게 하기
hwp.ActionObject().ActionTable().TableCellBorderTop() // 상단 테두리
hwp.ActionObject().ActionTable().TableCellBorderBottom() // 하단 테두리
hwp.ActionObject().ActionEdit().Cancel() // 취소
여기서는 주석만 읽어보셔도 될 듯 합니다. 1칸짜리 표를 만들고 테두리 선을 안보이게 했다가 상단 및 하단 테두리 선만 다시 보이게 했습니다. ActionObject에 정의된 액션은 단순하게 테두리 선을 on/off 한다고 생각하시면 됩니다.
// 상단 및 하단 테두리 선 색상 및 두께 조절
act := hwp.HAction()
set := hwp.HParameterSet().HCellBorderFill()
act.GetDefault("CellBorderFill", set.HSet())
set.BorderColorBottom(uint32(hwp.RGBColor(65, 105, 225)))
set.BorderWidthBottom(uint16(hwp.HwpLineWidth("1.0mm")))
set.BorderColorTop(uint32(hwp.RGBColor(65, 105, 225)))
set.BorderWidthTop(uint16(hwp.HwpLineWidth("1.0mm")))
act.Execute("CellBorderFill", set.HSet())
여기서는 좀 더 상세한 수정이 있습니다. CellBorderFill 액션 및 HCellBorderFill 파라미터 세트는 셀의 테두리 및 배경을 조절할 수 있습니다. 앞서 테두리를 안보이게 하거나, 다시 보이게 하는 행위도 여기서 가능하긴 합니다.
1칸짜리 표의 상단 및 하단 테두리 선의 두께를 BorderWidthBottom 등의 메서드로, 색상은 BorderColorBottom 등의 메서드를 이용하여 변경했습니다.
주의하셔야 할 것은 Go언어에서는 강타입의 언어이다보니 타입을 잘 맞춰서 넣어야 합니다. 저와 같이 아마추어라고 부르기도 민망한 코더의 입장으로 메서드마다 int32, uint16, uint32 등등 서로 다른 타입을 사용하는 것이 상당히 불편하게 느껴집니다.
// 표 속성 조절
set2 := hwp.HParameterSet().HShapeObject()
act.GetDefault("TablePropertyDialog", set2.HSet())
set2.TreatAsChar(1) // 글자처럼 취급
set2.CellMarginTop(hwp.MiliToHwpUnit(1.5))
set2.CellMarginBottom(hwp.MiliToHwpUnit(1.5))
set2.OutsideMarginBottom(hwp.MiliToHwpUnit(4.))
act.Execute("TablePropertyDialog", set2.HSet())
앞서 셀의 관점에서 수정이 있었다면 여기서는 표의 관점에서 속성을 수정합니다.
액션은 "TablePropertyDialog"이지만 파라미터 세트는 HShapeObject입니다.
TreatAsChat(1)로 표를 글자처럼 취급합니다.
CellMarginTop 및 CellMarginBottom은 표 내 전체 셀의 내부 여백에 반영이 되는 것으로 제목 글자와 상하단 테두리 선의 간격을 띄우기 위해 집어넣었습니다.
OutsideMarginBottom은 표 밖 하단의 여백으로 제목 바로 아래 문단이 바로 붙어있지 않고 띄우기 위해 넣었습니다.
// 제목 입력하기
hwp.ActionObject().ActionShape().ParagraphShapeAlignCenter()
hwp.ActionWithParameters("CharShape", "Height", hwp.PointToHwpUnit(20))
hwp.SetFont("HY헤드라인M")
hwp.InsertText("Go언어: gohwp를 이용한 한글 자동화")
아직 커서(캐럿)이 표 안에 있는 상태에서 ParagraphShapeAlignCenter() 액션으로 문단 속성을 중앙 정렬로 변경하였습니다. 글씨 크기를 20p, 글꼴을 "HY헤드라인M"으로 설정한 후 제목을 입력합니다.
이 뒤의 코드는 기본적으로 따라올 문자들을 입력한 것인데 굳이 설명하지 않아도 될 것 같아 생략합니다.
제목 위아래로 선이 하나씩 있는 제목 서식이지만, 선 색깔을 소속 조직을 상징하는 색깔로 하는 것 만으로도 소속 기관을 나타내는 효과가 있습니다. 위와 같은 문서 제목 서식의 문서는 내용이 많지 않고 메일로 주고 받는 문서에서 주로 쓰곤 했습니다.