mirror of
https://gitee.com/willfree/folder-file-manager.git
synced 2026-06-07 08:29:36 +08:00
34 lines
896 B
Python
34 lines
896 B
Python
import os
|
|
import xlsxwriter
|
|
import xlrd
|
|
|
|
|
|
# 读取excel文件某一列
|
|
def readExcelByCol(path, i):
|
|
i_col_content = []
|
|
worksheet = xlrd.open_workbook(path)
|
|
sheet_names = worksheet.sheet_names()
|
|
print(sheet_names)
|
|
for sheet_name in sheet_names:
|
|
sheet = worksheet.sheet_by_name(sheet_name)
|
|
rows = sheet.nrows # 获取行数
|
|
print(rows)
|
|
for j in range(rows):
|
|
i_col_content.append(sheet.cell_value(j, i))
|
|
return i_col_content
|
|
|
|
# 创建excel文件
|
|
def mkExcel(path):
|
|
workbook = xlsxwriter.Workbook(path)
|
|
workbook.close()
|
|
print("--- Created excel success" + path + " ---")
|
|
|
|
|
|
# 创建新文件。如果原来已经存在文件,则覆盖掉原有文件
|
|
def mkfileCoverOriginFile(path,content):
|
|
file = open(path, 'w')
|
|
file.write(content)
|
|
file.close()
|
|
print("--- Created file success" + path + " ---")
|
|
|