Macros/Basic/Calc/Hojas

    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

    Hojas

    Todas las hojas

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

    Todos los nombres

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

    Acceder por nombre

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

    Acceder por índice

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

    Verificar si existe

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

    Contar

    sheets = ThisComponent.Sheets
    Msgbox sheets.Count

    Acceder a la hoja activa

    doc = ThisComponent
    sheet = doc.CurrentController.ActiveSheet

    Establecer la hoja activa

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

    Insertar por nombre

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

    Insertar como objeto

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

    Borrar

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

    Mover

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

    Copiar en el mismo archivo

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

    Copiar desde otro archivo

    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)

    Reemplazar

    PRECAUCIÓN: Reemplazará la hoja con NOMBRE con una hoja limpia.

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

    Renombrar

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

    Visibilidad

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

    Establecer contraseña

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

    Quitar contraseña

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

    Colorear pestaña

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