

These commands apply to the current document, open a new document, or close the application. After the run, all cell values from all sheets are shown below.Learn to use the File Menu. I will concatenate each cell value in a formatted way and show it in a message box, which is an easier way to read and display. Select Case my_cell.TypeĬase .CellContentType.VALUEĬase .CellContentType.TEXT The switch-case block can take care of the type at runtime, and you get the values you need. We would use the snippet to access the cell values in this example. LibreOffice provides a list of enums for Cell.Type as below: .CellContentType.VALUE ' Used for cells containing numbersĬom.TEXT ' Used for cells containing charactersĬom.EMPTY ' Used for empty cellsĬom.FORMULA ' Used for cells containing formula If you put a number on a cell, it becomes number type if you put characters on it, it becomes type text. Each cell is defined by its content type. Note that the first argument of getCellByPosition is a column and then a row.Īfter getting the cell object my_cell set, we have to access its contents. getByName("Sheet1").getCellByPosition(col,row) So, the same statement above can also be written as below: my_cell = ThisComponent.Sheets. Tip: If you think accessing Sheet with a subscript is difficult, you can also use the sheet name (e.g. A typical way of accessing a cell is as below: my_cell = ThisComponent.Sheets(subscript).getCellByPosition(col,row) Once we get a handle on sheet using Sheets(subscript), we can access each cell using getCellByPosition method.

Note that the subscript starts at zero in Basic. To access them, we have to use subscripts like Sheets(0), Sheets(1) so on. All the sheets are assigned to object my_sheets as an array. Once this is done, the Sheets collection is assigned to my_sheets object to access all the workbook sheets. Set my_doc using ThisComponent which refers to the current active Calc workbook. First, we will declare 3 Objects to define the Calc workbook, a collection of sheets and a cell.
