> In an exam, we make a numbered list style for questions. We make a
> variable (perhaps a macros will be helpful here) that holds the total
> number of items in that list (which equals the number of questions).
> When we update the document, the table is created by reading in that
> variable. The result is a table of two rows, the top one having cells
> with sequential numbers in them (representing the question numbers) and
> the lower one blank to be filled in with the grades.
>
Hello HS,
Here's a macro that does exactly what you asked above. It is *not*
elegant, probably it is not efficient, but I just tried and it works.
All you need to do is to create a style called "NumberedList" and use
it for each question. The macro will count the occurrencies of this
style and create at the end of the document the table you want
(leaving 1.5 cm to the left and to the right).
The module (one main and two functions) is almost entirely ripped from
from the excellent document of Andrew Pitonyak where you will find
many more tips on how to format the table and so on...
Cheers,
Michele
Sub CreateResultsTable
Dim nNumberOfColumns As Integer
Dim oText As Object
Dim oCursor As Object
Dim oResultsTable As Object
Dim oCell As Object
' create the text object which will contain the text of the document
oText = thisComponent.GetText()
' create a cursor and move it to the end of the document (not selecting)
oCursor = oText.CreateTextCursor()
oCursor.gotoEnd( False )
' get the number of columns needed counting the questions
nNumberOfColumns = fnCountNumberedListStyles()
' create the table
oResultTable = fnCreateTable( thisComponent, nNumberOfColumns )
' insert the table
oText.insertTextContent( oCursor, oResultTable, False )
' quick loop to fill the first row with numbers
For i = 0 To nNumberOfColumns - 1
oCell = oResultTable.GetCellByPosition(i, 0)
oCell.String = i+1
Next i
End Sub
Function fnCountNumberedListStyles()
Dim n As Integer
Dim oPara As Object
Dim oEnum As Object
n = 0
oEnum = thisComponent.Text.createEnumeration
Do While oEnum.hasMoreElements()
oPara = oEnum.nextElement()
If oPara.supportsService("com.sun.star.text.Paragraph") Then
If oPara.ParaStyleName = "NumberedList" Then
n = n+1
End If
End If
Loop
fnCountNumberedListStyles = n
End Function
Function fnCreateTable(oDoc As Object, nCols As Integer) As Object
Dim oTextTable As Object
oTextTable = oDoc.createInstance("com.sun.star.text.TextTable")
oTextTable.initialize(2, nCols)
oTextTable.HoriOrient = 0 'com.sun.star.text.HoriOrientation::NONE
oTextTable.LeftMargin = 1500
oTextTable.RightMargin = 1500
fnCreateTable = oTextTable
End Function
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]