=========保存文件名========
import os
import xlwt
file_dir = 'd:/'
dirs = os.listdir(file_dir)
new_workbook = xlwt.Workbook()
worksheet = new_workbook.add_sheet('new_test')
n = 0
for i in dirs:
worksheet.write(n,0,i)
n+=1
new_workbook.save('file_name.xls')
"""import xlwt
workbook = xlwt.Workbook()
sheet0 = workbook.add_sheet('sheet0')
for i in range(0,300):
sheet0.write(i,0,i)
workbook.save('d:/number.xls')
"""
#新的写入方式
"""
import xlsxwriter as xw
workbook = xw.Workbook('d:/number2.xls')
sheet2 = workbook.add_worksheet('sheet2')
for i in range(0,300):
sheet2.write(i,0,i)
workbook.close()
"""
#新的追加写入的方式openpyxl
import openpyxl
workbook = openpyxl.load_workbook('test4.xlsx')
sheet0 = workbook['目录']
sheet0['B3'] = '5'
sheet0['B4'] = '6'
sheet0['B5'] = 7
sheet0['B6'] = 8
workbook.save('测试写入数据.xls')