toolsos 0.3.3__py3-none-any.whl → 0.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,76 +1,76 @@
1
- from pathlib import Path
1
+ # from pathlib import Path
2
2
 
3
- import pandas as pd
4
- import win32com.client as win32
3
+ # import pandas as pd
4
+ # import win32com.client as win32
5
5
 
6
6
 
7
- def remove_underscores_from_columns(df: pd.DataFrame) -> pd.DataFrame:
8
- df.columns = df.columns.str.replace("_", " ")
9
- return df
7
+ # def remove_underscores_from_columns(df: pd.DataFrame) -> pd.DataFrame:
8
+ # df.columns = df.columns.str.replace("_", " ")
9
+ # return df
10
10
 
11
11
 
12
- def get_excel_files_from_folder(folder: str) -> list[str]:
13
- return [str(f.resolve()) for f in Path(folder).glob("*") if f.suffix == ".xlsx"]
12
+ # def get_excel_files_from_folder(folder: str) -> list[str]:
13
+ # return [str(f.resolve()) for f in Path(folder).glob("*") if f.suffix == ".xlsx"]
14
14
 
15
15
 
16
- def combine_excel_files(out_path: str, files: list[str] = None, overwrite: bool = True):
17
- out_path = Path(out_path)
16
+ # def combine_excel_files(out_path: str, files: list[str] = None, overwrite: bool = True):
17
+ # out_path = Path(out_path)
18
18
 
19
- if overwrite:
20
- if out_path.exists():
21
- out_path.unlink()
19
+ # if overwrite:
20
+ # if out_path.exists():
21
+ # out_path.unlink()
22
22
 
23
- # INITIALIZE EXCEL COM APP
24
- try:
25
- xlapp = win32.gencache.EnsureDispatch("Excel.Application")
23
+ # # INITIALIZE EXCEL COM APP
24
+ # try:
25
+ # xlapp = win32.gencache.EnsureDispatch("Excel.Application")
26
26
 
27
- # constants
28
- xlPasteValues = -4163
29
- lPasteFormats = -4122
30
- xlWorkbookDefault = 51
27
+ # # constants
28
+ # xlPasteValues = -4163
29
+ # lPasteFormats = -4122
30
+ # xlWorkbookDefault = 51
31
31
 
32
- # create new workbook
33
- new_wb = xlapp.Workbooks.Add()
34
- new_wb.SaveAs(Filename=str(out_path), FileFormat=xlWorkbookDefault)
32
+ # # create new workbook
33
+ # new_wb = xlapp.Workbooks.Add()
34
+ # new_wb.SaveAs(Filename=str(out_path), FileFormat=xlWorkbookDefault)
35
35
 
36
- dup_count = 1
36
+ # dup_count = 1
37
37
 
38
- for wb in files:
39
- xlwb = xlapp.Workbooks.Open(wb)
38
+ # for wb in files:
39
+ # xlwb = xlapp.Workbooks.Open(wb)
40
40
 
41
- for xlsh in xlwb.Worksheets:
42
- new_sh = new_wb.Worksheets.Add()
41
+ # for xlsh in xlwb.Worksheets:
42
+ # new_sh = new_wb.Worksheets.Add()
43
43
 
44
- try:
45
- new_sh.Name = xlsh.Name
44
+ # try:
45
+ # new_sh.Name = xlsh.Name
46
46
 
47
- # Ugly non defined exception. Be aware that this wil caputre
48
- except Exception as e:
49
- new_sh.Name = f"{xlsh.Name}_{dup_count}"
50
- dup_count += 1
47
+ # # Ugly non defined exception. Be aware that this wil caputre
48
+ # except Exception as e:
49
+ # new_sh.Name = f"{xlsh.Name}_{dup_count}"
50
+ # dup_count += 1
51
51
 
52
- new_wb.Save()
53
- new_sh.Move(After=new_wb.Worksheets(new_wb.Worksheets.Count))
52
+ # new_wb.Save()
53
+ # new_sh.Move(After=new_wb.Worksheets(new_wb.Worksheets.Count))
54
54
 
55
- xlsh.Cells.Copy(new_sh.Cells)
56
- new_sh = None
55
+ # xlsh.Cells.Copy(new_sh.Cells)
56
+ # new_sh = None
57
57
 
58
- xlwb.Close(True)
59
- xlwb = None
58
+ # xlwb.Close(True)
59
+ # xlwb = None
60
60
 
61
- # remove default blad1
62
- new_wb.Worksheets("Blad1").Delete()
63
- new_wb.Save()
61
+ # # remove default blad1
62
+ # new_wb.Worksheets("Blad1").Delete()
63
+ # new_wb.Save()
64
64
 
65
- except Exception as e:
66
- print(e)
65
+ # except Exception as e:
66
+ # print(e)
67
67
 
68
- # RELEASE RESOURCES
69
- finally:
70
- xlsh = None
71
- new_sh = None
72
- xlwb = None
73
- new_wb = None
74
- xlapp.Quit()
75
- xlapp = None
76
- xlwb = None
68
+ # # RELEASE RESOURCES
69
+ # finally:
70
+ # xlsh = None
71
+ # new_sh = None
72
+ # xlwb = None
73
+ # new_wb = None
74
+ # xlapp.Quit()
75
+ # xlapp = None
76
+ # xlwb = None
@@ -7,13 +7,20 @@ STYLE_OLD = {
7
7
  "fill": {"fill_type": "solid", "fgColor": "B1D9F5"},
8
8
  "font": {"bold": False},
9
9
  },
10
- "calibri": {"font": {"name": "Calibri", "size": 9}},
10
+ "calibri": {
11
+ "font": {"name": "Calibri", "size": 9},
12
+ # "alignment": {"vertical": "center"},
13
+ },
11
14
  "blue_border_bottom": {
12
15
  "border_bottom": {"color": "00a0e6", "border_style": "medium"}
13
16
  },
14
17
  "left_align": {"alignment": {"horizontal": "left"}, "font": {"bold": False}},
15
18
  "right_align": {"alignment": {"horizontal": "right"}},
16
- "title_bold": {"font": {"bold": True, "name": "Calibri", "size": 9}},
19
+ "title_bold": {
20
+ "font": {"bold": True, "name": "Calibri", "size": 9},
21
+ "alignment": {"vertical": "center"},
22
+ },
23
+ "vert_align_middle": {"alignment": {"vertical": "center"}},
17
24
  }
18
25
 
19
26
  STYLE_NEW = {
@@ -25,11 +32,18 @@ STYLE_NEW = {
25
32
  "fill": {"fill_type": "solid", "fgColor": "b8bcdd"},
26
33
  "font": {"bold": True},
27
34
  },
28
- "calibri": {"font": {"name": "Calibri", "size": 9}},
35
+ "calibri": {
36
+ "font": {"name": "Calibri", "size": 9},
37
+ "alignment": {"vertical": "center"},
38
+ },
29
39
  "blue_border_bottom": {
30
40
  "border_bottom": {"color": "004699", "border_style": "medium"}
31
41
  },
32
42
  "left_align": {"alignment": {"horizontal": "left"}, "font": {"bold": True}},
33
43
  "right_align": {"alignment": {"horizontal": "right"}},
34
- "title_bold": {"font": {"bold": True, "name": "Calibri", "size": 9}},
44
+ "title_bold": {
45
+ "font": {"bold": True, "name": "Calibri", "size": 9},
46
+ # "alignment": {"vertical": "center"},
47
+ },
48
+ "vert_align_middle": {"alignment": {"vertical": "center"}},
35
49
  }
@@ -322,6 +322,7 @@ def cell_formatting(
322
322
  float_col_format: str | None = None,
323
323
  blue_border_ids: bool | None = None,
324
324
  number_format: str | None = None,
325
+ middle_vertical_aligment: list = None,
325
326
  ):
326
327
  """Function to create the nested list with the shape of the input data (including columns)
327
328
  containing dictionaries with the formatting
@@ -382,6 +383,9 @@ def cell_formatting(
382
383
  if blue_border_ids:
383
384
  fmt = set_style_row(fmt, blue_border_ids, STYLES["blue_border_bottom"])
384
385
 
386
+ if middle_vertical_aligment:
387
+ fmt = set_style_row(fmt, middle_vertical_aligment, STYLES["vert_align_middle"])
388
+
385
389
  return fmt
386
390
 
387
391
 
@@ -521,7 +525,7 @@ def write_table(
521
525
  column_widths: list[int] | None = None,
522
526
  min_column_width: int | None = None,
523
527
  col_filter: bool | None = False,
524
- style: str = "old",
528
+ style: str = "new",
525
529
  combine_multiindex: bool | int = False,
526
530
  column_names_to_string: bool = True,
527
531
  ):
@@ -772,6 +776,11 @@ def format_worksheet(
772
776
  else:
773
777
  col_widths = None
774
778
 
779
+ # The top row of a table should be bottom aligned vertically. The rest of the table
780
+ # should vertically be aligned in the middle. If there is a title row the alignment
781
+ # needs to be shifted on row
782
+ row_vert_middle = [i for i in range(1, arr.shape[0] + 1)]
783
+
775
784
  ws = wb.create_sheet(sheet_name)
776
785
 
777
786
  fmt = cell_formatting(
@@ -788,6 +797,7 @@ def format_worksheet(
788
797
  float_col_format=float_col_format,
789
798
  number_format=number_format,
790
799
  blue_border_ids=blue_border_ids,
800
+ middle_vertical_aligment=row_vert_middle,
791
801
  )
792
802
 
793
803
  write_to_worksheet(
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: toolsos
3
- Version: 0.3.3
3
+ Version: 0.4.0
4
4
  Summary: OS tools
5
- Author-email: OS <d.schmitz@amsterdam.nl>
5
+ Author-email: Daan Schmitz <d.schmitz@amsterdam.nl>
6
6
  Keywords: tools,Onderzoek & Statistiek
7
7
  Classifier: License :: OSI Approved :: MIT License
8
8
  Classifier: Programming Language :: Python
@@ -18,10 +18,10 @@ toolsos/huisstijl/graphs/styler.py,sha256=-uZ7pjY1G39XvmaGHQd31gPRxjxmJGhYZk8xhy
18
18
  toolsos/huisstijl/maps/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  toolsos/huisstijl/maps/choropleth.py,sha256=2B2Av5hQXkuFHR-TDcDndSmksji-mIwGoqq_JDMwO6w,2531
20
20
  toolsos/huisstijl/tables/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
- toolsos/huisstijl/tables/table_helpers.py,sha256=Q1VuaEHl__K0xFQOeucihN212joTkxhcNbS6wKZaMew,2033
22
- toolsos/huisstijl/tables/table_styles.py,sha256=oYU6GJcfqlKpZof5PUjPsA7woJ3Tew78CHPyT0_jY6w,1343
23
- toolsos/huisstijl/tables/tables.py,sha256=Ri08lyz0y9PYdtTpWpVdDAiGlgVYW2JEyawg636cfWQ,28194
24
- toolsos-0.3.3.dist-info/METADATA,sha256=lqAFIt4-_XNUrHfsgIQSIfC90WdXCZd7V-j9U5y8D0c,2767
25
- toolsos-0.3.3.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
26
- toolsos-0.3.3.dist-info/top_level.txt,sha256=2ClEjUBbtfDQ8oPwvWRy1Sz2nrkLCXlg0mHaMdCWia0,8
27
- toolsos-0.3.3.dist-info/RECORD,,
21
+ toolsos/huisstijl/tables/table_helpers.py,sha256=LgFEH3g_qOo79JHplV_ONEg5vP0p3P00QisMDaoCZmE,2141
22
+ toolsos/huisstijl/tables/table_styles.py,sha256=tzwTDRRUyw8f9zsGNo08lK2hVl_Eahj-2ZOSNyN1SF0,1729
23
+ toolsos/huisstijl/tables/tables.py,sha256=jS55zIxTJ2Q_mQEivyDaZZu7sl2gORCXfvO7HetewvM,28691
24
+ toolsos-0.4.0.dist-info/METADATA,sha256=V3u8o42Fx8wyPHyZ89JkYq9OlUg8vFGfcDvkXmTYzq8,2777
25
+ toolsos-0.4.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
26
+ toolsos-0.4.0.dist-info/top_level.txt,sha256=2ClEjUBbtfDQ8oPwvWRy1Sz2nrkLCXlg0mHaMdCWia0,8
27
+ toolsos-0.4.0.dist-info/RECORD,,