赞
踩
#转换xls为xlsx文件
"""
coding:utf-8
@Software:PyCharm
"""
import pandas as pd
from pandas import DataFrame
import openpyxl
from openpyxl import workbook
import xlwt
import xlrd
import numpy as np
def xls_to_xlsx(filename):
book = xlrd.open_workbook(filename,encoding_override='gbk') #'gb2312' 或 'gbk' 或 'gb18030' 文件的encoding类型
sheet_names = book.sheet_names()
wb = openpyxl.Workbook()
for sheet_name in sheet_names:
sh = book.sheet_by_name(sheet_name)
sheet = wb.active
sheet.title = sheet_name
for row_index in range(sh.nrows):
row = sh.row_values(row_index)
sheet.append(row)
return wb
filename = "D:\demo.xls"
xl = xls_to_xlsx(filename)
xl.save("D:\demotest.xlsx")
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。