```python
'''
Descripttion:
version: 请写项目版本
Author: @cdm
Date: 2021-12-30 11:07:51
LastEditors: @cdm
LastEditTime: 2021-12-31 13:50:37
No pains no gains
'''
import threading
import tkinter
from tkinter import filedialog, scrolledtext, END
from openpyxl import Workbook,load_workbook
from openpyxl.styles import *import os
import warnings# file_name()###############################################################################
class DirDialog:def __init__(self):self.fileList = []self.result = ""mac = tkinter.Tk()  # 初始化Tk()创建Mac窗口对象mac.title('excel2Interface')mac.geometry("600x500+22+83")self.label3 = tkinter.Label(mac, text="一键转换excel成为interface格式, Civil制作")self.label3.place(relx=0.05, rely=0.01)self.label = tkinter.Label(mac, text="当前选择路径")self.label.place(relx = 0.1, rely = 0.8)self.button1 = tkinter.Button(mac, text="选择", command=self.selectDir)self.button1.place(relx=0.8, rely=0.8)self.label1 = tkinter.Label(mac, text="文件保存路径")self.label1.place(relx=0.1, rely=0.9)self.editor1 = tkinter.Entry(mac, bd=1, width=40)self.editor1.place(relx=0.3, rely=0.9)self.buttonOut = tkinter.Button(mac, text="选择保存地址", command=self.saveDir)self.buttonOut.place(relx=0.8, rely=0.9)self.button2 = tkinter.Button(mac, text="开始转换", command=self.startParseExcel)self.button2.place(relx=0.9, rely=0.8)self.editor = tkinter.Entry(mac,bd = 1, width=40)self.editor.place(relx = 0.3, rely = 0.8)self.log = scrolledtext.ScrolledText(width=60,height=20,)self.log.place(relx = 0.1, rely = 0.1)mac.mainloop()def saveDir(self):folderpath = tkinter.filedialog.askdirectory()self.editor1.insert(0 ,folderpath)def selectDir(self):folderpath = tkinter.filedialog.askdirectory()self.file_name(folderpath)self.editor.insert(0 ,folderpath)self.editor1.insert(0, folderpath)def startThread(self):t1 = threading.Thread(self.startParseExcel())t1.start()def startParseExcel(self):if self.editor1.get() == "":self.log.insert('end', "输出文件不能为空")# 第一次打开清空下with open(self.editor1.get() + "/data.ts", 'w+') as f:f.truncate()for file in self.fileList:# if not os.access(file, os.R_OK):#     self.log.insert("end", "%s表格已被打开,转换失败\n" % file)#     self.log.see(END);#     continueself.parseExcel(file);self.log.insert("end", "开始转换%s表格\n"%file)def saveJson(self, json):with open(self.editor1.get() + "/data.ts", 'a+', encoding='utf-8') as fs:fs.write(json)self.log.insert("end", "转换完毕\n")self.log.see(END);def parseExcel(self, file):# 开始转换warnings.filterwarnings('ignore')print(file);wb = load_workbook(self.editor.get() + "/" + file)book = wb.activeinterfaceName = os.path.splitext(file)[0]type_str = '\n\n export interface %sCfg {\n'%interfaceName;note = "";for row in book.iter_rows(min_row=2, max_col=book.max_column, max_row=2):for idx, cell in enumerate(row):# print(row1)if cell.value.endswith(".p"):type_str += "\t" + cell.value[0: -2];elif cell.value.endswith(')'):type_str += "\t" + cell.value[1: -1];else:type_str += "\t%s: " % cell.value;note = book.cell(row=3, column=idx + 1).value;if note == "numberArr":note = "number[]"elif note == 'stringArr':note = "string[]"elif note.startswith("function"):note = "string";type_str += note + ";";type_str += " //" + book.cell(row=1, column=idx + 1).value;type_str += '\n';if idx + 1 == book.max_column:type_str += "}"print(type_str)# self.result += type_str;self.saveJson(type_str);def file_name(self, file_dir="./"):self.fileList = []for root, dirs, files in os.walk(file_dir):for file in files:res = os.path.splitext(file);if res[1].endswith('.xlsx'):self.log.insert("end", "扫描出文件{fileName}\n".format(fileName = file))self.fileList.append(file)self.log.see(END);# print(file)  # 当前路径下所有非目录子文件
###############################################################################
if __name__ == '__main__':app = DirDialog()

需要自取

python自动转换excel格式相关推荐

  1. python自动汇总表格_用Python自动生成Excel报表

    作者 / 来源:林骥(ID:linjiwx) 01 安装和导入模块 以 Python 中的 openpyxl 模块为例,它能够读取和修改 Excel 文件,如果你还没有安装,可以通过以下命令进行安装: ...

  2. 用Python自动生成Excel报表

    在日常工作中,可能会有一些重复无聊的任务,比如说,从 Excel 或数据库中收集一些数据,设置相应的数据格式并做成报表. 类似这种重复无聊的任务,我们完全可以交给 Python 去自动完成,只要第一次 ...

  3. 将整数k转换成实数python表达式_在混合类型表达式中python自动转换intlongfloat例如.ppt...

    在混合类型表达式中python自动转换intlongfloat例如 空位:格式指示符,描述了填入的值的输出形式. %. 类型字符: 宽度:用多少位置显示数值. 省略或指定为0:根据值的实际长度显示. ...

  4. python自动读取excel文件邮箱列表,自动批量发送邮件项目(附使用方法+代码)

    python自动发送邮件项目 项目简介 使用方法 项目结构 完整项目代码 结语 项目简介 该项目功能是利用python自动读取excel文件中的邮箱列表,并批量发送邮件到目标邮箱,进行客户挖掘的.该项 ...

  5. vba html 转化为 xlsx,使用VBA批量转换Excel格式,由.xls转换成.xlsx

    问题分析: Excel2007以前的格式是.xls,之后的格式是.xlsx.打开单独的一个Excel文档,使用"另存为"功能,可以很轻松的转换格式.但是面对几百个Excel表这样就 ...

  6. python导入word转换的html,python如何转换word格式、读取word内容、转成html

    # python如何转换word格式.读取word内容.转成html? import docx from win32com import client as wc # 首先将doc转换成docx wo ...

  7. Gox语言自动转换Excel文件为CSV格式-GX35.2

    本文继续介绍Gox语言中如何利用内置的github.com/360EntSecGroup-Skylar/excelize包来实现Excel文件的操作,例子中演示的是如何将Excel文件自动转换为CSV ...

  8. 如何用手机打开dcm格式图片_实现原始Dicom自动转换BIDS格式 ——Heudiconv

    Python神经影像社区日趋完善,Linux shell搭配Python的神经影像工具开发方式越来越受追捧,催生出fMRIPrep.fMRIDenoise.Nipype.Nilearn.PyMVPA等 ...

  9. bundle打包自动转换tiff格式的处理方法

    png图片如果用了@2x .@3x会自动转换成tiff格式的图片.设置不转换的方法是 在bundle的target中 Build Settings 里的 COMBINE_HIDPI_IMAGES 设置 ...

最新文章

  1. 从思维导图学习操作系统(一)
  2. Codeforces 1005D Polycarp and Div 3
  3. 最新php常用函数200个,180多个PHP常用函数总结
  4. python标准库之zipfile
  5. 读者福利:复盘2018上半年精选文章,还有礼品等着你!
  6. Linux工作笔记032---Centos7.3 kill杀掉不用的进程_查看某个进程_某个进程占用的cpu,内存情况
  7. p51 thinkpad 拆解_ThinkPad P51值得买吗?联想ThinkPad P51移动工作站图解评测
  8. c语言二级考试南开100,南开100题WORD加答案(二级C语言考试)
  9. 中国历史上十大无名英雄
  10. 小 Biu 的旅行(dfs)
  11. SEGMENT_VARIABLE什么意思?
  12. 深入理解空洞卷积:优点以及存在问题
  13. Github域名解析连接慢问题
  14. http隧道、https、SSL层、http代理、在线代理、socks代理区别
  15. bzoj4668: 冷战
  16. 生成MySQL数据库表报错:Error Code: 1022. Can't write; duplicate key in table '#sql-e88_23'
  17. vue中MVVM模型
  18. [附源码]计算机毕业设计JAVA校园二手交易平台的设计
  19. bmc控制卡_BMC+IKVM远程管理模块
  20. 第五篇Data Feeds(3)使用Pandas加载数据

热门文章

  1. [转fym0121] oracle instant client odbc安装
  2. 蔬菜干行业调研报告 - 市场现状分析与发展前景预测
  3. 支付系统中如何应用加密方式的
  4. 统计自然语言处理梳理二:句法分析
  5. 读《一个程序员的奋斗史》有感
  6. 加拿大PCI GXL地理成像加速器-地理国情大显身手
  7. 算法:求小于N的最大素数
  8. Spark——RDD操作详解
  9. Git 出错error: Pulling is not possible because you have unmerged files
  10. 基于Ventoy制作单个U盘引导Windows+Linux+黑苹果macOS