编程语言
首页 > 编程语言> > python中如何把xlsx、xls文件转换为txt文件?安排

python中如何把xlsx、xls文件转换为txt文件?安排

作者:互联网

# _*_ coding: utf-8 _*_
"""
Time:     2021/12/30 16:45
Author:   xiang_qu@huacenav.com
Version:  V1.0
File:   change2txt.py
Describe:  xls文件转换成txt
"""

import pandas as pd

def change2txt(excel_name,sheet_name,txt_name,sep):
    df = pd.read_excel(excel_name, sheet_name , header=None)
    df.to_csv(txt_name, header=None, sep=sep, index=False)		# 写入,逗号分隔
    print('文件转换成功!')

if __name__ == '__main__':
    excel_name = '数据.xlsx'
    sheet_name = 'sheet'
    txt_name = 'gnss.txt'
    sep = ','
    change2txt(excel_name,sheet_name,txt_name,sep)

 

标签:__,文件,sheet,name,sep,python,excel,xlsx,txt
来源: https://blog.csdn.net/fairytale520/article/details/122250227