-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexcel_formatter.py
55 lines (42 loc) · 1.17 KB
/
excel_formatter.py
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
43
44
45
46
47
48
49
50
51
52
53
54
import os
import Arguments
import Formatter
import Config
import Logger
from Utils import *
import xlsxwriter
args = Arguments.Parse()
cfg = Config.Get()
@Formatter.Register("xlsx")
def excel_formatter(components):
""" Formats a list of components into an excel spreadsheet """
save_path = args.output_file
workbook = xlsxwriter.Workbook(save_path)
ws = workbook.add_worksheet('BOM')
# Create styling for the header titles
header_style = workbook.add_format({
'font_size': 16,
'bold': True,
'align': 'center',
'bottom': 2,
'right': 1,
})
# Create styling for general row
row_style = workbook.add_format({
'right': 1,
'bottom': 1
})
columns = cfg['columns'] # List of columns
# Add the columns to the file
for col in range(0, len(columns)):
ws.write(0, col, denormalizeStr(columns[col]), header_style)
# Add a row for each component
for row in range(0, len(components)):
for col in range(0, len(columns)):
try:
ws.write(row + 1, col, components[row][columns[col]], row_style)
except:
ws.write(row + 1, col, cfg['emptyValue'], row_style)
# Close the file
workbook.close()
return save_path