自动提取表格中单号工具,作用比如策划将总结好,需要合并的单号全都放到表格中,可以使用此脚本一键提取表格中所有单号,单号会保存到Txt文本中,然后程序复制所有单号,粘贴到合并svn处,就可以一键查找此次需要合并的内容,进行一键合并,非常方便
#!/usr/bin/python
# -*- coding:utf-8 -*-
import os
import xlrd
import re
import sys
isHaveChar = input('不带有"SRPG-"输入y,其他回车:')
file_ext = ['.xlsx']
current_directory = os.path.dirname(os.path.abspath(__file__))
current_directory = current_directory.replace('\\','/')
data = ","
filenames = ""
needSaveStr = ""
for path in os.listdir(current_directory):
temp_name = re.search("~\$.*?\.xlsx",path)
if temp_name == None:
path_list = os.path.join(current_directory, path) # 连接当前目录及文件或文件夹名称
if os.path.isfile(path_list): # 判断当前文件或文件夹是否是文件,把文件夹排除
if (os.path.splitext(path_list)[1]) in file_ext: # 判断取得文件的扩展名是否是.xls、.xlsx
filenames = path_list # 打印输出
filenames = filenames.replace('\\','/')
xlsx = xlrd.open_workbook(filenames)
sheets = xlsx.sheets()
for table in sheets:
if table.visibility == 0:
row = table.nrows
for i in range(row):
rowdate = table.row_values(i)
for a, b in enumerate(rowdate):
data = data + str(b)
data = data + "\n"
strCount = len(re.findall(r"SRPG-(.+)",data))
for i in range(strCount):
if isHaveChar == "Y" or isHaveChar == "y":
if i + 1 >= strCount:
needSaveStr = needSaveStr + re.findall(r"SRPG-(\d+)",data)[i]
else:
needSaveStr = needSaveStr + re.findall(r"SRPG-(\d+)",data)[i] + " "
else:
if i + 1 >= strCount:
needSaveStr = needSaveStr + "SRPG-" + re.findall(r"SRPG-(\d+)",data)[i]
else:
needSaveStr = needSaveStr + "SRPG-" + re.findall(r"SRPG-(\d+)",data)[i] + " +"
file = open(current_directory + "/lookJira.txt",'w')
file.write(needSaveStr)