[Solved] How to get the Current Cell or Current Sheet

Creating a macro - Writing a Script - Using the API

[Solved] How to get the Current Cell or Current Sheet

Postby ernestodeorozco » Wed Aug 18, 2010 9:46 pm

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
Last edited by Hagar Delest on Sat Aug 28, 2010 7:03 pm, edited 1 time in total.
Reason: tagged [Solved].
OpenOffice 3.2.1 on Windows XP
ernestodeorozco
 
Posts: 6
Joined: Wed Aug 18, 2010 9:41 pm

Re: Easy Question - How to get the Current Cell or Current S

Postby ernestodeorozco » Wed Aug 18, 2010 10:09 pm

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   Expand viewCollapse view
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
ernestodeorozco
 
Posts: 6
Joined: Wed Aug 18, 2010 9:41 pm

Re: Easy Question - How to get the Current Cell or Current S

Postby Charlie Young » Wed Aug 18, 2010 11:10 pm

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.

Code: Select all   Expand viewCollapse view
Sub Last()
   oSheet=thiscomponent.getcurrentcontroller.activesheet
   oCell = ThisComponent.getCurrentSelection()
   oCell.SetString("oops")

End Sub


if you want a function to write a string in a cell, you could do

Code: Select all   Expand viewCollapse view
Function fnLast(s As String) As String

   fnLast = s

End Function


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.
Apache OpenOffice 4.1.1
Windows XP
User avatar
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

Postby ernestodeorozco » Thu Aug 19, 2010 5:49 am

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:
Code: Select all   Expand viewCollapse view
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
ernestodeorozco
 
Posts: 6
Joined: Wed Aug 18, 2010 9:41 pm

Re: Easy Question - How to get the Current Cell or Current S

Postby Charlie Young » Thu Aug 19, 2010 6:09 am

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
User avatar
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

Postby ernestodeorozco » Thu Aug 19, 2010 6:23 am

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.


Trickier and maybe difficult.
so... what is the normal way to do this? seems to be a common issue for anyone...
OpenOffice 3.2.1 on Windows XP
ernestodeorozco
 
Posts: 6
Joined: Wed Aug 18, 2010 9:41 pm

Re: Easy Question - How to get the Current Cell or Current S

Postby Charlie Young » Fri Aug 20, 2010 2:33 am

ernestodeorozco wrote:
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.


Trickier and maybe difficult.
so... what is the normal way to do this? seems to be a common issue for anyone...


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 macro

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   Expand viewCollapse view
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



Note that I'm also only working with the active sheet for now (except that anything anywhere in the document is recalculated).

I sure hope I understand what you're after.
Attachments
LastFunction.ods
Last Function - selection change example
(8.84 KiB) Downloaded 343 times
Apache OpenOffice 4.1.1
Windows XP
User avatar
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

Postby ernestodeorozco » Fri Aug 20, 2010 7:35 am

Thank you I appreciate your help and work. It has been good for my learning.
Have a nice day
OpenOffice 3.2.1 on Windows XP
ernestodeorozco
 
Posts: 6
Joined: Wed Aug 18, 2010 9:41 pm

Re: [Solved] How to get the Current Cell or Current Sheet

Postby Tommy » Sat Dec 25, 2010 8:04 pm

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
User avatar
Tommy
 
Posts: 252
Joined: Sun Dec 23, 2007 2:44 pm

Re: [Solved] How to get the Current Cell or Current Sheet

Postby Villeroy » Sat Dec 25, 2010 9:05 pm

Tommy wrote:what about a macro to read the text inside the current selected cell?

Can't you read?
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24653
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Easy Question - How to get the Current Cell or Current S

Postby antekg » Sat Nov 04, 2017 11:21 am

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   Expand viewCollapse view
Sub Main

End Sub

Function Last()
oSheet=thiscomponent.getcurrentcontroller.activesheet
oCell = ThisComponent.getCurrentSelection()
oCell.SetString("oops")
End Function


