-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredactXLSX.py
More file actions
42 lines (28 loc) · 939 Bytes
/
Copy pathredactXLSX.py
File metadata and controls
42 lines (28 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import sys
sys.path.append('/home/m335964/miniconda3/lib/python3.9/site-packages')
import openpyxl
import os
import string
import random
filestoremove = []
for filename in os.listdir():
if ".xlsx" in filename:
print("\n" + filename )
filestoremove.append(filename)
print()
for file in filestoremove:
wb = openpyxl.load_workbook(file)
wl = wb.sheetnames
ws = wb[wl[0]]
i = 0
for r in range(1,ws.max_row+1):
for c in range(1,ws.max_column+1):
s = str(ws.cell(r,c).value)
if s == 'None':
continue
new_string = s.translate(str.maketrans('', '', string.punctuation))
if new_string.isdigit():
ws.cell(r,c).value = random.randint(0,1000)
i+=1
wb.save("noTechnicaldata_{}".format(file))
print("{} cells updated".format(i))