Skip to main content

Lightweight helper library for parsing and manipulating Excel and CSV files easily.

Project description

ExcelCSVParseHelper

A lightweight Python library to help parse, manipulate, and automate workflows between CSV and Excel files.

Features

  • Insert numerical or string data into Excel cells
  • Automatically reopen or close Excel files (Windows platform, other OS best-effort with manual fallback)
  • Parse, clean, and filter CSV datasets
  • Read ranges from Excel sheets
  • Split lists into positives/negatives for further processing

Installation

pip install ExcelCSVParseHelper

On Windows, psutil and pywin32 are installed automatically (via environment markers) and enable the Excel process-close helper. The reopen helper is best-effort and works cross-platform.

On macOS/Linux, core CSV/Excel parsing and writing functions work normally; the Excel process close helper is disabled and will instruct you to close the workbook manually if needed. The reopen helper will try to launch your default application (best-effort).

Included dependency

As of v1.2.2, this package installs LockFileSemaphore automatically as a dependency (no separate installation required). You can import and use it directly:

from LockFileSemaphore import FileLock

with FileLock("/tmp/my.lock"):
    # protected section
    pass

Example Usage

from ExcelCSVParseHelper import *

insert_data_to_excel("myfile.xlsx", {"A1": 100, "B2": 200}, sheet_arg="Sheet1")

df = prepare_source(base_path="data.csv", sep=",", columns_to_drop=[0, 2])

More advanced use cases are also supported like for example via use of a 'staging' function in the following manner:

def run(
    date,
    idea1_base_path,
    idea1_postfix = "_results_ide1.csv",
    idea1_sep = ";",
    ida1_columns_to_keep = [1, 2],
    idea1_prefix_list = ["A", "B"], 
    idea1_column_list = ["One", "Two"],
    idea1_start_int= 1,
    idea1_include_header= True,
    raw_path = None
):
    
   
    
    postfix= idea1_postfix
    base_path= idea1_base_path
    sep= idea1_sep
    columns_to_keep= ida1_columns_to_keep
    
    return_dict= {}
    
    prefix_list= ida1_prefix_list
    column_list= ida1_column_list
    
    for i in range(len(prefix_list)):
        return_dict = set_source(
            file_path= raw_path,
            prefix_letter=prefix_list[i],
            column_target=column_list[i],
            date_target=f"{date}",
            start_int= idea1_start_int,
            header=column_list[i],
            postfix=postfix,
            base_path=base_path,
            sep=sep,
            white_list=True,
            columns_to_keep=columns_to_keep,
            infer=False,
            
            header_start= 213,
            range_of_interest_start=0,
            range_of_interest_end=96,
            include_header= idea1_include_header
        )
        
        fp  = return_dict["file_path"]
        
        
        
        close_excel_file_if_open(return_dict["file_path"])
        
        insert_data_to_excel(
            return_dict["file_path"],
            return_dict["column_insert"],
            sheet_arg= "data",
        )

or

def run_2(
    date,
    two_base_path,
    two_colums_to_drop=[
        "UsrName",
        "TmZn",
        "INFO",
        "Self",
    ],
    two_postfix="-two.csv",
    two_sep=";",
    two_prefix_list=["B", "C", "D", "E", "F"], #do których kolumn będzie wstawione
    two_column_list=["1", "2" , "3", "4", "5"],
    two_start_int= 1,
    two_include_header= True,
    raw_path = None
    
):
    
    

    postfix = two_postfix
    base_path= two_base_path
    sep = two_sep
    columns_to_drop = two_colums_to_drop

    return_dict = {}

    prefix_list = two_prefix_list
    column_list = two_column_list


    for i in range(len(prefix_list)):
        return_dict = set_source(
            file_path= raw_path,
            prefix_letter=prefix_list[i],
            column_target=column_list[i],
            date_target=f"{date}",
            start_int= two_start_int,
            header=column_list[i],
            postfix=postfix,
            base_path=base_path,
            sep=sep,
            columns_to_drop=columns_to_drop,
            white_list=False,
            columns_to_keep=None,
            infer=True,
            header_start=None,
            range_of_interest_start=None,
            range_of_interest_end=None,
            include_header= two_include_header
        )

        fp  = return_dict["file_path"]
        
       


        close_excel_file_if_open(return_dict["file_path"])

        insert_data_to_excel(
            return_dict["file_path"],
            return_dict["column_insert"],
            sheet_arg= "Dane",
        )

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

excelcsvparsehelper-1.2.3.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

excelcsvparsehelper-1.2.3-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file excelcsvparsehelper-1.2.3.tar.gz.

File metadata

  • Download URL: excelcsvparsehelper-1.2.3.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for excelcsvparsehelper-1.2.3.tar.gz
Algorithm Hash digest
SHA256 2028e3bd661cf085fde7d88bb95d67ab88f96893295d51cbbfbca008c6d9c027
MD5 787d4eac12801d0c33212cb1da7cb6b3
BLAKE2b-256 4ffefcb4b6f5ddf15e697e6ed55dbe911fc16072a09cffe807e402f5e2d79a4c

See more details on using hashes here.

File details

Details for the file excelcsvparsehelper-1.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for excelcsvparsehelper-1.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2f35778014a7019b17692f1efb43908ce12dd9407aab6d9261bd3c687a0af121
MD5 755fafdb4b22ce5613f864e0c2fb69a6
BLAKE2b-256 77b99afa77d0759afebdf0e0e3a4e6ceca3bf1e5b7848eb8ca5e318aa2cd60d0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page