pip install openpyxl
注:可以使用相对路径
也可以使用绝对路径
import openpyxl
wb1=openpyxl.load_workbook("E:\\PythonProject\\programming4\\test.xlsx")
sheet1=wb1["表2"]
sheet1.append(['0010','鬼谷子',17,'2020/12/9',20,20,20])
wb1.save("E:\\PythonProject\\programming4\\test.xlsx")
方法一
sheet1['A9']='0010'
wb1.save("E:\\PythonProject\\programming4\\test.xlsx")
sheet1.cell(row = 9,column = 2,value='test')
wb1.save("E:\\PythonProject\\programming4\\test.xlsx")
sheet1.merge_cells(start_row = 2,start_column = 1,end_row = 2,end_column = 2)
a=['物理',24,25,26]
for i in range(1,5):
sheet1['H'+str(i)]=a[i-1]
wb1.save("E:\\PythonProject\\programming4\\test.xlsx")
sheet1=wb1["表1"]
sheet1['H2']="=SUM(E2:G2)"
注:可以用相对路径
也可以用绝对路径
wb1.save("E:\\PythonProject\\programming4\\test.xlsx")
import openpyxl
wb2 = openpyxl.Workbook()
wb2.save("E:\\PythonProject\\programming4\\test2.xlsx")
ws = wb2.active #默认选用当前表
ws.title = '表4' #设定sheet的名字
ws1 = wb.create_sheet() # 默认在最后插入
# 或者
ws2 = wb.create_sheet(0) #在开头插入