86 lines
1.1 KiB
Markdown
86 lines
1.1 KiB
Markdown
|
+++
|
||
|
title = "Celdas y rangos"
|
||
|
weight = 3
|
||
|
+++
|
||
|
|
||
|
#### Trabajar con celdas y rangos
|
||
|
|
||
|
### selection
|
||
|
|
||
|
Referencia por selección actual.
|
||
|
|
||
|
```python
|
||
|
seleccion = app.selection
|
||
|
app.debug(seleccion)
|
||
|
```
|
||
|
|
||
|
```
|
||
|
20/08/2022 15:32:36 - DEBUG - Cell: $Sheet1.$A$2
|
||
|
20/08/2022 15:32:39 - DEBUG - Range: $Sheet1.$C$8:$D$11
|
||
|
```
|
||
|
|
||
|
### address
|
||
|
|
||
|
Referencia por dirección.
|
||
|
|
||
|
```python
|
||
|
hoja = app.active_sheet
|
||
|
celda = hoja['A1']
|
||
|
rango = hoja['C10:D15']
|
||
|
|
||
|
app.debug(celda)
|
||
|
app.debug(rango)
|
||
|
```
|
||
|
|
||
|
|
||
|
### position
|
||
|
|
||
|
Referencia por posición.
|
||
|
|
||
|
Para celdas: `HOJA[fila,columna]`
|
||
|
|
||
|
Para rangos: `HOJA[fila_inicial:fila_final, columna_inicial:columna_final]`
|
||
|
|
||
|
|
||
|
```python
|
||
|
hoja = app.active_sheet
|
||
|
|
||
|
# ~ Cell A10
|
||
|
celda = hoja[9,0]
|
||
|
|
||
|
# ~ Range A1:C10
|
||
|
rango = hoja[0:10,0:3]
|
||
|
```
|
||
|
|
||
|
|
||
|
### iter
|
||
|
|
||
|
Iterar cada celda de un rango.
|
||
|
|
||
|
```python
|
||
|
hoja = app.active_sheet
|
||
|
rango = hoja['B10:C15']
|
||
|
|
||
|
for celda in rango:
|
||
|
app.debug(celda)
|
||
|
```
|
||
|
|
||
|
|
||
|
### contains
|
||
|
|
||
|
Verificar si un rango esta dentro de otro.
|
||
|
|
||
|
```python
|
||
|
hoja = app.active_sheet
|
||
|
|
||
|
celda = hoja['C5']
|
||
|
rango = hoja['A1:E10']
|
||
|
|
||
|
resultado = celda in rango
|
||
|
app.debug(resultado)
|
||
|
|
||
|
celda = hoja['C50']
|
||
|
resultado = celda in rango
|
||
|
app.debug(resultado)
|
||
|
```
|