Skip to content

Commit

Permalink
Merge branch 'master' of github.com:nursix/eden-asp
Browse files Browse the repository at this point in the history
  • Loading branch information
nursix committed Sep 4, 2024
2 parents df6181e + 9aa3c74 commit 26e9d00
Show file tree
Hide file tree
Showing 23 changed files with 1,685 additions and 570 deletions.
3 changes: 3 additions & 0 deletions languages/de.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,8 @@
'Armenian': 'Armenisch',
'Aromanian; Arumanian; Macedo-Romanian': 'Aromunisch, Makedoromanisch',
'Arrival': 'Ankunft',
'Arrivals and Departures##shelter': 'Zugänge und Abgänge',
'Arrivals##shelter': 'Zugänge',
'Arrivals##shelter': 'Zugänge',
'Arrived': 'Angekommen',
'Assamese': 'Assamesisch',
Expand Down Expand Up @@ -1860,6 +1862,7 @@
'Department / Unit': 'Abteilung / Einheit',
'Department Catalog': 'Abteilungskatalog',
'Departure': 'Abreise',
'Departures##shelter': 'Abgänge',
'Departures': 'Abgänge',
'Dependency': 'Abhängigkeit',
'Dependent Person': 'Abhängige Person',
Expand Down
171 changes: 101 additions & 70 deletions modules/core/formats/xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,19 @@ def encode(cls, resource, **attr):
Keyword Args:
title: the main title of the report
sheet_title: the sheet title
list_fields: fields to include in list views
use_color: use background colors in cells (boolean, default False)
even_odd: when using colors, render different background colors
for even/odd rows (boolean, default True)
as_stream: return BytesIO rather than bytes
append_to: append to this workbook rather than creating a new one,
either a filename, or a byte stream
Note:
Appending to a workbook will re-use named styles already in the
workbook, so the workbook should be created with the same encoder
to prevent conflicting/incorrect styling
"""

T = current.T
Expand Down Expand Up @@ -112,8 +120,18 @@ def encode(cls, resource, **attr):
msg = "XLSXWriter: field(s) missing from data rows (%s)" % ", ".join(missing)
current.log.error(msg)

# Create the workbook
wb = Workbook(iso_dates=True)
append_to = attr_get("append_to")
if append_to:
# Use existing workbook
from openpyxl import load_workbook
wb = load_workbook(append_to)
sheet_number = len(wb.sheetnames) + 2
else:
# Create the workbook
wb = Workbook(iso_dates=True)
if len(wb.sheetnames) > 0:
wb.remove(wb[wb.sheetnames[0]]) # Remove default worksheet
sheet_number = 0

# Add named styles
use_color = attr_get("use_color", False)
Expand All @@ -139,20 +157,20 @@ def encode(cls, resource, **attr):
# Add the work sheets

# Characters /\?*[] not allowed in sheet names
sheet_name = " ".join(re.sub(r"[\\\/\?\*\[\]:]", " ", s3_str(title)).split())
sheet_name = attr_get("sheet_title")
if not sheet_name:
sheet_name = " ".join(re.sub(r"[\\\/\?\*\[\]:]", " ", s3_str(title)).split())

batch, remaining = rows[:batch_size], rows[batch_size:]
sheet_number = 0
if not batch:
# Create at least one sheet even if there are no data
batch = True
while batch:

# Create work sheet
sheet_number += 1
ws_title = "%s-%s" % (sheet_name[:28], sheet_number)
if sheet_number == 1:
ws = wb.active
ws.title = sheet_name[:31] if not remaining else ws_title
else:
ws = wb.create_sheet(title=ws_title)
ws_title = "%s-%s" % (sheet_name[:28], sheet_number) if remaining else sheet_name[:31]
ws = wb.create_sheet(ws_title)

# Count columns and initialize column width
num_columns = len(labels)
Expand Down Expand Up @@ -191,7 +209,8 @@ def encode(cls, resource, **attr):
ws.append(label_row)

# Add the data
cls.write_rows(ws, batch, lfields, types, column_widths)
if batch is not True:
cls.write_rows(ws, batch, lfields, types, column_widths)

# Adjust column widths
for i in range(1, num_columns + 1):
Expand Down Expand Up @@ -449,65 +468,77 @@ def add_styles(wb, use_color=False, even_odd=True):
font_bold = Font(name="Arial", size=10, bold=True)
font_large = Font(name="Arial", size=14, bold=True)

style = NamedStyle(name="normal")
style.font = font_normal
wb.add_named_style(style)

style = NamedStyle(name="even")
style.font = font_normal
if use_color and even_odd:
style.fill = PatternFill(start_color="FFFFFF", fill_type="solid")
style.border = border
wb.add_named_style(style)

style = NamedStyle(name="odd")
style.font = font_normal
if use_color and even_odd:
style.fill = PatternFill(start_color="E7E7E7", fill_type="solid")
style.border = border
wb.add_named_style(style)

style = NamedStyle(name="label")
style.font = font_bold
if use_color:
style.fill = PatternFill(start_color="BBDCED", fill_type="solid")
style.border = border
wb.add_named_style(style)

style = NamedStyle(name="large_header")
style.font = font_large
if use_color:
style.fill = PatternFill(start_color="BDBDEC", fill_type="solid")
style.border = border
wb.add_named_style(style)

style = NamedStyle(name="header")
style.font = font_bold
if use_color:
style.fill = PatternFill(start_color="BDBDEC", fill_type="solid")
style.border = border
wb.add_named_style(style)

style = NamedStyle(name="subheader")
style.font = font_bold
if use_color:
style.fill = PatternFill(start_color="CCCCFF", fill_type="solid")
style.border = border
wb.add_named_style(style)

style = NamedStyle(name="subtotals")
style.font = font_bold
if use_color:
style.fill = PatternFill(start_color="E6E6E6", fill_type="solid")
style.border = border
wb.add_named_style(style)

style = NamedStyle(name="totals")
style.font = font_bold
if use_color:
style.fill = PatternFill(start_color="C6C6C6", fill_type="solid")
style.border = border
wb.add_named_style(style)
existing = wb.style_names
missing = lambda n: n not in existing

if missing("normal"):
style = NamedStyle(name="normal")
style.font = font_normal
wb.add_named_style(style)

if missing("even"):
style = NamedStyle(name="even")
style.font = font_normal
if use_color and even_odd:
style.fill = PatternFill(start_color="FFFFFF", fill_type="solid")
style.border = border
wb.add_named_style(style)

if missing("odd"):
style = NamedStyle(name="odd")
style.font = font_normal
if use_color and even_odd:
style.fill = PatternFill(start_color="E7E7E7", fill_type="solid")
style.border = border
wb.add_named_style(style)

if missing("label"):
style = NamedStyle(name="label")
style.font = font_bold
if use_color:
style.fill = PatternFill(start_color="BBDCED", fill_type="solid")
style.border = border
wb.add_named_style(style)

if missing("large_header"):
style = NamedStyle(name="large_header")
style.font = font_large
if use_color:
style.fill = PatternFill(start_color="BDBDEC", fill_type="solid")
style.border = border
wb.add_named_style(style)

if missing("header"):
style = NamedStyle(name="header")
style.font = font_bold
if use_color:
style.fill = PatternFill(start_color="BDBDEC", fill_type="solid")
style.border = border
wb.add_named_style(style)

if missing("subheader"):
style = NamedStyle(name="subheader")
style.font = font_bold
if use_color:
style.fill = PatternFill(start_color="CCCCFF", fill_type="solid")
style.border = border
wb.add_named_style(style)

if missing("subtotals"):
style = NamedStyle(name="subtotals")
style.font = font_bold
if use_color:
style.fill = PatternFill(start_color="E6E6E6", fill_type="solid")
style.border = border
wb.add_named_style(style)

if missing("totals"):
style = NamedStyle(name="totals")
style.font = font_bold
if use_color:
style.fill = PatternFill(start_color="C6C6C6", fill_type="solid")
style.border = border
wb.add_named_style(style)

# =============================================================================
class XLSXPivotTableWriter:
Expand Down
2 changes: 1 addition & 1 deletion modules/core/methods/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .grouped import *
from .hcrud import *
from .mapview import *
from .merge import S3Merge, S3RecordMerger
from .merge import S3Merge
from .mobile import *
from .organizer import *
from .pois import *
Expand Down
Loading

0 comments on commit 26e9d00

Please sign in to comment.