I need to write a script in Lua that can open the required file for LibreOfficeCalc, find the required sheet in it, and count the number of cells in the working range. I was able to get the desired sheet this way:
self._myLOCdoc = luacom.CreateObject("com.sun.star.ServiceManager")
self._desktop = self._myLOCdoc:createInstance("com.sun.star.frame.Desktop")
self._workbook = self._desktop:loadComponentFromURL("file:///" .. file_path, "_blank", 0, {ReadOnly = false})
self._worksheet = _workbook:getSheets():getByIndex(0)
local sheetName = self._worksheet:getName() --Check sheet name
--Trying to count cells
local cursor = self._worksheet:createCursor()
cursor:gotoEndOfUsedArea(true)
--cursor:gotoStartOfUsedArea(false)
local nCountCells = cursor:getRows():getCount() * cursor:getColumns():getCount()
local RCount = cursor:getRows():getCount() --always 1
local CCount = cursor:getColumns():getCount() --always 1
Why do I always only get one row and one column? How to do it right?
I am attaching my document with which I am experimenting.
TestFile.ods (11.6 KB)