Python Forum
Need Help writing data into Excel format
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need Help writing data into Excel format
#1
I have the below code. I have one counter. if counter less than value set value It should write the value into excel.
in below code I could see counter printing 0 and hangs

The filed column should be written only once
I wanted to write into excel per 1S time sleep
Counter has to increment every time and save into SL no


I have used pyscripter 4

import csv
import datetime
import time
from datetime import datetime

filename = "TestFormat.csv"
fields = ['SLNo', 'Date','Time', 'RData', 'BData','GData','IRdata']


def main():
   count=0
   while(count<10):
        print("Counter:",count)
        now = datetime.now()
        Sln0=count
        date_Format=now.strftime('%Y/%m/%d ')
        current_time = now.strftime("%I:%M:%S")
        with open(filename, 'a+') as csvfile:
            csvwriter = csv.writer(csvfile)
            csvwriter.writerow(fields)
            csvwriter.writerow([Sln0,date_Format,current_time])
        csvfile.close()
   count=count+1

if __name__ == '__main__':
    main()
    time.sleep(1)
Reply


Messages In This Thread
Need Help writing data into Excel format - by ajitnayak87 - Feb-03-2022, 04:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with writing monitored data to mysql upon change of one particular variable donottrackmymetadata 3 338 Apr-18-2024, 09:55 PM
Last Post: deanhystad
  Export data from PDF as tabular format zinho 5 750 Nov-11-2023, 08:23 AM
Last Post: Pedroski55
  Copy data from Excel and paste into Discord (Midjourney) Joe_Wright 4 2,132 Jun-06-2023, 05:49 PM
Last Post: rajeshgk
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,143 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  How to properly format rows and columns in excel data from parsed .txt blocks jh67 7 1,950 Dec-12-2022, 08:22 PM
Last Post: jh67
  Issue in writing sql data into csv for decimal value to scientific notation mg24 8 3,127 Dec-06-2022, 11:09 AM
Last Post: mg24
  Trying to Get Arduino sensor data over to excel using Python. eh5713 1 1,758 Dec-01-2022, 01:52 PM
Last Post: deanhystad
  Appending a row of data in an MS Excel file azizrasul 3 1,214 Nov-06-2022, 05:17 PM
Last Post: azizrasul
  Moving data from one Excel to another and finding maximum profit azizrasul 7 1,514 Oct-06-2022, 06:13 PM
Last Post: azizrasul
  Create a function for writing to SQL data to csv mg24 4 1,217 Oct-01-2022, 04:30 AM
Last Post: mg24

Forum Jump:

User Panel Messages

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