이 확장은 VB 클래스 변수 선언에서 VB 생성자, getter/setter, 클래스 속성 목록(출력 형식 유형 및 값 포함) 및 싱글톤 팩토리를 생성합니다. 단일 명령으로 모두 렌더링할 수도 있습니다! :)
조각을 생성할 속성을 선택하고 팔레트 Ctrl/Cmd + Shift + P 명령에서 다음 명령 중 하나를 실행합니다.
$ VB getters and setters
$ VB constructor
$ VB class attribute list
$ VB class attribute list with output format list
$ VB factory from class attributes
$ VB full class
$ VB full class with factory
1. Private Const 속성(결국 Const 키워드와 속성이 필요함):
Private Const p_attr As String = "ATTRIBUTE"2. 셀 형식 지정(VBA에서 Range 개체의 형식 속성 유형으로 NumberFormat 또는 NumberFormatLocal 뿐만 아니라 FORMAT 및 VALUE 키워드가 필요함):
' FORMAT NumberFormat VALUE @
' FORMAT NumberFormat VALUE yyyy-mm-dd
' FORMAT NumberFormat VALUE #####0.#03. 셀 색상 서식 지정( FORMATCOLOR , BGCOLOR 및 FGCOLOR 키워드와 배경색의 숫자 값(0~56) 및 전경색의 VB 상수 색상(vbWhite, vbRed, vbBlack 등) 필요):
' FORMATCOLOR BGCOLOR 1 FGCOLOR vbWhite
' FORMATCOLOR BGCOLOR 56 FGCOLOR vbBlack
' FORMAT NumberFormat VALUE #####0.#0 FORMATCOLOR BGCOLOR 56 FGCOLOR vbBlack4. 셀 형식 지정 케이스를 결합할 수 있습니다(형식 유형 및 색상):
' FORMAT NumberFormat VALUE #####0.#0 FORMATCOLOR BGCOLOR 56 FGCOLOR vbBlack5. 숫자 형식은 Const 속성과 함께 사용할 수도 있습니다.
Private Const p_attr As String = "ATTRIBUTE" ' FORMAT NumberFormat VALUE @
Private Const p_attr As String = "ATTRIBUTE" ' FORMATCOLOR BGCOLOR 56 FGCOLOR vbBlack
Private Const p_attr As String = "ATTRIBUTE" ' FORMAT NumberFormat VALUE @ FORMATCOLOR BGCOLOR 56 FGCOLOR vbBlack6. 속성 유형이 무엇인지 밝히지 않는 경우 확장은 모든 생성기에서 속성이 Variant 유형이라는 것을 이해합니다. 예를 들면 다음과 같습니다.
Private p_attr As
Private p_attr7. 다음과 같은 경우에는 오류가 발생하므로 반드시 피하십시오.
' *** No Public/Private declaration
p_attr As String
' *** No attribution from Const attribute
Private Const p_attr
Private Const p_attr As String = ""
' *** Const attribute with the Const keyword
Private p_attr As String
' *** FORMET instead of FORMAT, TextFormat not acceptable, VALUES instead of VALUE, " usages are not allowed in the format value
Private p_attr As String ' FORMET TextFormat VALUES "@"
' *** FORMETCOLOUR instead of FORMATCOLOR, BG_COLOR instead of BGCOLOR, vbblack instead vbBlack, " usages are not allowed in the BGCOLOR value (needs to be numeric)
Private p_attr As String ' FORMETCOLOUR BG_COLOR "1" FG_COLOR vbblack
' *** BGCOLOR and FGCOLOR without values
Private p_attr As String ' FORMATCOLOR BGCOLOR FGCOLOR
' *** BGCOLOR and FGCOLOR inverted positions, BGCOLOR value out of range (0-56)
Private p_attr As String ' FORMATCOLOR FGCOLOR vbBlack BGCOLOR 578. 팩토리 케이스는 Factory/ 폴더에 파일을 출력합니다(오류가 발생하지 않거나 적어도 하나의 비상수 속성이 있는 경우). 특정 팩토리 파일이 폴더에 이미 있는 경우 재정의를 승인하라는 메시지가 표시될 수 있습니다.
해당 형식 출력이 포함된 속성 목록을 갖는 주요 아이디어는 각 속성 값을 시트 행에 쉽게 출력할 수 있도록 하는 것입니다. 다음 Sub는 목록과 해당 형식을 사용하여 객체를 반복하고 모든 속성 값을 행으로 출력합니다.
'*******************************************
'*** @Sub insertGenericRow *****************
'*******************************************
'*** @Argument {Worksheet} ws **************
'*** @Argument {Variant} classObj **********
'*** @Argument {Integer} myLL **************
'*******************************************
'*** Insert a header/shipment/charge *******
'*** inside a worksheet. *******************
'*******************************************
Sub insertGenericRow(ws As Worksheet, classObj As Variant , ByRef myLL As Integer )
Dim listLen As Integer
Dim i As Integer
i = 1
listLen = UBound(classObj.attributesList)
' Iterate through each ordered property from class and send it to the iterated cell with formats
With ws
For i = 0 To listLen
If Not (isEmpty(classObj.attributesFormatTypesList()(i))) Then
If classObj.attributesFormatTypesList()(i) = "NumberFormat" Then
If Not (isEmpty(classObj.attributesFormatValuesList()(i))) Then
.Cells(myLL, i + 1 ).NumberFormat = classObj.attributesFormatValuesList()(i)
End If
End If
End If
' classObj.attributesList() returns the list, and then classObj.attributesList()(i) access an i-element of the list
.Cells(myLL, i + 1 ).value = CallByName(classObj, classObj.attributesList()(i), VbGet)
' Format cell after inserting into sheet
If Not (isEmpty(classObj.attributesFormatTypesList()(i))) Then
If classObj.attributesFormatTypesList()(i) = "NumberFormat" Then
If Not (isEmpty(classObj.attributesFormatValuesList()(i))) Then
.Cells(myLL, i + 1 ).NumberFormat = classObj.attributesFormatValuesList()(i)
End If
End If
End If
Next
End With
myLL = myLL + 1
End Sub MIT © 다비카와사키
코드 개선을 위한 PR이나 이슈를 보내주세요 :)