Files
Neil Roberts b991ec6042 tdf#173293 Use InvocationHelper in ooo.vba.excel.Application
ScVbaApplication now contains a comphelper::InvocationHelper member
which it forwards methods and properties to when ScVbaSWFunction doesn’t
recognise them. This makes it possible to access methods such as
getSelection when via the XInvocation such as when accessing the object
via pyuno.

Change-Id: I1481d4f2e613037ae9283bd86844bd4d805cd2bf
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/210131
Tested-by: Jenkins
Reviewed-by: Neil Roberts <nroberts@libreoffice.org>
2026-09-25 10:39:30 +02:00

68 lines
2.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
import unittest
from org.libreoffice.unotest import UnoInProcess
from com.sun.star.awt import Toolkit
# Tests that we can access ooo.vba.excel.Application from Python. See tdf#173293.
class VbaApplication(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls._uno = UnoInProcess()
cls._uno.setUp()
cls.xContext = cls._uno.getContext()
cls.xDoc = cls._uno.openEmptyCalcDoc()
cls.xSheet = cls.xDoc.getSheets()[0]
# This is needed for the VBA Application to find the doc
cls.xDoc.createInstance("ooo.vba.VBAGlobals")
xServiceManager = cls.xContext.getServiceManager()
cls.xApplication = xServiceManager.createInstanceWithContext(
"ooo.vba.excel.Application", cls.xContext)
@classmethod
def tearDownClass(cls):
cls.xApplication = None
cls.xSheet = None
cls.xDoc.dispose()
cls.xDoc = None
cls.xContext = None
cls._uno.tearDown()
def testSelection(self):
# Tests that we can access the Selection property
# Select a square of 10×10 cells in the topleft
xController = self.xDoc.getCurrentController()
xRange = self.xSheet.getCellRangeByName("A1:J10")
xController.select(xRange)
# Use the VBA API to fill in the selection
self.xApplication.Selection.Value = "x"
# Check that the values were filled in
self.assertEqual(xRange.getCellByPosition(0, 0).getString(), "x")
self.assertEqual(xRange.getCellByPosition(9, 0).getString(), "x")
self.assertEqual(xRange.getCellByPosition(0, 9).getString(), "x")
self.assertEqual(xRange.getCellByPosition(9, 9).getString(), "x")
def testFunction(self):
# Tests that we can call a function
self.assertEqual(int(self.xApplication.CentimetersToPoints(1)), 28)
def testWorksheetFunction(self):
# Tests that we can call a dynamic function via XInvocation
self.assertEqual(self.xApplication.Concat("one", " ", "potato"), "one potato")
# vim: set shiftwidth=4 softtabstop=4 expandtab: