[英]Writing Pandas Data Frame live to Excel file (.XLSX) using xlwings
我假设您不太关心速度,因为更新将实时发生并且对用户可见。 我能想到实现这个目标的方法是使用win32 apis for com对象,在Windows上通过win32com
包提供。 为了与其他对象通信,我们通常需要win32com.client
包。
使用这个,写一个开放的excel书是相当简单的:
import win32com.client as win32
filename = "book.xlsx"
# Get a handle to excel:
excel = win32.gencache.EnsureDispatch('Excel.Application')
# Find open workbook with "filename" (which is the base name only)
wb = excel.Workbooks(filename)
# Set active sheet
ws = wb.Worksheets(1)
# We can access a single cell with "Cells":
ws.Cells(1,1).Value = "A1"
# Or multiple cells with a "Range" (note the strange tuple format of values)
ws.Range("C1:C3").Value =[("C1",), ("C2",), ("C3",)]
这个例子应该很简单,可以用来将你的pandas
数据写入excel。 但是,它需要您“手动”循环遍历不同的单元格并将它们写入Excel文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.