📄 wordreports.bas
字号:
iCount = 1
oTable.AutoFormat Format:=wdTableFormatColorful2, _
ApplyBorders:=True, ApplyFont:=True, ApplyColor:=True
oTable.Columns(1).Width = InchesToPoints(1.5)
oTable.Columns(2).Width = InchesToPoints(1.5)
oTable.Columns(3).Width = InchesToPoints(3)
oTable.Columns(4).Width = InchesToPoints(1.5)
oTable.Columns(5).Width = InchesToPoints(0.5)
oTable.Cell(1, 1).Range.InsertAfter "Name"
oTable.Cell(1, 2).Range.InsertAfter "Type"
oTable.Cell(1, 3).Range.InsertAfter "Description"
oTable.Cell(1, 4).Range.InsertAfter "Precondition"
oTable.Cell(1, 5).Range.InsertAfter "Postcondition"
iCounter = OperationList.Count
OperationList.Restart
iColCount = 2
While (OperationList.IsLast = False)
Set currentOperation = OperationList.GetNext
oTable.Cell(row:=iColCount, Column:=1).Range.InsertAfter currentOperation.Name
oTable.Cell(row:=iColCount, Column:=2).Range.InsertAfter currentOperation.ReturnType
oTable.Cell(row:=iColCount, Column:=3).Range.InsertAfter currentOperation.Comment1
oTable.Cell(row:=iColCount, Column:=4).Range.InsertAfter currentOperation.Precondition
oTable.Cell(row:=iColCount, Column:=5).Range.InsertAfter currentOperation.Postcondition
iColCount = iColCount + 1
Wend
Exit Sub
ErrorHandler:
sMsg = "Error # " & Str(Err.Number) & " was generated by " & Err.Source & Chr(13) & Err.Description
MsgBox sMsg, , "Error", Err.HelpFile, Err.HelpContext
End Sub
Sub WordCreateStateReport()
On Error GoTo ErrorHandler
Dim numStates As Long
Dim oTable As Object
Dim oCell As Object
Dim h As Integer
Dim I As Integer
Dim j As Integer
Dim k As Integer
Dim l As Integer
Dim iFileID As Integer
Dim m As Integer
Dim iParameterCount As Integer
Dim iCounter As Integer
Dim iAttrCounter As Integer
Dim iOperCounter As Integer
Dim iRelCounter As Integer
Dim iIncludeCounter As Integer
Dim currentState As With_Class.State
Dim currentTransition As With_Class.Transition
Dim StateList As With_Class.States
Dim TransitionList As With_Class.Transitions
Dim sFileName As String
Dim sInfile As String
Dim sCellNum As String
Dim iRowCount As Integer
Dim iColCount As Integer
Dim myRange As Object
' ***********Word Variables***************
Dim ThisWord As Word.Application
Dim newDoc As Object
Dim aRange As Word.Range
Dim TitleArray As Variant
Dim DataArray As Variant
' ****************************************
iFileID = FreeFile
iRowCount = 2
sFileName = "c:\report.txt"
Dim iCount As Integer
Set wcDocument = ActiveDocument
TitleArray = Array("Name", "Description", "Activity", "Class", "CompositeState", "ImportFile", "LibraryBaseClass")
Set ThisWord = CreateObject("Word.application")
ThisWord.DefaultSaveFormat = "HTML"
ThisWord.Visible = True
Set newDoc = ThisWord.Documents.Add
With newDoc
.Content.Font.Name = "Arial"
.PageSetup.Orientation = wdOrientLandscape
Set StateList = wcDocument.States
numStates = StateList.Count
.Tables.Add Range:=.Range(Start:=0, End:=0), NumRows:=numStates + 1, NumColumns:=6
Set oTable = .Tables.Item(1)
Set aRange = newDoc.Range(Start:=0, End:=0)
' Set oTable = newDoc.Tables.Add(Range:=aRange, NumRows:=numClasses, NumColumns:=5)
iCount = 1
oTable.AutoFormat Format:=wdTableFormatColorful2, _
ApplyBorders:=True, ApplyFont:=True, ApplyColor:=True
oTable.Columns(1).Width = InchesToPoints(1.5)
oTable.Columns(2).Width = InchesToPoints(3)
oTable.Columns(3).Width = InchesToPoints(1)
oTable.Columns(4).Width = InchesToPoints(1)
oTable.Columns(5).Width = InchesToPoints(1)
oTable.Columns(6).Width = InchesToPoints(1)
oTable.Cell(1, 1).Range.InsertAfter "Name"
oTable.Cell(1, 2).Range.InsertAfter "Description"
oTable.Cell(1, 3).Range.InsertAfter "Activity"
oTable.Cell(1, 4).Range.InsertAfter "Class"
oTable.Cell(1, 5).Range.InsertAfter "Composite State"
iCounter = StateList.Count
StateList.Restart
iColCount = 2
While (StateList.IsLast = False)
Set currentState = StateList.GetNext
oTable.Cell(row:=iColCount, Column:=1).Range.InsertAfter currentState.Name
oTable.Cell(row:=iColCount, Column:=2).Range.InsertAfter currentState.Description
oTable.Cell(row:=iColCount, Column:=3).Range.InsertAfter currentState.Do
oTable.Cell(row:=iColCount, Column:=4).Range.InsertAfter currentState.StateClass
oTable.Cell(row:=iColCount, Column:=5).Range.InsertAfter currentState.CompositeState
iColCount = iColCount + 1
Wend
wcDocument.CopyRegionToClipBoard 0, 0, 500, 500
ThisWord.Selection.Paste
StateList.Restart
While (StateList.IsLast = False)
Set currentState = StateList.GetNext
GenerateTransitionOutPage currentState, newDoc
' GenerateTransitionInPage CurrentState, newDoc
Wend
'.Save
'.Close
End With
MsgBox ("Finished generating table")
' ThisWord.Quit
Exit Sub
ErrorHandler:
sMsg = "Error # " & Str(Err.Number) & " was generated by " & Err.Source & Chr(13) & Err.Description
MsgBox sMsg, , "Error", Err.HelpFile, Err.HelpContext
End Sub
Private Sub GenerateTransitionOutPage(aState As With_Class.State, aDoc As Object)
On Error GoTo ErrorHandler
Dim sMsg As String
Dim TransitionList As With_Class.Transitions
Dim currentTransition As With_Class.Transition
Dim oTable As Object
Dim oCell As Object
Dim sCellNum As String
Dim iRowCount As Integer
Dim iColCount As Integer
Dim myRange As Object
Dim iCount As Integer
Dim iCounter As Integer
Set myRange = aDoc.Sections.Last.Range
myRange.SetRange Start:=myRange.End + 10, End:=myRange.End + 20
myRange.InsertBreak Type:=wdSectionBreakNextPage
myRange.InsertAfter Text:="State Transition out of " + aState.Name
myRange.SetRange Start:=myRange.End + 100, End:=myRange.End + 110
Set TransitionList = aState.TransitionsOut
Set oTable = aDoc.Tables.Add(Range:=myRange, NumRows:=TransitionList.Count + 1, _
NumColumns:=6)
iCount = 1
oTable.AutoFormat Format:=wdTableFormatColorful2, _
ApplyBorders:=True, ApplyFont:=True, ApplyColor:=True
oTable.Columns(1).Width = InchesToPoints(1)
oTable.Columns(2).Width = InchesToPoints(1)
oTable.Columns(3).Width = InchesToPoints(1)
oTable.Columns(4).Width = InchesToPoints(1)
oTable.Columns(5).Width = InchesToPoints(1.5)
oTable.Columns(6).Width = InchesToPoints(1)
oTable.Cell(1, 1).Range.InsertAfter "Current State"
oTable.Cell(1, 2).Range.InsertAfter "Next State"
oTable.Cell(1, 3).Range.InsertAfter "Event"
oTable.Cell(1, 4).Range.InsertAfter "Condition"
oTable.Cell(1, 5).Range.InsertAfter "Action"
oTable.Cell(1, 6).Range.InsertAfter "Send Event"
iCounter = TransitionList.Count
TransitionList.Restart
iColCount = 2
While (TransitionList.IsLast = False)
Set currentTransition = TransitionList.GetNext
oTable.Cell(row:=iColCount, Column:=1).Range.InsertAfter currentTransition.SourceState.Name
oTable.Cell(row:=iColCount, Column:=2).Range.InsertAfter currentTransition.DestState.Name
oTable.Cell(row:=iColCount, Column:=3).Range.InsertAfter currentTransition.Event
oTable.Cell(row:=iColCount, Column:=4).Range.InsertAfter currentTransition.Condition
oTable.Cell(row:=iColCount, Column:=5).Range.InsertAfter currentTransition.Action
oTable.Cell(row:=iColCount, Column:=6).Range.InsertAfter currentTransition.SendEvent
iColCount = iColCount + 1
Wend
Exit Sub
ErrorHandler:
sMsg = "Error # " & Str(Err.Number) & " was generated by " & Err.Source & Chr(13) & Err.Description
MsgBox sMsg, , "Error", Err.HelpFile, Err.HelpContext
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -