Es posible tener un atajo de teclado para saltar entre las divisiones de una ventana en Calc

Es muy común que cuando trabajamos en hojas de cálculo largas, con muchas filas o columnas, queremos ver diferentes partes de la tabla al mismo tiempo, para cotejar datos, explorar resultados de funciones, etc. Después de dividir la ventana en Calc (con el menú Ver > Dividir ventana), si quisiéramos usar solo el teclado y no el ratón, de manera nativa Calc no nos permite saltar entre esas divisiones (podemos llamarles panes, splits o subventanas… el nombre que quieran usar está bien porque aún no he encontrado el “oficial” en español).

Afortunadamente, dos personas crearon sendas macros, una en Basic y otra en Python, que pueden agregar a su biblioteca personal y después crear un atajo de teclado para usar cualquiera de ellas. Yo elegí el atajo Control+F10, por ejemplo.

La macro en Basic se encuentra en el sitio de Ask de LibreOffice, por si quieren echarle ojo al hilo donde se solicitó. O pueden verla aquí mismo. (Cuando obtenga el permiso de publicar la macro en Python, aquí también la pondré).

Option Explicit

Global aInfo    ' An array to store information about sheet panes.
                ' Element is an array of 10 elements. Indexes:
                ' 0:   RuntimeUID of the document;
                ' 1:   sheet index; 
                ' 2-9: column and row of the active cell at the time the macro is called for panes 0-3
Global indInfo As Long
Global iCurrInfo As Long

' lang:en
' Remembers the active cell and moves to the next window pane.
' If possible, the previously saved cell for the target pane is set as active.
' - oDoc  Spreadsheet document. If is missing then ThisComponent.
Sub JumpToNextPane(Optional ByVal oDoc As Object)
  Dim oCont As Object
  Dim nPanes As Long, currPane as Long, nextPane as Long, arr, arr2, aSh, i As Long
  Dim iSheet As Long, shInfo As String, nCol as Long, nRow as Long, sep As String, vRange
  If IsMissing(oDoc) Then oDoc=ThisComponent
  If Not HasUnoInterfaces(oDoc, "com.sun.star.sheet.XSpreadsheetDocument") Then Exit Sub
  oCont=oDoc.CurrentController
  If Not HasUnoInterfaces(oCont, "com.sun.star.sheet.XSpreadsheetView") Then Exit Sub
  
  nPanes=oCont.Count               ' Number of Panes
  If nPanes<2 Then Exit Sub
  
  arr=Split(oCont.ViewData, ";")   ' View Data: https://docs.libreoffice.org/sc/html/classScViewData.html#abb5889c04d6857f169f07e4fc15c03b8 
  iSheet=Clng(arr(1)) + 3          ' Active sheet index in arr
  shInfo=arr(iSheet)               ' Sheet info
  sep="+"                          ' Token separator: + or /
  arr2=Split(shInfo, sep)         
  If Ubound(arr2)=0 Then
    sep="/"
    arr2=Split(shInfo, sep)
  End If    
   
  currPane=Clng(arr2(6))
  If nPanes=4 Then                            ' Hori and Vert Split
     nextPane=(Clng(arr2(6))+1) Mod 4
  ElseIf arr2(2)="1" Then                     ' Vert    
     nextPane=IIf(currPane=2, 3, 2)
  Else                                        ' Hori
     nextPane=IIf(currPane=2, 0, 2)     
  End If
  arr2(6)=Cstr(nextPane)
  
  ' Look for information about the sheet in the aInfo array
  FindInfoIndex oDoc.RuntimeUID, Clng(arr(1))
  aSh=aInfo(indInfo)
  
  ' Save currpane
  ash(2+2*currPane)=Clng(arr2(0))
  ash(3+2*currPane)=Clng(arr2(1))
  
  nCol=-1
  If Not IsEmpty(ash(2+2*nextPane)) Then
    nCol=ash(2+2*nextPane)
    nRow=ash(3+2*nextPane)
  End If
  
  ' pane index in controller numbering.
  If nPanes=4 Then
    i=IIf(nextPane=1, 2, Iif(nextPane=2, 1, nextPane))
  Else
    i=IIf(nextPane<currPane, 0, 1)
  End If
  
  ' Check VisibleRange
  vRange=oCont.getByIndex(i).VisibleRange
  With vRange
  
    If nCol>=0 Then
      If nCol > .EndColumn Or nCol < .StartColumn Or nRow < .StartRow Or nRow > .EndRow Then  nCol=-1
    End With 
     
    If ncol=-1 Then
      nCol=.StartColumn
      nRow=.StartRow 
    End If
  End With  
  
  arr2(0)=Cstr(nCol)
  arr2(1)=Cstr(nRow)
      
  arr(iSheet)=Join(arr2, sep)
  oCont.restoreViewData Join(arr, ";")
End Sub

' Look for information about the sheet in the aInfo array.
' Assigns the iCurrInfo variable.
Sub FindInfoIndex(ByVal UID As String, ByVal n As Long)
  Dim aSh, i As Long
  If Not IsArray(aInfo) Then
    ReDim aInfo(99)
    indInfo=-1
    iCurrInfo=-1
  End If
    
  If iCurrInfo>=0 Then
    aSh=aInfo(iCurrInfo)
    If aSh(0)=UID And aSh(1)=n Then Exit Sub
  End If
  
  For i=0 To indInfo
    aSh=aInfo(i)
    If aSh(0)=UID And aSh(1)=n Then
      iCurrInfo=i
      Exit Sub
    End If
  Next i
    
  indInfo=indInfo+1
  If indInfo>Ubound(aInfo) Then
    ReDim Preserve aInfo(2 * Ubound(aInfo))
  End If  
  aSh=DimArray(9)
  aSh(0)=UID
  aSh(1)=n
  aInfo(indInfo)=aSh
  iCurrInfo=indInfo
End Sub

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

Acepto la Política de privacidad