答案 0 :(得分:0)
我认为您不能这样做。例如,参见this,其中说Excel可以处理文档的副本。
要将数据帧写入Excel文件,您可以使用pandas to_excel()
方法,如下所示:
your_dataframe.to_excel(output.xlsx')
xlwt是一个使用Excel并具有更多详细信息的好模块。您可以看到this tutorial,其中有许多示例说明了如何使用它。
答案 1 :(得分:0)
我认为您不太关心速度,因为更新是实时进行的,并且对用户可见。我可以想到的方法是,通过win32com
包将win32 api用于com对象,这些对象在Windows上的Python中可用。为了与其他对象通信,我们通常需要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文档。