vamseeachanta / assetutilities

Utilities for performing day to day tasks. Helps in automation of day to day business tasks
MIT License
0 stars 1 forks source link

Word Utilities | Format CSV data and save in word #21

Open vamseeachanta opened 1 month ago

vamseeachanta commented 1 month ago

Objective: Format a table with borders and save it in word page to fit

Overall process:

STEPS for CSV to DOCX:

# 1. Open the .csv file
# 2. Read the .csv file as DF
# Format as table then write to .docx
# 3. Create a new .docx file

See testcase csv file data below. https://github.com/vamseeachanta/assetutilities/blob/751472da008f5e7dce8ad2840c0e868077afc23f/src/assetutilities/tests/test_data/word_utilities/data

vamseeachanta commented 1 month ago

Legacy code:

https://github.com/vamseeachanta/assetutilities/blob/b2cbe58ce4bf5483ff863adb99ef73ce84aee6d8/src/assetutilities/common/data.py

Look at functions:

Example usage:

save_data = SaveData()
example_data = {
    "first_name": ["Jason", "Molly", "Tina", "Jake", "Amy"],
    "last_name": ["Miller", "Jacobson", "Ali", "Milner", "Cooze"],
    "age": [42, 52, 36, 24, 73],
    "preTestScore": [4, 24, 31, 2, 3],
    "postTestScore": [25, 94, 57, 62, 70],
}
df = pd.DataFrame(
    example_data,
    columns=["first_name", "last_name", "age", "preTestScore", "postTestScore"],
)
cfg = {"file_name": "test_file"}
save_data.df_to_table_as_docx(df, cfg)
vamseeachanta commented 1 month ago

Please review this podcast. Great Tables make data display in tables better is what this podcast goes through. I do not know the details. https://realpython.com/podcasts/rpp/214/?utm_source=notification_summary&utm_medium=email&utm_campaign=2024-07-26

vamseeachanta commented 1 month ago

Review existing code. DF can be formatted for rounding numbers font size can be defined? columns can be dropped per choice