I am trying to create a list of shares and to get the price in turn I need to paste it in the cell of B2 and B3 the values. I am not finding the way that they do not overwrite.
import xlwings as xw
import time
#Data Source
import yfinance as yf
wb = xw.Book('EPGB V3.3.2 FE-AB - Python.xlsb')
sht1 = wb.sheets['Dolar']
while True:
try:
tickers = ['GGAL','BMA']
for ticker in tickers:
ticker_yahoo = yf.Ticker(ticker)
data = ticker_yahoo.history()
last_quote = data['Close'].iloc[-1]
last_quote_decimals = "{:.2f}".format(last_quote)
print(ticker, last_quote_decimals)
sht1.range('B1:B3').value = last_quote_decimals
time.sleep(10)
except:
print('Hubo un error al actualizar excel')
Get the list of values and paste it into the excel
You need to write one value [last quote] to one cell.
Change
sht1.range('B1:B3').value = last_quote_decimals
to
sht1.range(f'B{tickers.index(ticker)+2}').value = last_quote_decimals
import xlwings as xw
import time
#Data Source
import yfinance as yf
wb = xw.Book('EPGB V3.3.2 FE-AB - Python.xlsb')
sht1 = wb.sheets['Dolar']
while True:
try:
tickers = ['GGAL','BMA']
for ticker in tickers:
ticker_yahoo = yf.Ticker(ticker)
data = ticker_yahoo.history()
last_quote = data['Close'].iloc[-1]
last_quote_decimals = "{:.2f}".format(last_quote)
print(ticker, last_quote_decimals)
# sht1.range('B1:B3').value = last_quote_decimals
sht1.range(f'B{tickers.index(ticker)+2}').value = last_quote_decimals
time.sleep(10)
except:
print('Hubo un error al actualizar excel')