I'm in the midst of writing a iPython notebook that will pull the contents of a .csv file and paste them into a specified tab on an .xlsx file. The tab on the .xlsx is filled with a bunch of pre-programmed formulas so that I might run an analysis on the original content of the .csv file.
I've ran into a snag, however, with the the date fields that I copy over from the .csv into the .xlsx file.
The dates do not get properly processed by the Excel formulas unless I double-click the date cells or apply Excel's "text to columns" function on the column of dates and set a tab as the delimiter (which I should note, does not split the cell).
I'm wondering if there's a way to either...
- write a helper function that logs the keystrokes of applying the "text to columns" function call
write a helper function to double click and return down each row of the column of dates
from openpyxl import load_workbook import pandas as pd def transfer_hours(report_name, ER_hours_analysis_wb): df = pd.read_csv(report_name, index_col=0) book = load_workbook(ER_hours_analysis_wb) sheet_name = "ER Work Log" with pd.ExcelWriter("ER Hours Analysis 248112.xlsx", engine='openpyxl') as writer: writer.book = book writer.sheets = dict((ws.title, ws) for ws in book.worksheets) df.to_excel(writer, sheet_name=sheet_name, startrow=1, startcol=0, engine='openpyxl')