Very usable - thank you. My problem is that setting date as a string changes format of the cell.
Code: Select all   Expand viewCollapse view
ThisComponent.getCurrentSelection().SetString(CStr(Date))

I would like preserve the date format as it has been preset in the spreadsheet design.
AOO 4.1.4 (Polish) on Windows 10 (64b) / AOO 4.1.0 on Windows Vista / (LibreOffice on Mageia Linux)
User avatar
antekg
 
Posts: 14
Joined: Sat Oct 17, 2009 10:03 pm

Re: [Solved] How to get the Current Cell or Current Sheet

Postby antekg » Sat Nov 04, 2017 12:15 pm

Found answer (does not touch format of a cell assigning date):
Code: Select all   Expand viewCollapse view
ThisComponent.getCurrentSelection().Value = Date
AOO 4.1.4 (Polish) on Windows 10 (64b) / AOO 4.1.0 on Windows Vista / (LibreOffice on Mageia Linux)
User avatar
antekg
 
Posts: 14
Joined: Sat Oct 17, 2009 10:03 pm

Re: [Solved] How to get the Current Cell or Current Sheet

Postby Villeroy » Sat Nov 04, 2017 2:21 pm

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')
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24653
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] How to get the Current Cell or Current Sheet

Postby antekg » Sat Nov 04, 2017 3:33 pm

Dear Villeroy,
First, thank you for your reply.
Your code
Code: Select all   Expand viewCollapse view
oCell.FormulaLocal = Year(Date)& "-" & Month(Date)& "-" & Day(Date)

works in my macro perfectly.
I prefer my solution.
Code: Select all   Expand viewCollapse view
oCell.Value = Date

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.
AOO 4.1.4 (Polish) on Windows 10 (64b) / AOO 4.1.0 on Windows Vista / (LibreOffice on Mageia Linux)
User avatar
antekg
 
Posts: 14
Joined: Sat Oct 17, 2009 10:03 pm

Re: [Solved] How to get the Current Cell or Current Sheet

Postby Villeroy » Sat Nov 04, 2017 3:44 pm

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.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24653
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] How to get the Current Cell or Current Sheet

Postby antekg » Sat Nov 04, 2017 4:54 pm

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
exotic spreadsheet applications
https://forum.openoffice.org/en/forum/viewtopic.php?f=74&t=82181 make more sense to my approach, however.
I don't understand the phrase
Date + (ThisComponent.NullDate - Date)
. Probably, this idea should have following form:
Code: Select all   Expand viewCollapse view
Date - ThisComponent.NullDate
AOO 4.1.4 (Polish) on Windows 10 (64b) / AOO 4.1.0 on Windows Vista / (LibreOffice on Mageia Linux)
User avatar
antekg
 
Posts: 14
Joined: Sat Oct 17, 2009 10:03 pm

Re: [Solved] How to get the Current Cell or Current Sheet

Postby Villeroy » Sat Nov 04, 2017 5:10 pm

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:
Code: Select all   Expand viewCollapse view
dtCellValue = DateSerial(1899, 12, 30) - ConvertDateTime(ThisComponent.NullDate,"BASIC") + Date
oCell.setValue(dtCellValue)


without ConvertDateTime we may concatenate the parts of the UNO-struct to an ISO string and convert that to a StarBasic date:
Code: Select all   Expand viewCollapse view
obj = ThisComponent.NullDate
dtCellValue = DateSerial(1899, 12, 30) - cDate(obj.Year &"-"& obj.Month &"-"& obj.Day) + Date


or
Code: Select all   Expand viewCollapse view
dtCellValue = DateSerial(1899, 12, 30) - DateSerial(cInt(obj.Year), cInt(obj.Month), cInt(obj.Day)) + Date


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.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24653
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] How to get the Current Cell or Current Sheet

Postby antekg » Sat Nov 04, 2017 6:05 pm

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)
User avatar
antekg
 
Posts: 14
Joined: Sat Oct 17, 2009 10:03 pm

Re: [Solved] How to get the Current Cell or Current Sheet

