[Solved] Inserting a new sheet with properties

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
sokolowitzky
Posts: 103
Joined: Mon Sep 15, 2014 7:34 pm

[Solved] Inserting a new sheet with properties

Post by sokolowitzky »

Hi,

I need to insert an invisible sheet into a calc spreadsheet. But the properties that I have written are ignored by "InsertNewByName" command.
Is there any possibility to create a new calc sheet with properties, like an invisible sheet.

The reason why I need this is, there is a short noticeable period between the moment when basic creates a new sheet and the moment when it sets the sheet invisible. Is it possible to insert a sheet with properties?

Code: Select all

Function aNewSheet
  Dim oSheets       
  oSheets = ThisComponent.Sheets
  sCount = oSheets.GetCount
  nsnumber = sCount + 1
  nsname = "Sheet" & nsnumber
  thenextsheetname = nsname
 
dim oProps(0) as New com.sun.star.beans.PropertyValue
oProps(0).Name = "Visible"'.IsVisible(False)
oProps(0).Value = False
  oSheets.insertNewByName(thenextsheetname, sCount + 1, oProps)
End Function
Last edited by sokolowitzky on Sat May 20, 2023 10:57 am, edited 1 time in total.
Win10-OpenOffice 4.1/LibreOffice 7.4
JeJe
Volunteer
Posts: 2784
Joined: Wed Mar 09, 2016 2:40 pm

Re: Inserting a new sheet with properties

Post by JeJe »

Not unless there's another method for inserting sheets

https://www.openoffice.org/api/docs/co ... NewByName

You need to use lockcontrollers and hide it.

Code: Select all

Function aNewSheet
  Dim oSheets       
  oSheets = ThisComponent.Sheets

  sCount = oSheets.GetCount
  nsnumber = sCount + 1
  nsname = "Sheet" & nsnumber
  thenextsheetname = nsname
 
thiscomponent.lockcontrollers
  oSheets.insertNewByName(thenextsheetname, sCount + 1)
osheets(oSheets.GetCount-1).isvisible = false
thiscomponent.unlockcontrollers

End Function

Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
sokolowitzky
Posts: 103
Joined: Mon Sep 15, 2014 7:34 pm

Re: Inserting a new sheet with properties

Post by sokolowitzky »

Thank you very much.
Last edited by sokolowitzky on Sat May 27, 2023 6:27 am, edited 2 times in total.
Win10-OpenOffice 4.1/LibreOffice 7.4
JeJe
Volunteer
Posts: 2784
Joined: Wed Mar 09, 2016 2:40 pm

Re: Inserting a new sheet with properties

Post by JeJe »

The other method of inserting sheets is insertbyname but there's an error with isvisible before its inserted.

I don't see anything showing on my machine with setting isvisible to false afterwards without lock controllers - but your machine may be different

Code: Select all


doc = ThisComponent
sheet = doc.createInstance("com.sun.star.sheet.Spreadsheet")
'sheet.isvisible = false 'runtime exception
sheets = thiscomponent.sheets
sheets.insertByName("New_Sheet2", sheet)
sheet.isvisible = false

Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply