python - Exporting plain text header and image to Excel -


i new python, i'm getting stuck trying pass image file header during dataframe.to_excel() portion of file.

basically want picture in first cell of excel table, followed couple of rows (5 exact) of text include date (probably datetime.date.today().ctime() if possible).

i have code output table portion as:

mydataframe.to_excel(my_path_name, sheet_name= my_sheet_name, index=false, startrow=7,startcol=0) 

is there way output image , text portion directly python?

update:

for clarity, mydataframe exporting meat , potatoes of worksheet (data rows , columns). have starting on row 7 of worksheet in excel. header portion trouble spot.

i found solution , of help.

the simple answer use xlsxwriter package engine. in other words assume image saved @ path /image.png. code insert data excel file image located @ top of data be:

# importing packages , storing string image file import pandas pd import xlsxwriter import numpy np image_file = '/image.png'  # creating fictitious data set since actual data doesn't matter dataframe = pd.dataframe(np.random.rand(5,2),columns=['a','b'])  # opening xlsxwriter object path on c:/ drive writer = pd.excelwriter('c:/file.xlsx',engine='xlsxwriter')  dataframe.to_excel(writer,sheet_name = 'arbitrary', startrow=3)  # accessing workbook / worksheet workbook = writer.book worksheet = writer.sheets['arbitrary']  # inserting image workbook in cell a1 worksheet.insert_image('a1',image_file)  # closing workbook , saving file specified path , filename writer.save() 

and have image on top of excel file. huzzah!


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -