Hello,
in the German forum for LibreOffice (https://www.libreoffice-forum.de/viewto ... =5&t=33002) there is a question unsolved:
Can Writer show the current cursor position as line/column in the status bar like Notepad++ (or Microsoft Word) can do?
Any suggestions?
Thanks for reading, cheers.
[Issue] Display line number, column number in status bar
-
- Volunteer
- Posts: 254
- Joined: Tue Apr 18, 2017 8:23 am
- Location: Germany
[Issue] Display line number, column number in status bar
Last edited by Hagar Delest on Sun Nov 22, 2020 12:29 pm, edited 1 time in total.
Reason: tagged issue
Reason: tagged issue
LibreOffice current versions 7 and OpenOffice 4.1.15
on LinuxMint 20 - 21 Mate, W10-64 pro
on LinuxMint 20 - 21 Mate, W10-64 pro
- Hagar Delest
- Moderator
- Posts: 32627
- Joined: Sun Oct 07, 2007 9:07 pm
- Location: France
Re: Writer: display line number, column number in status bar
Not yet implemented (nor in LibreOffice): [Issue] Way to view column/row numbers in Writer?
Issue 18004.
Issue 18004.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
Re: [Issue] Display line number, column number in status bar
You could turn on the line numbering for the line.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: [Issue] Display line number, column number in status bar
A simple but probably tedious to use macro can give the column number in a message box.
CAUTION: may not work/give errors in circumstances such as the cursor not being a normal text one.
Edit: slight improvement, collapsed selection before showing message box
CAUTION: may not work/give errors in circumstances such as the cursor not being a normal text one.
Code: Select all
Sub GetCursorColumn
on error goto hr
vc = thiscomponent.currentcontroller.viewcursor
vc.gotoStartOfLine(true)
lenst= len(vc.string)
vc.collapsetoend
msgbox "Column: " & lenst
hr:
End Sub
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: [Issue] Display line number, column number in status bar
Unfortunately the ruler doesn't allow you to have Column marking.
A bit off beat... but if you're using a fixed width (non-proportional) font you can make your own and put it in the header.
A bit off beat... but if you're using a fixed width (non-proportional) font you can make your own and put it in the header.
- Attachments
-
- Heading Character Ruler.odt
- (10.92 KiB) Downloaded 175 times
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: [Issue] Display line number, column number in status bar
Q&D:
We may feel sure there are only simple cases without nested tables or frames or whatever, but we cannot be sure.
That "rare complications" to be expected make reliable solutions rare.
Code: Select all
Sub lineAndPosInText(Optional pDoc)
REM If the text object of the current selection contains interceptive tables,
REM the lines of the leftmost column should be counted as if they are lines
REM of ordinary paragraphs - independent of the heights of the cells.
REM TextTable cause problems again and again. Not sure if my stetement is reloable.
If isMissing(pDoc) Then pDoc = ThisComponent
oldSel = pDoc.CurrentSelection
currPos = oldSel(0).End
cCtrl = pDoc.CurrentController
vc = cCtrl.ViewCursor
currText = vc.Text
inTableCell = tryCellName(currText)
inTable = (inTableCell<>"")
inFrame = currText.supportsService("com.sun.star.text.BaseFrame")
vc.gotoRange(currPos, False)
vc.goToStartOfLine(False)
REM Strange! The ViewCursor.String is empty after vc.goToStartOfLine(True) if in a TextTable cell.
REM Therefore:
tcPos = currText.createTextCursorByRange(currPos)
tcPos.gotoRange(vc.Start, True)
charsLeft = Len(tcPos.String)
trgLineStart = vc.Start
If EqualUnoObjects(currText, pDoc.Text) Then
REM For the BodyText line counting is done per page.
vc.jumpToStartOfPage()
Else
REM Otherwise for the current text not regarding pages.
cCtrl.select(currText.Start)
End If
LinesAbove = 0
REM TextTable are a mess!!
REM The following may NOT work if nested TextTable objects exist.
REM Will not work araound! Someone else?
While currText.compareRegionStarts(vc.Start, trgLineStart)>0
LinesAbove = LinesAbove + 1
vc.goDown(1, False)
Wend
MsgBox("Line:" & LinesAbove + 1 & "; Position in line:" & charsLeft + 1 & Chr(10) & _
IIf(inTableCell<>"", "Table cell " & inTableCell, "") & IIf(inFrame, "Textframe!", ""))
cCtrl.select(oldSel)
End Sub
Function tryCellName(pObj)
tryCellName = ""
On Local Error Goto fail
tryCellName = pObj.CellName
fail:
End Function
That "rare complications" to be expected make reliable solutions rare.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
---
Lupp from München
Re: [Issue] Display line number, column number in status bar
This is Lupp's code slightly modified to add his result to the status bar, wait half a second and return the status bar to normal. You just need a shortcut to run the macro.
Change the 500 number to a different value if you want more time to look at the result.
Change the 500 number to a different value if you want more time to look at the result.
Code: Select all
Sub lineAndPosInText2()
REM If the text object of the current selection contains interceptive tables,
REM the lines of the leftmost column should be counted as if they are lines
REM of ordinary paragraphs - independent of the heights of the cells.
REM TextTable cause problems again and again. Not sure if my stetement is reloable.
'If isMissing(pDoc) Then
pDoc = ThisComponent
oldSel = pDoc.CurrentSelection
currPos = oldSel(0).End
cCtrl = pDoc.CurrentController
vc = cCtrl.ViewCursor
currText = vc.Text
inTableCell = tryCellName(currText)
inTable = (inTableCell<>"")
inFrame = currText.supportsService("com.sun.star.text.BaseFrame")
vc.gotoRange(currPos, False)
vc.goToStartOfLine(False)
REM Strange! The ViewCursor.String is empty after vc.goToStartOfLine(True) if in a TextTable cell.
REM Therefore:
tcPos = currText.createTextCursorByRange(currPos)
tcPos.gotoRange(vc.Start, True)
charsLeft = Len(tcPos.String)
trgLineStart = vc.Start
If EqualUnoObjects(currText, pDoc.Text) Then
REM For the BodyText line counting is done per page.
vc.jumpToStartOfPage()
Else
REM Otherwise for the current text not regarding pages.
cCtrl.select(currText.Start)
End If
LinesAbove = 0
REM TextTable are a mess!!
REM The following may NOT work if nested TextTable objects exist.
REM Will not work araound! Someone else?
While currText.compareRegionStarts(vc.Start, trgLineStart)>0
LinesAbove = LinesAbove + 1
vc.goDown(1, False)
Wend
cCtrl.select(oldSel)
lbl = ( "Line:" & LinesAbove + 1 & "; Position in line:" & charsLeft + 1 & Chr(10) & _
IIf(inTableCell<>"", "Table cell " & inTableCell, "") & IIf(inFrame, "Textframe!", ""))
sbar = pdoc.getCurrentController.StatusIndicator 'add to the status ar
sbar.start( lbl,0 )
Wait 500 'wait a bit so you can look at it CHANGE 500 TO PREFERRED TIME 500 = HALF A SECOND 1000 = 1 SECOND
sbar.end()
End Sub
Function tryCellName(pObj)
tryCellName = ""
On Local Error Goto fail
tryCellName = pObj.CellName
fail:
End Function
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: [Issue] Display line number, column number in status bar
I need a second to read it, and it helps if its abbreviated a little.
Code: Select all
Sub lineAndPosInText2()
REM If the text object of the current selection contains interceptive tables,
REM the lines of the leftmost column should be counted as if they are lines
REM of ordinary paragraphs - independent of the heights of the cells.
REM TextTable cause problems again and again. Not sure if my stetement is reloable.
'If isMissing(pDoc) Then
pDoc = ThisComponent
oldSel = pDoc.CurrentSelection
currPos = oldSel(0).End
cCtrl = pDoc.CurrentController
vc = cCtrl.ViewCursor
currText = vc.Text
inTableCell = tryCellName(currText)
inTable = (inTableCell<>"")
inFrame = currText.supportsService("com.sun.star.text.BaseFrame")
vc.gotoRange(currPos, False)
vc.goToStartOfLine(False)
REM Strange! The ViewCursor.String is empty after vc.goToStartOfLine(True) if in a TextTable cell.
REM Therefore:
tcPos = currText.createTextCursorByRange(currPos)
tcPos.gotoRange(vc.Start, True)
charsLeft = Len(tcPos.String)
trgLineStart = vc.Start
If EqualUnoObjects(currText, pDoc.Text) Then
REM For the BodyText line counting is done per page.
vc.jumpToStartOfPage()
Else
REM Otherwise for the current text not regarding pages.
cCtrl.select(currText.Start)
End If
LinesAbove = 0
REM TextTable are a mess!!
REM The following may NOT work if nested TextTable objects exist.
REM Will not work araound! Someone else?
While currText.compareRegionStarts(vc.Start, trgLineStart)>0
LinesAbove = LinesAbove + 1
vc.goDown(1, False)
Wend
cCtrl.select(oldSel)
lbl = ( "Line:" & LinesAbove + 1 & ", Col:" & charsLeft + 1 & Chr(10) & _
IIf(inTableCell<>"", "Table cell " & inTableCell, "") & IIf(inFrame, "Textframe!", ""))
sbar = pdoc.getCurrentController.StatusIndicator
sbar.start( lbl,0 )
Wait 1000
sbar.end()
End Sub
Function tryCellName(pObj)
tryCellName = ""
On Local Error Goto fail
tryCellName = pObj.CellName
fail:
End Function
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)