working single group
This commit is contained in:
parent
ae2a5c286f
commit
0c180a7f42
|
@ -1,3 +1,4 @@
|
|||
*.xlsx
|
||||
*#
|
||||
__pycache__
|
||||
__pycache__
|
||||
test_out
|
|
@ -1,11 +1,17 @@
|
|||
from openpyxl import load_workbook
|
||||
import argparse
|
||||
|
||||
wb = load_workbook(filename = 'names.xlsx')
|
||||
parser = argparse.ArgumentParser(description='Process some intzzz')
|
||||
parser.add_argument('--in', '-i', dest='file_in', required=True)
|
||||
parser.add_argument('--out', '-o')
|
||||
parser.add_argument('--range', '-r', dest='cell_range')
|
||||
|
||||
names = []
|
||||
args = parser.parse_args()
|
||||
|
||||
for row in wb.active.iter_rows():
|
||||
name = " ".join(list(map(lambda cell: cell.value, row)))
|
||||
names.append(name)
|
||||
from spreadsheet import get_names_list
|
||||
|
||||
names = get_names_list(args.file_in, args.cell_range)
|
||||
print(names)
|
||||
|
||||
from directory import create_directories
|
||||
|
||||
create_directories(args.out, names)
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
import os
|
||||
from pathlib import Path
|
||||
|
||||
def create_directory(name):
|
||||
Path(name).mkdir(parents=True, exist_ok=True)
|
||||
|
||||
def create_directories(outdir, paths):
|
||||
for path in paths:
|
||||
fullpath = f"{outdir}/{path}" if outdir is not None else path
|
||||
create_directory(fullpath)
|
|
@ -0,0 +1,57 @@
|
|||
from openpyxl import load_workbook
|
||||
|
||||
ALPHA = {
|
||||
'A': 1,
|
||||
'B': 2,
|
||||
'C': 3,
|
||||
'D': 4,
|
||||
'E': 5,
|
||||
'F': 6,
|
||||
'G': 7,
|
||||
'H': 8,
|
||||
'I': 9,
|
||||
'J': 10,
|
||||
'K': 11,
|
||||
'L': 12,
|
||||
'M': 13,
|
||||
'N': 14,
|
||||
'O': 15,
|
||||
'P': 16,
|
||||
'Q': 17,
|
||||
'R': 18,
|
||||
'S': 19,
|
||||
'T': 20,
|
||||
'U': 21,
|
||||
'V': 22,
|
||||
'W': 23,
|
||||
'X': 24,
|
||||
'Y': 25,
|
||||
'Z': 26
|
||||
}
|
||||
|
||||
def parse_range(cellrange):
|
||||
cell1 = cellrange.split(":")[0]
|
||||
cell2 = cellrange.split(":")[1]
|
||||
|
||||
min_col = ALPHA[cell1[0]]
|
||||
min_row = int(cell1[1:])
|
||||
|
||||
max_col = int(ALPHA[cell2[0]])
|
||||
max_row = int(cell2[1:])
|
||||
|
||||
return (min_row, min_col, max_row, max_col)
|
||||
|
||||
def get_names_list(filename, cellrange):
|
||||
wb = load_workbook(filename = filename)
|
||||
names = []
|
||||
|
||||
min_row = min_col = max_row = max_col = None
|
||||
|
||||
if cellrange:
|
||||
min_row, min_col, max_row, max_col = parse_range(cellrange)
|
||||
|
||||
for row in wb.active.iter_rows(min_row=min_row, min_col=min_col, max_row=max_row, max_col=max_col, values_only=True):
|
||||
name = " ".join([str(cell) for cell in row if cell is not None])
|
||||
names.append(name)
|
||||
|
||||
return [name for name in names if name != ""]
|
Loading…
Reference in New Issue