Skip to content

fixes duplicate table names #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions bmsdna/table_rendering/excel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
from datetime import datetime
import os
from pathlib import Path
from typing import Callable, Any, TYPE_CHECKING, Iterable, Literal, Mapping, Sequence
from typing import (
Callable,
Any,
TYPE_CHECKING,
Iterable,
Literal,
Mapping,
Sequence,
cast,
)
from typing_extensions import NotRequired, TypedDict
from uuid import uuid4
import json
Expand Down Expand Up @@ -34,6 +43,8 @@ def render_into_sheet(
*,
translator: Callable[[str, str], str] | None = None,
offset_rows=0,
autofit=True,
table_name: str | None = None,
) -> "Worksheet":
try:
import polars as pl
Expand Down Expand Up @@ -116,21 +127,29 @@ def render_into_sheet(
ws.write(row_ind, i, value, formats[i])

assert ws.name is not None

if table_name is None:
t_name = ws.name.replace(" ", "_")
existing_names = set(t["name"].lower() for t in ws.tables if t.get("name"))
cnt = 2
while t_name.lower() in existing_names:
t_name = ws.name.replace(" ", "_") + "_" + str(cnt)
cnt += 1
table_name = t_name
ws.add_table(
offset_rows,
0,
row_ind,
len(configs) - 1,
{
"name": ws.name.replace(" ", "_"),
"name": table_name,
"style": "Table Style Medium 2",
"columns": [
{"header": config.get_header(translator)} for config in configs
],
},
)
ws.autofit()
if autofit:
ws.autofit()

fp = sheet_options.get("freeze_panes", None)
if fp:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "bmsdna-table-rendering"
version = "0.3.6"
version = "0.3.7"
description = ""
authors = [{ name = "Adrian Ehrsam", email = "adrian.ehrsam@bmsuisse.ch" }]
dependencies = [
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.