Hello,
REH-CAE-RPT wrote:Does anybody know a way to highlight all spelling errors within a document
Here is a first attempt:
- Code: Select all Expand viewCollapse view
sub highlight_spell_errors(optional container)
if ismissing(container) then
container = thiscomponent
end if
' get text object
T = container.Text
' get text cursor
cursor = T.createTextCursor()
' get spell checker service
lsm = createUnoService("com.sun.star.linguistic2.LinguServiceManager")
spellchecker = lsm.getSpellchecker()
' bypassing an uno api bug which confuse between XSpellChecker and XSpellChecker1
reflector = createUnoService("com.sun.star.reflection.CoreReflection")
xspellchecker = reflector.forName("com.sun.star.linguistic2.XSpellChecker")
isvalid = xspellchecker.getMethod("isValid")
' iterate through all words
dim props() as new com.sun.star.beans.PropertyValue
do
cursor.gotoStartOfWord(False)
cursor.gotoEndOfWord(True)
word = cursor.String
if not isValid.invoke(spellchecker, array(word, cursor.CharLocale, props())) then
cursor.CharBackColor = 16776960
end if
cursor.gotoNextWord(False)
if cursor.isEndOfParagraph then
cursor.gotoNextParagraph(False)
end if
loop while T.compareRegionEnds(T, cursor) <> 0
' check sub texts
frames = container.TextFrames
for each frame in frames
on error resume next
highlight_spell_errors(frame)
next frame
tables = container.TextTables
for n = 0 to tables.Count -1
table = tables(n)
cellnames = tables(n).CellNames
for each cellname in cellnames
cell = table.getCellByName(cellname)
highlight_spell_errors(cell)
next cellname
next n
end sub
It shall exist a simpler way, but I can't figure out how.
In addition, it seems that there's a bug with the spell checker api service, as interfaces
XSpellChecker and
XSpellChecker1 are conflicting...
Do not expect any great performance over large document.