Примеры макросов Acell-Диапазоны

Получить ячейку по имени


#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import uno
from com.sun.star.awt.MessageBoxType import INFOBOX
from com.sun.star.awt.MessageBoxButtons import BUTTONS_YES_NO_CANCEL, DEFAULT_BUTTON_YES

def msgbox(msg=None, title=None):
   if msg is None:
       msg = "HELLO WORLD"
   else:
       msg = msg

   if title is None:
       title = "ТЕСТОВОЕ ДИАЛОГОВОЕ ОКНО"
   else:
       title = title

   ctx = uno.getComponentContext()
   smgr = ctx.getServiceManager()
   tk = smgr.createInstance("com.sun.star.awt.Toolkit")
   dtp = smgr.createInstance("com.sun.star.frame.Desktop")
   frame = dtp.getCurrentFrame()
   win = frame.getComponentWindow()
   mtyp = INFOBOX
   btn = BUTTONS_YES_NO_CANCEL + DEFAULT_BUTTON_YES
   mb = tk.createMessageBox(win, mtyp, btn, title, msg)

   return mb.execute()

def get_cell_by_name():
   cell_name = "A1"

   doc = XSCRIPTCONTEXT.getDocument()
   sheet = doc.CurrentController.ActiveSheet
   cell = sheet[cell_name]

   msgbox(
               title="Информация",
               msg=f"Ячейка по имени: {cell_name}\nполученна: {cell.AbsoluteName}"
   )


Получить ячейку по положению


#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import uno
from com.sun.star.awt.MessageBoxType import INFOBOX
from com.sun.star.awt.MessageBoxButtons import BUTTONS_YES_NO_CANCEL, DEFAULT_BUTTON_YES

def msgbox(msg=None, title=None):
   if msg is None:
       msg = "HELLO WORLD"
   else:
       msg = msg

   if title is None:
       title = "ТЕСТОВОЕ ДИАЛОГОВОЕ ОКНО"
   else:
       title = title

   ctx = uno.getComponentContext()
   smgr = ctx.getServiceManager()
   tk = smgr.createInstance("com.sun.star.awt.Toolkit")
   dtp = smgr.createInstance("com.sun.star.frame.Desktop")
   frame = dtp.getCurrentFrame()
   win = frame.getComponentWindow()
   mtyp = INFOBOX
   btn = BUTTONS_YES_NO_CANCEL + DEFAULT_BUTTON_YES
   mb = tk.createMessageBox(win, mtyp, btn, title, msg)

   return mb.execute()

def get_cell_by_position():
   row = 5
   column = 2

   doc = XSCRIPTCONTEXT.getDocument()
   sheet = doc.CurrentController.ActiveSheet
   cell = sheet[row, column]

   msgbox(
           title="Информация",
           msg=f"Ячейка по положению: row-{row}, column-{column}\nполученна: {cell.AbsoluteName}"
   )