Тема: Новые свойства для класс Таблиц Word
В этой теме создан новый класс Таблицы Word с новыми полезными свойствами и функциями.
По мере написания новых свойств буду добавлять их в этой теме.
Вот основные параметры нового класса clsMyTable
Public Table As Table ' Объект Таблица Word
Public LinesTables As Collection ' Коллекция строк таблицы
Public LinesTableInPage As Collection ' Коллекция строк таблицы по страницам
Private Sub Class_Initialize()
Set LinesTables = New Collection
Set LinesTableInPage = New Collection
End Sub
Public Property Get PageStart() As Long ' Номер первой страницы таблицы
PageStart = Me.Table.Range.Characters.First.Information(wdActiveEndAdjustedPageNumber)
End Property
Public Property Get PageEnd() As Long ' Номер последней страницы таблицы
PageEnd = Me.Table.Range.Characters.Last.Information(wdActiveEndAdjustedPageNumber)
End Property
Public Property Get PagesTable() As Collection ' Коллекция всех страниц таблицы
Dim i As Long
Set PagesTable = New Collection
For i = Me.PageStart To Me.PageEnd
PagesTable.Add ActiveWindow.ActivePane.Pages(i), "Page_" & i
Next i
End Property
Public Property Get PageCount() As Long ' Всего страниц занимаемых таблицей
PageCount = Me.PagesTable.Count
End Property
Public Property Get LineStart() As Long ' Номер 1-й строки таблицы
LineStart = Me.Table.Range.Characters.First.Information(wdFirstCharacterLineNumber)
End Property
Public Property Get LineEnd() As Long ' Номер последней строки таблицы
LineEnd = Me.Table.Range.Characters.Last.Information(wdFirstCharacterLineNumber)
End Property
Public Property Get LinesCount() As Long ' Всего строк в таблице
Dim Page As Page, i As Long, j As Long
Dim colLine As Collection
Select Case Me.PageCount
Case 1
Set Page = Me.PagesTable("Page_" & Me.PageStart)
Set colLine = New Collection
For i = Me.LineStart To Me.LineEnd
colLine.Add Page.Rectangles(1).Lines(i)
Next i
Set Me.LinesTables = colLine
LinesTableInPage.Add colLine, "Page_" & Me.PageStart
Case Else
For j = Me.PageStart To Me.PageEnd
Set Page = Me.PagesTable("Page_" & Me.PageStart)
If j = Me.PageStart Then
Set colLine = New Collection
For i = Me.LineStart To Page.Rectangles(1).Lines.Count
colLine.Add Page.Rectangles(1).Lines(i)
Me.LinesTables.Add Page.Rectangles(1).Lines(i)
Next i
ElseIf j = Me.PageEnd Then
Set colLine = New Collection
For i = 1 To Me.LineEnd
colLine.Add Page.Rectangles(1).Lines(i)
Me.LinesTables.Add Page.Rectangles(1).Lines(i)
Next i
Else
Set colLine = New Collection
For i = 1 To Page.Rectangles(1).Lines.Count
colLine.Add Page.Rectangles(1).Lines(i)
Me.LinesTables.Add Page.Rectangles(1).Lines(i)
Next i
End If
Me.LinesTableInPage.Add colLine, "Page_" & j
Next j
End Select
LinesCount = Me.LinesTables.Count
End Property
Public Property Get TableWidth() As Single ' Общая ширина таблицы в пунктах
Dim Wmax As Single, i As Long, Line As Line
Set Line = Me.LinesTables(1)
Wmax = Line.Width
For i = 2 To Me.LinesTables.Count
Set Line = Me.LinesTables(i)
If Line.Width > Wmax Then
Wmax = Line.Width
End If
Next i
TableWidth = Wmax
End Property
Public Property Get TableHeight() As Single ' Общая высота таблицы в пунктах
Dim Hmax As Single, i As Long, Line As Line
Hmax = 0
For i = 1 To Me.LinesTables.Count
Set Line = Me.LinesTables(i)
Hmax = Hmax + Line.Height
Next i
TableHeight = Hmax
End Property