我写了一个python代码来获取字符串输出,如下所示。
a = "First "
b = "Second"
c = a+b
每次运行该程序时,我都需要将c的值保存在一个excel文件中。该怎么办?
答案 0 :(得分:0)
from openpyxl import Workbook
a = "First "
b = "Second"
c = a+b
file_path= "temp.xlsx"
wb = Workbook()
ws = wb.active
ws.append(c)
wb.save(file_path)
答案 1 :(得分:0)
首先制作一个名为test.xlsx的excel文件 然后使用以下代码加载文件并写入文件:
from openpyxl import load_workbook
filename= 'test.xlsx'
wb = load_workbook(filename)
file = wb.active
file.append(["data"])
wb.save(filename=filename)