【问题标题】:Convert a .xlsx file to .xls without losing data using Python使用 Python 将 .xlsx 文件转换为 .xls 而不会丢失数据
【发布时间】:2019-05-29 09:52:11
【问题描述】:

需要将.xlsx 文件转换为.xls

使用opepyxlwin32.com 的现有解决方案类型会导致数据丢失,一些公式依赖项以.xlsx 格式实现。

是否有任何模块将无损格式转换为.xlsx.xls

或者也许有一个用于处理.xlsx 文件的高级库?

【问题讨论】:

标签: python xlsx xls


【解决方案1】:

你可以试试:

import openpyxl
import os

# get files
os.chdir(os.path.abspath(os.path.dirname(__file__)))
pdir = <<folder path in xlsx files are>>
filelist = [filename for filename in pdir.iterdir() if filename.suffix == '.xlsx']

for filename in filelist:
    print(filename.name)

for infile in filelist:
    workbook = openpyxl.load_workbook(infile)
    outfile = f"{infile.name.split('.')[0]}.xls"
    workbook.save(outfile)

来源:https://python-forum.io/Thread-how-to-convert-xlsx-to-xls

【讨论】:

    猜你喜欢
    • 2013-05-27
    • 1970-01-01
    • 2021-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-25
    • 2011-12-30
    • 2016-06-22
    相关资源
    最近更新 更多