【发布时间】:2021-10-24 01:57:13
【问题描述】:
您需要在没有 win32com 的主机上将 xls 转换为 xlsx。我试过这段代码:
import xlrd, os
from openpyxl.workbook import Workbook
def open_xls_as_xlsx(filename):
# first open using xlrd
book = xlrd.open_workbook( filename =filename)
index = 0
nrows, ncols = 0, 0
while nrows * ncols == 0:
sheet = book.sheet_by_index(index)
nrows = sheet.nrows
ncols = sheet.ncols
index += 1
# prepare a xlsx sheet
book1 = Workbook()
sheet1 = book1.active()
for row in range(1, nrows):
for col in range(1, ncols):
sheet1.cell(row=row, column=col).value = sheet.cell_value(row, col)
return book1
open_xls_as_xlsx(os.getcwd() + '/Расписание_1-4_курсов_с_01.04_по_05.07.2021_(2_поток).xls').save(filename = 'path_to_file.xlsx')
但出现错误:
'Worksheet' object is not callable
或者我可以做点别的吗?请帮忙
【问题讨论】:
-
请edit您的问题并发布错误和回溯的全文。不要发布文字图片。
标签: python excel file converters