Macro/Basic/Calc/Fogli

    From The Document Foundation Wiki
    This page is a translated version of the page Macros/Basic/Calc/Sheets and the translation is 100% complete.
    Other languages:

    Return to Index

    Fogli

    Tutti i fogli

    doc = ThisComponent
    
    For Each sheet In doc.Sheets
        MsgBox sheet.Name
    Next

    Tutti i nomi

    sheets = ThisComponent.Sheets
    MsgBox Join(sheets.ElementNames, Chr(13))

    Seleziona per nome

    sheets = ThisComponent.Sheets
    sheet = sheets.getByName("Sheet1")

    Seleziona per indice

    sheets = ThisComponent.Sheets
    sheet = sheets.getByIndex(1)

    Verifica se esiste

    sheets = ThisComponent.Sheets
    exists = sheets.hasByName("Sheet1")

    Conta

    sheets = ThisComponent.Sheets
    Msgbox sheets.Count

    Ottenere il foglio attivo

    doc = ThisComponent
    sheet = doc.CurrentController.ActiveSheet

    Impostare il foglio attivo

    doc = ThisComponent
    sheet = doc.Sheets.getByIndex(1)
    doc.CurrentController.setActiveSheet(sheet)

    Inserire in base al nome

    sheets = ThisComponent.Sheets
    position = 0
    sheets.insertNewByName("New_Sheet", position)

    Inserire come oggetto

    doc = ThisComponent
    sheet = doc.createInstance("com.sun.star.sheet.Spreadsheet")
    sheets.insertByName("New_Sheet_Obj", sheet)

    Eliminare

    sheets = ThisComponent.Sheets
    sheets.removeByName("Sheet1")

    Spostare

    sheets = ThisComponent.Sheets
    position = 0
    sheets.moveByName("Sheet1", position)

    Copiare nello stesso file

    sheets = ThisComponent.Sheets
    position = 0
    sheets.copyByName("Sheet1", "Copy_Sheet", position)

    Copiare da un altro file

    sheets = ThisComponent.Sheets
    path = ConvertToUrl("/home/USER/Source_File.ods")
    doc_source = StarDesktop.loadComponentFromURL(path, "default", 0, Array())
    position = 0
    
    sheets.importSheet(doc_source, "Sheet1", position)

    Sostituire

    ATTENZIONE: Sostituisce il foglio NAME con uno vuoto.

    doc = ThisComponent
    sheets = doc.Sheets
    
    sheet = doc.createInstance("com.sun.star.sheet.Spreadsheet")
    sheets.replaceByName("Sheet1", sheet)

    Rinominare

    sheet = sheets.getByName("Sheet1")
    sheet.Name = "New_Name"

    Visibilità

    sheet = sheets.getByName("Sheet1")
    sheet.IsVisible = False
    
    'Or
    
    sheet.IsVisible = True

    Impostare una password

    sheet = sheets.getByName("Sheet1")
    sheet.Protect("letmein")

    Rimuovere la password

    sheet = sheets.getByName("Sheet1")
    sheet.unProtect("letmein")

    Colore della linguetta

    sheet = sheets.getByName("New_Name")
    sheet.TabColor = RGB(255, 0, 0)