Postby Villeroy » Sat Nov 04, 2017 7:51 pm

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, :evil: :roll: ).

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   Expand viewCollapse view
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

search "getActiveCell" in this forum for a Basic function which returns the active cell from any given controller (aka view or "window").
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24653
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] How to get the Current Cell or Current Sheet

Postby antekg » Fri Nov 17, 2017 11:53 am

I need to get the column index of an active cell. I do it as follows:
Code: Select all   Expand viewCollapse view
Dim StartCol%
StartCol = ThisComponent.CurrentSelection.CellAddress.Column

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.
Code: Select all   Expand viewCollapse view
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

Is it possible to remove selection in the more natural, simpler way?
AOO 4.1.4 (Polish) on Windows 10 (64b) / AOO 4.1.0 on Windows Vista / (LibreOffice on Mageia Linux)
User avatar
antekg
 
Posts: 14
Joined: Sat Oct 17, 2009 10:03 pm

Re: [Solved] How to get the Current Cell or Current Sheet

Postby Villeroy » Fri Nov 17, 2017 12:26 pm

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 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24653
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] How to get the Current Cell or Current Sheet

Postby antekg » Fri Nov 17, 2017 12:39 pm

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.
AOO 4.1.4 (Polish) on Windows 10 (64b) / AOO 4.1.0 on Windows Vista / (LibreOffice on Mageia Linux)
User avatar
antekg
 
Posts: 14
Joined: Sat Oct 17, 2009 10:03 pm

Re: [Solved] How to get the Current Cell or Current Sheet

Postby Lupp » Fri Nov 17, 2017 1:03 pm

antekg wrote:I need to get the column index of an active cell. I do it as follows:
(Comes a sub collapsing the selection for the purpose.)
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".)
antekg wrote:Is it possible to remove selection in the more natural, simpler way?

I don't know one. Would like to know, however.
antekg wrote:... Maybe you know another place on the forum to ask (?)

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.

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 5.4.2 and older versions, PortableOpenOffice 4.1.3 and older, StarOffice 5.2
---
Maybe we might! (Create a powerful UFO: United Free Office)
Lupp from München
User avatar
Lupp
Volunteer
 
Posts: 1522
Joined: Sat May 31, 2014 7:05 pm

Re: [Solved] How to get the Current Cell or Current Sheet

Postby Villeroy » Fri Nov 17, 2017 1:46 pm

antekg wrote:Dear respectfull Villeroy,
My current question sounds "Is it possible to remove selection in the more natural, simpler way?"

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).

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 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24653
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] How to get the Current Cell or Current Sheet

Postby antekg » Fri Nov 17, 2017 3:24 pm

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
Code: Select all   Expand viewCollapse view
dispatcher.executeDispatch(document, ".uno:Deselect", "", 0, Array())


... and finally
Code: Select all   Expand viewCollapse view
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)
User avatar
antekg
 
Posts: 14
Joined: Sat Oct 17, 2009 10:03 pm

Re: [Solved] How to get the Current Cell or Current Sheet

Postby Lupp » Fri Nov 17, 2017 9:56 pm

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:
Code: Select all   Expand viewCollapse view
tDoc=ThisComponent
tCC=tDoc.CurrentController
tNullSel=tDoc.CreateInstance("com.sun.star.sheet.SheetCellRanges")
tCC.Select(tNullSel)


Editing: I think I found the post by JohnSUN: https://forum.openoffice.org/en/forum/v ... 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.
On Windows 10: LibreOffice 5.4.2 and older versions, PortableOpenOffice 4.1.3 and older, StarOffice 5.2
---
Maybe we might! (Create a powerful UFO: United Free Office)
Lupp from München
User avatar
Lupp
Volunteer
 
Posts: 1522
Joined: Sat May 31, 2014 7:05 pm

Re: [Solved] How to get the Current Cell or Current Sheet

Postby antekg » Fri Nov 17, 2017 10:42 pm

Thank you Lupp.
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)
User avatar
antekg
 
Posts: 14
Joined: Sat Oct 17, 2009 10:03 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: Sool and 8 guests