[Solved] How to get the Current Cell or Current Sheet
-
- Posts: 6
- Joined: Wed Aug 18, 2010 9:41 pm
[Solved] How to get the Current Cell or Current Sheet
Hellow, I guess my question is easy but didnt find how to do it.
In a OpenOffice Calc Spreadsheet
What is the method to get the cell that has the focus (from which the function is loaded). And the same for the Sheet.
The Current Cell and The Current Sheet.
Then, how to I get The Column Number and Row Number of this current Cell.
Thanks in Advance
In a OpenOffice Calc Spreadsheet
What is the method to get the cell that has the focus (from which the function is loaded). And the same for the Sheet.
The Current Cell and The Current Sheet.
Then, how to I get The Column Number and Row Number of this current Cell.
Thanks in Advance
Last edited by Hagar Delest on Sat Aug 28, 2010 7:03 pm, edited 1 time in total.
Reason: tagged [Solved].
Reason: tagged [Solved].
OpenOffice 3.2.1 on Windows XP
-
- Posts: 6
- Joined: Wed Aug 18, 2010 9:41 pm
Re: Easy Question - How to get the Current Cell or Current S
Hello I found something, but ok now if I write "last()" in a cell It does not write the word "oops" on it after I hit enter, and it doesnt write anywhere, why is it???:
Code: Select all
Sub Main
End Sub
Function Last()
oSheet=thiscomponent.getcurrentcontroller.activesheet
oCell = ThisComponent.getCurrentSelection()
oCell.SetString("oops")
End Function
OpenOffice 3.2.1 on Windows XP
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: Easy Question - How to get the Current Cell or Current S
Your method of getting the current selection is fine. But if your trying to write a user-defined function to enter into a cell, it is illegal for such a function to modify cell contents except through its return value (same as Excel, by the way). If you change your Last to a Sub, and run it from either Tools > Macros or from the IDE, it will indeed write "oops" in the current cell.
if you want a function to write a string in a cell, you could do
and then ENTERING =FNLAST("oops") in the cell will display "oops," but that's kind of pointless since you could just type "oops" in the cell without the function.
You could put "oops" in another cell, say A1, and then put =FNLAST(A1) somewhere, but, of course, you could more easily just do =A1.
Code: Select all
Sub Last()
oSheet=thiscomponent.getcurrentcontroller.activesheet
oCell = ThisComponent.getCurrentSelection()
oCell.SetString("oops")
End Sub
Code: Select all
Function fnLast(s As String) As String
fnLast = s
End Function
You could put "oops" in another cell, say A1, and then put =FNLAST(A1) somewhere, but, of course, you could more easily just do =A1.
Apache OpenOffice 4.1.1
Windows XP
Windows XP
-
- Posts: 6
- Joined: Wed Aug 18, 2010 9:41 pm
Re: Easy Question - How to get the Current Cell or Current S
Thank you very much for your help.
I understand it looks pointless but what I want is this: after hitting enter in a cell, I want the code to search the last value below my current cell (the last cell that has content below the current in the same column) and type it, so when it finds an empty cell takes the last non-empty value and type it to the current cell. It seems very simple but I dont have any experience writing macros.
Now I got it done BUT it does NOT update when I change the values of the cells, I would have to write again "=Last()" in the cell and hit enter. I would like to know if you can help me to this get updated all time.
Thanks in advance, this is my code:
I understand it looks pointless but what I want is this: after hitting enter in a cell, I want the code to search the last value below my current cell (the last cell that has content below the current in the same column) and type it, so when it finds an empty cell takes the last non-empty value and type it to the current cell. It seems very simple but I dont have any experience writing macros.
Now I got it done BUT it does NOT update when I change the values of the cells, I would have to write again "=Last()" in the cell and hit enter. I would like to know if you can help me to this get updated all time.
Thanks in advance, this is my code:
Code: Select all
Function Last()
Dim finalValue
Dim oCell,oSheets,oSheet,oDoc,cellText,column,row,s
oDoc = ThisComponent
oCell = oDoc.getCurrentSelection
column = oCell.CellAddress.Column
row = oCell.CellAddress.Row
'cellText = oCell.getString
oSheets = oDoc.getSheets
' oSheet= oDoc.getSheets().getByIndex(s)
' For s = 0 to oSheets.Count - 1
For s = 0 to 1000
' oSheet= oDoc.getSheets().getByIndex(s)
oSheet=thiscomponent.getcurrentcontroller.activesheet
if oSheet.GetCellbyPosition(column,row+s).getValue()=0 Then
else
finalValue=oSheet.GetCellbyPosition(column,row+s).getValue()
endif
Next s
Last=finalValue
End Function
OpenOffice 3.2.1 on Windows XP
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: Easy Question - How to get the Current Cell or Current S
Your function should recalculate if you hit Ctrl + Shift + F9. If you want to make that recalculate automatically every time you modify the sheet, it's a bit trickier.
Apache OpenOffice 4.1.1
Windows XP
Windows XP
-
- Posts: 6
- Joined: Wed Aug 18, 2010 9:41 pm
Re: Easy Question - How to get the Current Cell or Current S
Trickier and maybe difficult.Charlie Young wrote:Your function should recalculate if you hit Ctrl + Shift + F9. If you want to make that recalculate automatically every time you modify the sheet, it's a bit trickier.
so... what is the normal way to do this? seems to be a common issue for anyone...
OpenOffice 3.2.1 on Windows XP
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: Easy Question - How to get the Current Cell or Current S
I'm not sure there is a normal way to do this, but here goes. Your LAST function is unusual in that its result is based on the position of the selection rather than on any particular cell value, thus the recalculation must occur whenever the selection changes, not just when cell values are modified. In the latter case one can use a modifyListener, but in this case one needs a selectionChangeListener, which I think I have managed to get working. To use it, run the macroernestodeorozco wrote:Trickier and maybe difficult.Charlie Young wrote:Your function should recalculate if you hit Ctrl + Shift + F9. If you want to make that recalculate automatically every time you modify the sheet, it's a bit trickier.
so... what is the normal way to do this? seems to be a common issue for anyone...
Setup_SelectionChangeListener
After running this, the entire document will be recalculated any time the cell selection is changed. That isn't so bad here because in this example there is only one cell to recalculate, that is A1, where I put the LAST function. The recalculation could be restricted if necessary, but maybe we'll discuss that later.
You can remove the listener with the Remove_Listener macro.
I also took some liberties with the last function itself. My method of finding the last value is much quicker, even though it looks for values all the way down to row 65,535.
Code: Select all
Function Last()
Dim finalValue
Dim oCell,oSheets,oSheet,oDoc,cellText,column,row
Dim Cell As Object
Dim oCells
oDoc = ThisComponent
oCell = oDoc.getCurrentSelection
column = oCell.CellAddress.Column
row = oCell.CellAddress.Row
oSheet=thiscomponent.getcurrentcontroller.activesheet
if row <=65535 then
oCells = oSheet.getCellRangeByPosition(column, row, column, 65535).queryContentCells(23)
endif
finalValue = 0
For Each Cell in oCells.Cells
if Cell.FormulaResultType = 1 then
finalValue = Cell.Value
else
finalValue = Cell.String
endif
Next
Last=finalValue
End Function
I sure hope I understand what you're after.
- Attachments
-
- LastFunction.ods
- Last Function - selection change example
- (8.84 KiB) Downloaded 769 times
Apache OpenOffice 4.1.1
Windows XP
Windows XP
-
- Posts: 6
- Joined: Wed Aug 18, 2010 9:41 pm
Re: Easy Question - How to get the Current Cell or Current S
Thank you I appreciate your help and work. It has been good for my learning.
Have a nice day
Have a nice day
OpenOffice 3.2.1 on Windows XP
Re: [Solved] How to get the Current Cell or Current Sheet
what about a macro to read the text inside the current selected cell?
-----
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
using latest X-LibreOffice release, made portable by winPenPack.com
http://www.winpenpack.com/main/download.php?view.1354
Re: [Solved] How to get the Current Cell or Current Sheet
Can't you read?Tommy wrote:what about a macro to read the text inside the current selected cell?
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Easy Question - How to get the Current Cell or Current S
Very usable - thank you. My problem is that setting date as a string changes format of the cell.ernestodeorozco wrote:Hello I found something, but ok now if I write "last()" in a cell It does not write the word "oops" on it after I hit enter, and it doesnt write anywhere, why is it???:
Code: Select all
Sub Main End Sub Function Last() oSheet=thiscomponent.getcurrentcontroller.activesheet oCell = ThisComponent.getCurrentSelection() oCell.SetString("oops") End Function
Code: Select all
ThisComponent.getCurrentSelection().SetString(CStr(Date))
AOO 4.1.4 (Polish) on Windows 10 (64b) / AOO 4.1.0 on Windows Vista / (LibreOffice on Mageia Linux)
Re: [Solved] How to get the Current Cell or Current Sheet
Found answer (does not touch format of a cell assigning date):
Code: Select all
ThisComponent.getCurrentSelection().Value = Date
AOO 4.1.4 (Polish) on Windows 10 (64b) / AOO 4.1.0 on Windows Vista / (LibreOffice on Mageia Linux)
Re: [Solved] How to get the Current Cell or Current Sheet
oCell.setValue(basic_date) failed at the time when this topic started because setValue used to take numbers only for cell values. The cell value could not be a Basic date. Some developer was so mercyful to implement a kind of implicit background conversion for this particular use case.
This can not work with other macro languages.
With Basic or any other language you can do the following in any locale context and with any document's NullDate setting:
oCell.FormulaLocal = strISO
where strISO is an ISO string in format "yyyy-mm-dd" or "yyyy-mm-dd hh:mm:ss.00" and the FormulaLocal property is a string you would enter into the formula bar (not necessary a formula expression starting with =)
Basic: oCell.FormulaLocal = Year(Date)& "-" & Month(Date)& "-" & Day(Date)
Python: oCell.FormulaLocal = time.strftime('%Y-%m-%d')
This can not work with other macro languages.
With Basic or any other language you can do the following in any locale context and with any document's NullDate setting:
oCell.FormulaLocal = strISO
where strISO is an ISO string in format "yyyy-mm-dd" or "yyyy-mm-dd hh:mm:ss.00" and the FormulaLocal property is a string you would enter into the formula bar (not necessary a formula expression starting with =)
Basic: oCell.FormulaLocal = Year(Date)& "-" & Month(Date)& "-" & Day(Date)
Python: oCell.FormulaLocal = time.strftime('%Y-%m-%d')
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: [Solved] How to get the Current Cell or Current Sheet
Dear Villeroy,
First, thank you for your reply.
Your code
works in my macro perfectly.
I prefer my solution.
I assume, that OO Basic Date returns a float number coding date as a number of days since 1900/01/01. Thus, a cell value can be a Basic Date.
I don't think it is performed any internal conversion. Practicing Visual Basic Script, I suppose that result of Date has type of variant. If the Date is being assigned to a variable of numeric type such format is available.
First, thank you for your reply.
Your code
Code: Select all
oCell.FormulaLocal = Year(Date)& "-" & Month(Date)& "-" & Day(Date)
I prefer my solution.
Code: Select all
oCell.Value = Date
I don't think it is performed any internal conversion. Practicing Visual Basic Script, I suppose that result of Date has type of variant. If the Date is being assigned to a variable of numeric type such format is available.
AOO 4.1.4 (Polish) on Windows 10 (64b) / AOO 4.1.0 on Windows Vista / (LibreOffice on Mageia Linux)
Re: [Solved] How to get the Current Cell or Current Sheet
Basic Date return a special date value which is specific to the Basic language. In the documentation of all Basic languages, Date (vartype 7) is different from any type of number (single, double, integer, long, vartypes 2 to 6).
Late office versions perform an implicit converstion to number when you using setValue with such a Basic value ... and look, they do it wrongly in some subtile use cases where the NullDate is different.
Open a spreadsheet.
Call Tools>Options>Calc>Calculation and set the base date from 1899-12-30 to 1904-01-01
Run ThisComponent.CurrentSelection.setValue(Date)
The date is 2021-11-05 because of the modified NullDate. StarBasic assumes 1899-12-30 without testing the document's NullDate
You have to do something like ThisComponent.CurrentSelection.setValue(Date + (ThisComponent.NullDate - Date)) but this does not work because the Null date is an UNO struct which can't be subtracted in Basic.
Late office versions perform an implicit converstion to number when you using setValue with such a Basic value ... and look, they do it wrongly in some subtile use cases where the NullDate is different.
Open a spreadsheet.
Call Tools>Options>Calc>Calculation and set the base date from 1899-12-30 to 1904-01-01
Run ThisComponent.CurrentSelection.setValue(Date)
The date is 2021-11-05 because of the modified NullDate. StarBasic assumes 1899-12-30 without testing the document's NullDate
You have to do something like ThisComponent.CurrentSelection.setValue(Date + (ThisComponent.NullDate - Date)) but this does not work because the Null date is an UNO struct which can't be subtracted in Basic.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: [Solved] How to get the Current Cell or Current Sheet
Dear Villeroy,
Thank you for the clarification of the variant types and discussion of the document's NullDate. I have learned a lot.
I have tested your variant of Date assignment to a cell in case of switching the base date. You are right. Your version is more robust than mine.
Your words
I don't understand the phrase
Thank you for the clarification of the variant types and discussion of the document's NullDate. I have learned a lot.
I have tested your variant of Date assignment to a cell in case of switching the base date. You are right. Your version is more robust than mine.
Your words
viewtopic.php?f=74&t=82181 make more sense to my approach, however.exotic spreadsheet applications
I don't understand the phrase
. Probably, this idea should have following form:Date + (ThisComponent.NullDate - Date)
Code: Select all
Date - ThisComponent.NullDate
AOO 4.1.4 (Polish) on Windows 10 (64b) / AOO 4.1.0 on Windows Vista / (LibreOffice on Mageia Linux)
Re: [Solved] How to get the Current Cell or Current Sheet
Date + (ThisComponent.NullDate - Date) is plain wrong. I just wanted to indicate that you have to subtract the difference between ThisComponent.NullDate and 1899-12-30 (StarBasic's NullDate) from the current date before you can insert the resulting Basic date into a sheet cell.
This may work with Basic function DateSerial and my user defined ConvertDateTime:
without ConvertDateTime we may concatenate the parts of the UNO-struct to an ISO string and convert that to a StarBasic date:
or
The benefit of my ConvertDateTime is that you don't have to get your head round so many data types and functions. Just pass anything that represents a date-time and one of the names indicating the type you want to get back from the function as indicated by the spreadsheet attached to the tutorial. It converts all types of strings, integers, doubles and dialog control values in OpenOffice and in LibreOffice and with any NullDate setting.
The macro on Module1 triggered by the push button demonstrates the power of that function when translating between different types of form controls in LO/AOO and sheet cells with variable NullDates. OK, it does not handle any NullDates, but it helps you to handle them correctly.
This may work with Basic function DateSerial and my user defined ConvertDateTime:
Code: Select all
dtCellValue = DateSerial(1899, 12, 30) - ConvertDateTime(ThisComponent.NullDate,"BASIC") + Date
oCell.setValue(dtCellValue)
Code: Select all
obj = ThisComponent.NullDate
dtCellValue = DateSerial(1899, 12, 30) - cDate(obj.Year &"-"& obj.Month &"-"& obj.Day) + Date
Code: Select all
dtCellValue = DateSerial(1899, 12, 30) - DateSerial(cInt(obj.Year), cInt(obj.Month), cInt(obj.Day)) + Date
The macro on Module1 triggered by the push button demonstrates the power of that function when translating between different types of form controls in LO/AOO and sheet cells with variable NullDates. OK, it does not handle any NullDates, but it helps you to handle them correctly.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: [Solved] How to get the Current Cell or Current Sheet
Villeroy! Nice discussion. Thanks again.
AOO 4.1.4 (Polish) on Windows 10 (64b) / AOO 4.1.0 on Windows Vista / (LibreOffice on Mageia Linux)
Re: [Solved] How to get the Current Cell or Current Sheet
Another answer to the original topic:
Install https://libreoffice.org/ which is the legitimate successor of OpenOffice.
Among hundreds of other new features, this application has shortcut commands to insert the current date or time into the active cell (BUT NOT the date+time, ).
The macro routine which inserts the current date-time correctly into the active cell (and nowhere else) independently from locale and NullDate settings may look like this:
search "getActiveCell" in this forum for a Basic function which returns the active cell from any given controller (aka view or "window").
Install https://libreoffice.org/ which is the legitimate successor of OpenOffice.
Among hundreds of other new features, this application has shortcut commands to insert the current date or time into the active cell (BUT NOT the date+time, ).
The macro routine which inserts the current date-time correctly into the active cell (and nowhere else) independently from locale and NullDate settings may look like this:
Code: Select all
Sub Now2ActiveCell()
GlobalScope.BasicLibraries.loadLibrary("Calc") 'my personal Calc lib
cell = Calc.modTools.getActiveCell(ThisComponent.getCurrentController())
cell.FormulaLocal = Format(Now, "yyyy-mm-dd hh:mm:ss") 'yet another alternative ;)
cell.setValue(cell.getValue())
End Sub
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: [Solved] How to get the Current Cell or Current Sheet
I need to get the column index of an active cell. I do it as follows:
It works well with the exception when CurrentSelection covers more then one cell. In the exceptional situation, the error is reported saying that the is no such property or method as CellAddress.
I decided to remove any potential selection by... imitating move the position of an active cell. Imitation is performed by declaration of the shift by 0. I do it using the dispatcher.
Is it possible to remove selection in the more natural, simpler way?
Code: Select all
Dim StartCol%
StartCol = ThisComponent.CurrentSelection.CellAddress.Column
I decided to remove any potential selection by... imitating move the position of an active cell. Imitation is performed by declaration of the shift by 0. I do it using the dispatcher.
Code: Select all
Dim StartCol%, args(1) As New com.sun.star.beans.PropertyValue, document, dispatcher As Object
Rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
Rem Remove a selection if any
args(0).Name = "By"
args(0).Value = 0
args(1).Name = "Sel"
args(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoLeft", "", 0, args())
StartCol = ThisComponent.CurrentSelection.CellAddress.Column
AOO 4.1.4 (Polish) on Windows 10 (64b) / AOO 4.1.0 on Windows Vista / (LibreOffice on Mageia Linux)
Re: [Solved] How to get the Current Cell or Current Sheet
search this forum for "getActiveCell". It actually returns the active cell of any spreadsheet window.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: [Solved] How to get the Current Cell or Current Sheet
Dear respectfull Villeroy,
My current question sounds "Is it possible to remove selection in the more natural, simpler way?" Maybe you know another place on the forum to ask (?)
I know your solution "getActiveCell" you have been promoting. Congratulations for the sub.
My current question sounds "Is it possible to remove selection in the more natural, simpler way?" Maybe you know another place on the forum to ask (?)
I know your solution "getActiveCell" you have been promoting. Congratulations for the sub.
AOO 4.1.4 (Polish) on Windows 10 (64b) / AOO 4.1.0 on Windows Vista / (LibreOffice on Mageia Linux)
Re: [Solved] How to get the Current Cell or Current Sheet
(Comes a sub collapsing the selection for the purpose.)antekg wrote:I need to get the column index of an active cell. I do it as follows:
Regarding the original question of this thread and the quotation above this seems to be a workaround with grave disadvantages: The previous selection is lost, and even if the selection gets saved and restored in addition, the cell under focus will not be reinstated if it not was the topmost leftmost cell of the selection, in specific if it not was part of the selection at all. (Cf. Andrew Pitonyak: "Useful Macro Information".)
I don't know one. Would like to know, however.antekg wrote:Is it possible to remove selection in the more natural, simpler way?
This is a new question, and actually it should better be posted in a new thread of this forum. (The branch 'Macros and UNO API' is obviously the correct one if the "more natural way" is expected to be by user code again.antekg wrote:... Maybe you know another place on the forum to ask (?)
Concerning the also discussed task to enter something into the "active cell" (cell under focus) the way evaluating the .ViewData property (suggested by Villeroy) has the valuable advantage that you can do this without changing the current selection or moving the focus.
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: [Solved] How to get the Current Cell or Current Sheet
because you want to reduce the current selection to the active cell. And I tried to show you how to get the active cell in any situation. A spreadsheet controller's current selection can be a cell, a range, multiple ranges or shapes (rectangular objects on the draw page).antekg wrote:Dear respectfull Villeroy,
My current question sounds "Is it possible to remove selection in the more natural, simpler way?"
And no, I don't know an elegant way to reduce a range selection to the active cell.
Edit: Oh, wait: GlobalScope.BasicLibraries.loadLibrary("Calc") view = ThisComponent.getCurrentController() c = getActiveCell(view) view.select(c) |
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: [Solved] How to get the Current Cell or Current Sheet
Dear Villeroy, Dear Loop,
I agree:
1. "to reduce the current selection to the active cell" is the correct phrase describing my intentions,
2. The getActiveCell with ViewData of Villeroy is the universal and robust sub,
3. I will start a new thread. My problem is a part of a larger project. In the project I move the position of an active cell anyway so it destroys the selection. I am collecting the potential risks applying this simple statement:
StartCol = ThisComponent.CurrentSelection.CellAddress.Column
Thank you here.
Found browsing OOME_3_0 then https://github.com/apache/openoffice: main/sc/inc/sccommands.h and main/sc/sdi/scalc.sdi
... and finally
I agree:
1. "to reduce the current selection to the active cell" is the correct phrase describing my intentions,
2. The getActiveCell with ViewData of Villeroy is the universal and robust sub,
3. I will start a new thread. My problem is a part of a larger project. In the project I move the position of an active cell anyway so it destroys the selection. I am collecting the potential risks applying this simple statement:
StartCol = ThisComponent.CurrentSelection.CellAddress.Column
Thank you here.
Found browsing OOME_3_0 then https://github.com/apache/openoffice: main/sc/inc/sccommands.h and main/sc/sdi/scalc.sdi
Code: Select all
dispatcher.executeDispatch(document, ".uno:Deselect", "", 0, Array())
Code: Select all
Dim document, dispatcher As Object
Rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
Rem removing a selection if any
dispatcher.executeDispatch(document, ".uno:Deselect", "", 0, Array())
StartCol% = ThisComponent.CurrentSelection.CellAddress.Column
AOO 4.1.4 (Polish) on Windows 10 (64b) / AOO 4.1.0 on Windows Vista / (LibreOffice on Mageia Linux)
Re: [Solved] How to get the Current Cell or Current Sheet
Sorry. I forgot:
In fact "JohnSUN-Pensioner" recently posted some code I did not understand. I asked him and since I should know: Instantiating a SheetCellRanges structure without any initialisation and giving it to the CurrentController for selection will collapse the existing selection completely and leave the focus on the cell that had it previously without selecting that cell:
Editing: I think I found the post by JohnSUN: viewtopic.php?f=20&t=90536&p=428025&hil ... s+#p428025
Please note that neither a "com.sun.star.sheet.SheetCellRange" object nor a "com.sun.star.sheet.SheetCell" object can be instantiated this way. You would get a Null Variant/Object.
In fact "JohnSUN-Pensioner" recently posted some code I did not understand. I asked him and since I should know: Instantiating a SheetCellRanges structure without any initialisation and giving it to the CurrentController for selection will collapse the existing selection completely and leave the focus on the cell that had it previously without selecting that cell:
Code: Select all
tDoc=ThisComponent
tCC=tDoc.CurrentController
tNullSel=tDoc.CreateInstance("com.sun.star.sheet.SheetCellRanges")
tCC.Select(tNullSel)
Please note that neither a "com.sun.star.sheet.SheetCellRange" object nor a "com.sun.star.sheet.SheetCell" object can be instantiated this way. You would get a Null Variant/Object.
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: [Solved] How to get the Current Cell or Current Sheet
Thank you Lupp.
I have referred to the solution on the Polish forum https://forum.openoffice.org/pl/forum/v ... 319#p18319
I have referred to the solution on the Polish forum https://forum.openoffice.org/pl/forum/v ... 319#p18319
AOO 4.1.4 (Polish) on Windows 10 (64b) / AOO 4.1.0 on Windows Vista / (LibreOffice on Mageia Linux)