我试图找出如何在写入后使用 xlwings 保存并关闭现有工作簿:
import xlwings as xw
list_of_values = [1, 2, 3]
workbook_path = 'abc.xlsx'
wb = xw.Book(workbook_path)
ws = wb.sheets['sheet1']
ws.range('E35').value = list_of_values
wb.save()
wb.close()
Run Code Online (Sandbox Code Playgroud)
当我到达 时wb.save(workbook_path)
,出现提示:“此位置已存在名为 abc.xlsx 的文件”。你想更换它吗?
我想立即覆盖该文件而不出现提示。根据文档,wb.save()
应该自动覆盖(参见: https: //docs.xlwings.org/en/v0.6.4/api.html)。我也试过了wb.save(workbook_path)
,但是还是出现弹窗。
感谢对此的任何帮助。
ps - 我基本上试图将数据写入预先格式化的 Excel 工作表中。如果有其他方法可以保留格式,我很乐意尝试。我已经尝试过这个,但它抛出一个错误if newCell
:Easy write formatted Excel from Python: Start with Excel formatted, use it in Python, and regenerate Excel from Python
我正在尝试使用async从URL列表(由ID标识)中获取HTML。我需要使用代理。
我正在尝试将aiohttp与以下代理一起使用:
import asyncio
import aiohttp
from bs4 import BeautifulSoup
ids = ['1', '2', '3']
async def fetch(session, id):
print('Starting {}'.format(id))
url = f'https://www.testing.com/{id}'
async with session.get(url) as response:
return BeautifulSoup(await response.content, 'html.parser')
async def main(id):
proxydict = {"http": 'xx.xx.x.xx:xxxx', "https": 'xx.xx.xxx.xx:xxxx'}
async with aiohttp.ClientSession(proxy=proxydict) as session:
soup = await fetch(session, id)
if 'No record found' in soup.title.text:
print(id, 'na')
loop = asyncio.get_event_loop()
future = [asyncio.ensure_future(main(id)) for id in ids]
loop.run_until_complete(asyncio.wait(future))
Run Code Online (Sandbox Code Playgroud)
根据这里的问题:https : //github.com/aio-libs/aiohttp/pull/2582,似乎ClientSession(proxy=proxydict)
应该工作。
但是,我收到一个错误 "__init__() …