Python Forum
Export Python output to Excel
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Export Python output to Excel
#1
Question 
Hi,
I am trying to get Python outputs to be in Excel.
The code is:
import xlwings as xw
import time
import schedule
from yahoo_fin.stock_info import *
def show_name():
    print(get_live_price("4339.SR"))
schedule.every(3).seconds.do(show_name)
while 1:
    schedule.run_pending()
    time.sleep(1)
workbook = xlsxwriter.Workbook('sample_data4.xlsx')
sheet = workbook.add_worksheet()

sheet.write('A1', '')


workbook.close()
   


However, the Excel file sample_data4.xlsx is unreachable as shown below:

   


Although, the Excel file is located in the same folder as shown below:

   

Then in Excel VBA I entered :
Sub RunPythonScript()
Dim objShell As Object
Dim PythonExePath, PythonScriptPath As String
Set objShell = VBA.CreateObject("Wscript.Shell")
PythonExePath = """C:\Users\osalh\AppData\Local\Programs\Python\Python39\python.exe"""
PythonScriptPath = "C:\Users\osalh\Desktop\pythonProject\main.py"
objShell.Run PythonExePath & PythonScriptPath
Application.Goto Reference:="RunPythonScript"
End Sub
   


After running the above code the output is given in the cmd file as follows:
   

How to have the output in an Excel cell?
Larz60+ write Jun-25-2022, 10:17 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use tags on future projects.
Reply
#2
Thanks, Larz60+

Now I know Cool
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,251 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  export into excel, how to implement pandas into for-loop deneme2 6 2,726 Sep-01-2022, 05:44 AM
Last Post: deneme2
  How to keep columns header on excel without change after export data to excel file? ahmedbarbary 0 1,245 May-03-2022, 05:46 PM
Last Post: ahmedbarbary
  HELP on Unwanted CSV Export Output | Using Selenium to Scrape soothsayerpg 0 1,323 Jun-13-2021, 12:23 PM
Last Post: soothsayerpg
  Need help with saving output into an excel file Beyondfacts 4 3,091 Mar-22-2021, 11:51 AM
Last Post: jefsummers
  Python script to summarize excel tables, then output a composite table? i'm a total n surfer349 1 2,482 Feb-05-2021, 04:37 PM
Last Post: nilamo
  How to export from Python to Excel? jpy 4 6,533 Dec-23-2020, 03:26 PM
Last Post: jpy
  Skeleton file export error Python Code pepapoha 4 3,664 Nov-17-2020, 02:06 AM
Last Post: pepapoha
  Python Export Question Below samlee916 1 1,639 Jul-07-2020, 12:22 PM
Last Post: Larz60+
  Save output into a Excel Sheet with Format Table skaailet 1 2,575 Apr-17-2020, 11:56 PM
Last Post: thirteendec

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020