Makros/Basis/Calc/Tabellenblätter

    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

    Tabellenblätter

    alle Tabellenblätter

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

    alle Namen

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

    über den Namen holen

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

    über den Index holen

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

    überprüfen auf Vorhandensein

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

    zählen

    sheets = ThisComponent.Sheets
    Msgbox sheets.Count

    aktives Tabellenblatt holen

    doc = ThisComponent
    sheet = doc.CurrentController.ActiveSheet

    Tabellenblatt aktiv setzen

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

    über Namen einfügen

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

    als Objekt einfügen

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

    Löschen

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

    Verschieben

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

    in dieselbe Datei kopieren

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

    aus einer anderen Datei kopieren

    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)

    Ersetzen

    ACHTUNG: Ersetze das Tabellenblatt NAME mit einem leeren Blatt.

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

    Umbenennen

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

    Sichtbarkeit

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

    Passwort setzen

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

    Passwort entfernen

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

    Tab Farbe

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