Created
January 9, 2024 01:54
-
-
Save Archonic944/856c1d63cd4bfdfe1294db6cb178caa2 to your computer and use it in GitHub Desktop.
A pasting utility that I made for my science project
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 openpyxl import Workbook, load_workbook | |
from pathlib import Path | |
import csv | |
from openpyxl.utils import get_column_letter | |
downloads_path = str(Path.home() / "Downloads") | |
src_block_path = downloads_path + "/closed_3.xlsx" | |
src_cells_start = "N1" | |
src_cells_end = "X5" | |
print(src_block_path) | |
#get src block | |
src_wb = load_workbook(src_block_path) | |
print(src_wb.sheetnames) | |
src_ws = src_wb.active | |
src_cells = src_ws[src_cells_start:src_cells_end] | |
actions = ("resting", "closed", "tapping", "reading") | |
amt = 5 | |
for action in actions: | |
for i in range(1, amt + 1, 1): | |
wb = load_workbook(downloads_path + "/data_me" + f"/{action}_{i}.xlsx") | |
ws = wb.active | |
#set same range of cells in the other workbook to what they were in src (don't set title) | |
cell_range = ws[src_cells_start:src_cells_end] | |
r = -1 | |
print(f"len: {len(cell_range)}") | |
print(f"src len: {len(src_cells)}") | |
for row in cell_range: | |
r += 1 | |
column = -1 | |
print(len(row)) | |
for cell in row: | |
column += 1 | |
print(f"{r}, {column}") | |
cell.value = src_cells[r][column].value | |
print(src_cells[r][column].value) | |
wb.save(downloads_path + "/data_me" + f"/{action}_{i}_mod") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment