'How I can set a specific cell from excel in python?
I'm doing a function with python where I have to create a matrix in Excel, but for that I need to know how I can manipulate some keyboard request to specific excel cells positions in it to create this matrix with some values in this cells.
The code that I have right now it is here:
import sys
import openpyxl as opxl
def crear_menu():
menu=int(input("Elija una opción \n 1.Crear parámetros \n
2.Aplicar Dijkstra \n 3.Aplicar Kruskal \n 4.Salir"))
if menu == 1:
min_nodos()
elif menu == 2:
dijkstra()
elif menu == 3:
kruskal()
elif menu == 4:
sys.exit()
else:
print("\n ERROR: Elija una opción válida.")
crear_menu()
def crear_matriz_adyacente2(cant_nodos):
lista_nodos = []
lista_matriz = []
lista_filas = []
lista_columnas = []
libro = opxl.Workbook()
pagina = libro.active
pagina.title = "matriz_de_adyacencia"
i = 0
while(i < cant_nodos):
num = str(i+1)
nodo = str(input("Ingresar nombre del nodo " + num + ":"))
if nodo not in lista_nodos:
lista_nodos.append(nodo)
pagina.cell(row = i+2, column = 1, value = nodo)
pagina.cell(row = 1, column = i+2, value = nodo)
i += 1
elif(nodo < 0):
print("ERROR: Nodo no valido")
else:
print("Error: Nodo existente. \n Ingrese otro nombre: ")
libro.save("matriz_de_adyacencia.xlsx")
def min_nodos():
cant_nodos = int(input("Elija la cantidad de nodos a utilizar
(mínimo 6):"))
while(cant_nodos < 6):
print("ERROR: Elija mínimo 6 nodos y que sea entero positivo.")
cant_nodos = int(input("Elija la cantidad de nodos a utilizar (mínimo 6):"))
else:
crear_matriz_adyacente(cant_nodos)
Here in the red box I'm trying to do the matrix, but I don't know the best way to import a specific excel cell. I mean, I don't know if with this I'm referring to A2.
Thank you for your help.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
