This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This must be at the very top of your script, before importing xlwings | |
import sys | |
import urllib.parse | |
# Make a copy of the original sys.argv | |
original_argv = sys.argv.copy() | |
# Process each argument to decode URL-encoded spaces | |
for i in range(1, len(sys.argv)): | |
if sys.argv[i].startswith('--'): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xlwings as xw | |
import pandas as pd | |
import random | |
import tkinter as tk | |
from tkinter import scrolledtext | |
from datetime import datetime, timedelta | |
import traceback | |
import os | |
import sys |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from concurrent.futures import ThreadPoolExecutor, as_completed | |
import os | |
import re | |
import pandas as pd | |
from collections import defaultdict | |
def import_files(): | |
# Your existing code for path and file detection remains the same | |
path = os.path.join(wkbk.api.Path, 'source') | |
exts = re.compile(r'\.tsv|\.csv|\.txt|\.xlsx|\.xls|\.tzo|\.LFC|\.dat', re.IGNORECASE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bgr_to_rgb(bgr_value): | |
""" | |
Converts a BGR integer value (like those from VBA's Interior.Color) | |
into an (R, G, B) tuple. | |
Args: | |
bgr_value: An integer representing the color in 0x00BBGGRR format. | |
Returns: | |
A tuple (R, G, B) with values from 0-255. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xlwings as xw | |
# If you need COM constants directly for things xlwings doesn't abstract: | |
# from win32com.client import constants as win32c | |
# No longer needed: _copy_range, _paste_format, _reset_cut_copy | |
def apply_format_from_source_cell(target_xw_range, source_xw_cell): | |
""" | |
Applies formatting from a source xlwings cell to a target xlwings range. | |
Args: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Looking at your code and the results, the issue appears to be with how you're handling the border copying logic. I can see a few potential problems: | |
1. **Border LineStyle Check**: In your code around line 583-584, you're checking `if s_border.LineStyle != xw.constants.LineStyle.xlLineStyleNone:` but then you're setting `t_border.LineStyle = s_border.LineStyle`. However, if the source border has no line style, you might still need to explicitly set it. | |
2. **Border Index Mapping**: The way you're iterating through `border_indices.items()` might not be correctly mapping the border positions. | |
Here's what I'd suggest to fix the border copying: | |
```python | |
def set_ttl_frmt(wkbk, sh, rng, frmt): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The issue is that your code is applying border properties to all edges regardless of whether the source cell actually has borders on those edges. You need to check if each border actually exists in the source before applying it to the target. | |
Here's the fix: | |
```python | |
def set_ttl_frmt(wkbk, sh, rng, frmt): | |
try: | |
if wkbk is None: | |
wkbk = xw.Book.caller() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import re | |
from datetime import datetime # For type checking if NavDate is datetime | |
# --- Define any custom processing functions based on your old logic --- | |
def custom_strip_logic(value): | |
""" | |
This function needs to replicate what `lstr(strip(0))` did | |
. The original `lstr(strip(0))` is unclear | |
as it doesn't specify which column it acts upon. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import polars as pl | |
def rollup_alpha_pl( | |
column_name: str, | |
delimiter: str = "#" | |
) -> pl.Expr: | |
""" | |
Creates a Polars expression to roll up unique values in a column, | |
handling numeric formatting, nulls, and pre-existing delimiters. | |
Uses only native Polars expressions for optimal performance. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import polars as pl | |
from pathlib import Path | |
def process_csvs_simple(folder_path, db_path): | |
# Get files for each type | |
type1_files = list(Path(folder_path).glob("pattern1_*.csv")) | |
type2_files = list(Path(folder_path).glob("pattern2_*.csv")) | |
# Process Type 1 files | |
if type1_files: |