Skip to content

Latest commit

 

History

History
57 lines (39 loc) · 1.58 KB

README.md

File metadata and controls

57 lines (39 loc) · 1.58 KB

Excel Tidy

PyPI version

在工作中遇到的一些需要处理的情况,编写为库,方便后续操作

openpyxl前缀的函数为基于openpyxl编写 xlwings同上

注意xlwings不支持linux,在linux上运行可能报错

使用方法 git clone https://github.com/cmacckk/exceltidy.git

安装依赖 pip install -r requirements.txt

openpyxl获取list[list, list, ...] openpyxl.workbook.Workbook openpyxl.worksheet.worksheet.Worksheet

from exceltidy.exceltidy import *

worksheet_datas, workbook, worksheet = openpyxl_get_datas_workbook_worksheet(filename="./test.xlsx")

# 通过工作表获取数据
datas = openpyxl_get_datas(worksheet)

# 替换工作表数据
openpyxl_replace_worksheet_data(origin_worksheet, to_be_replaced_worksheet)

# 保存及关闭工作薄
workbook.save('./result.xlsx')
workbook.close()

xlwings获取App xw.Book xw.Sheet sheet_nameNone时读取返回第一个工作表

from exceltidy.exceltidy import *

app, workbook, worksheet = xlwings_get_app_workbook_worksheet('./test.xlsx')

# 
_, _, to_be_replaced_worksheet = xlwings_get_app_workbook_worksheet('./test2.xlsx', sheet_name='sort')

# 替换工作表数据
xlwings_replace_worksheet_data(origin_worksheet, to_be_replaced_worksheet)

# 排序
xlwings_sort(worksheet, "A4:L11", "L4:L11", 'descending')

# 保存及关闭工作薄、App
workbook.save()
workbook.close()
app.quit()

openpyxl_parse_multi_title_to_singleopenpyxl_parser_merged_cell使用方法详见代码函数