Macros/Basic/Calc/Hojas

From The Document Foundation Wiki
Jump to: navigation, search
This page is a translated version of the page Macros/Basic/Calc/Sheets and the translation is 100% complete.

Other languages:
English • ‎español

Return to Index

Hojas

Todas las hojas

1 doc = ThisComponent
2 
3 For Each sheet In doc.Sheets
4     MsgBox sheet.Name
5 Next

Todos los nombres

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

Acceder por nombre

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

Acceder por índice

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

Verificar si existe

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

Contar

1 sheets = ThisComponent.Sheets
2 Msgbox sheets.Count

Acceder a la hoja activa

1 doc = ThisComponent
2 sheet = doc.CurrentController.ActiveSheet

Establecer la hoja activa

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

Insertar por nombre

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

Insertar como objeto

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

Borrar

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

Mover

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

Copiar en el mismo archivo

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

Copiar desde otro archivo

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

Reemplazar

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

1 doc = ThisComponent
2 sheets = doc.Sheets
3 
4 sheet = doc.createInstance("com.sun.star.sheet.Spreadsheet")
5 sheets.replaceByName("Sheet1", sheet)

Renombrar

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

Visibilidad

1 sheet = sheets.getByName("Sheet1")
2 sheet.IsVisible = False
3 
4 'Or
5 
6 sheet.IsVisible = True

Establecer contraseña

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

Quitar contraseña

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

Color

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