Adjust base font size for all formulas of ODT document

From Apache OpenOffice Wiki
Revision as of 09:42, 12 October 2010 by Hdu (Talk | contribs)

Jump to: navigation, search

The task can be easily done by this macros:

REM  *****  BASIC  *****
 
Sub Formulator
Dim Doc As Object
Dim objects As Object
Dim obj As Object
Dim embedded As Object
Dim formula As String
Dim newFontSize As Integer
 
newFontSize = InputBox("New formula font size:", "BaseFontHeight", 14)
 
' Create document object
doc = ThisComponent
rem doc = StarDesktop.CurrentComponent
 
' get objects
objects = Doc.getEmbeddedObjects()
 
' now iterate objects
MsgBox("There are " + objects.count + " objects found.")
For i = 0 to objects.count - 1
 
	rem embedded = objects(i).getEmbeddedObject() 'this line produces 'Object variable not set' when i becomes 20
	embedded = objects(i).embeddedObject 'but this code works!
 
	rem MsgBox("i=" + i + " name=" + objects(i).name + " " + embedded.Formula)
 
	If embedded.supportsService("com.sun.star.formula.FormulaProperties") Then
		embedded.BaseFontHeight = newFontSize
		' some tricks to force OO.o redraw formulas
		formula = embedded.Formula
		embedded.Formula = ""
		embedded.Formula = formula
	End If
 
Next i
 
doc.reformat()
 
MsgBox("Done!")
 
End Sub

Related Links

This is a modified version of the code from here [1] (it seems that original version doesn't work in Ooo 3.1).

Other urls about this subject:

Personal tools