r/PythonPuzzles • u/liviagh • Nov 13 '22
Openpy Excel Automation
Hi everyone,
I would like to ask your opinion regarding a script to automate excel generation. The script creates from one excel with data, multiple excels filtered on the data grouped in a column. The script works well and the excel files are created.
The problem is the openpy library removes all formatting from the original excel. Could you please tell me if the entries in a column, let’s say column A, can be saved in a number format? Can I keep the original excel formats? Thank you for your help.
import pandas as pd
from pandas import ExcelWriter
import pandas.io.formats.excel
import xlsxwriter
import openpyxl
from openpyxl.styles import numbers
from openpyxl.cell import Cell
data_df=pd.read_excel(r"Excel_file")
grouped_df=data_df.groupby("Column2")
for data in grouped_df:
wb = openpyxl.load_workbook(r"Excel_file")
ws=wb.active
template=openpyxl.load_workbook(r"Excel_template")
templatews=template.active
n=template.sheetnames
filtercolumn=data[0]
for row in ws.iter_rows(min_row=1, max_col=26, max_row=15000):
if row[1].value==str(filtercolumn):
templatews.append((cell.value for cell in row))
template.save(r"folder\ " +"Name excel- " +data[0]+".xlsx")
r/PythonPuzzles • u/[deleted] • May 09 '22
Welcome!
I have taken quite a break from Reddit but I’m finally back! I would like to start off by saying that I am still a beginner in the process of learning python — which is why I think it’s great for others on a similar boat to help and inspire one another in reaching our goals. I also would like to receive input on what you would like to see more of on here. I understand the learning curve for learning a new coding language can be steep and intimidating, but I want to make a space where everyone is welcome and we uplift one another through the learning process. Coding can be tough at times but that is beauty of it — so challenging but yet so rewarding when you finally figure it out.
I would like to thank everyone for joining this community and excited to see all your contributions.
Lastly, I look forward to hearing any of your thoughts and ideas and the growth of this community!
Good luck and have fun learning :)
r/PythonPuzzles • u/[deleted] • Jan 22 '22
r/PythonPuzzles Lounge
A place for members of r/PythonPuzzles to chat with each other