Python- how do I write user input to an Excel file?

kittenparade

I'm new to Python so I hope this sounds right. How could I use Python to write to an Excel file from user input? I want my script to ask users "Name:" "Job Title:" "Building Number:" "Date:" etc. and from that raw input, fill in the corresponding columns one after the other in an Excel spreadsheet. I don't want future use of the script to overwrite previous data in the sheet either. I'd like each time to create a new line in the spreadsheet and then fill in the correct entries in each row. I hope that makes sense. Thank you so much in advance for your help.

SuperNova

You could use openpyxl to write to the workbook. Here's some basic usage, and should help avoid overwriting:

import openpyxl
wb = openpyxl.load_workbook('C:/test.xlsx')
ws = wb.active
i = 0
cell_val = ''
# Finds which row is blank first
while cell_val != '':
    cell_val = ws['A' + i].value
    i += 1
# Modify Sheet, Starting With Row i
wb.save('C:/test.xlsx')

Hope This Helps.

Edited, getting input and time:

For getting information from the user, use

x = input('Prompt: ')

However, if you want the actual current, I suggest using the time module:

>>> from time import strftime
>>> date = strftime('%m-%d-%y')
>>> time = strftime('%I:%M%p')
>>> print(date)
08-28-15
>>> print(time)
01:57AM

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I read user input and write it to a .txt. file?

How do i write the users input in a file in python?

Python How do I write a user provided IP address to a file?

How do I write a python dictionary to an excel file?

How to write a user defined function and perform an operation in python which takes input from a single column of excel file?

How do i validate a user input in python?

How do I add a PHP code that will always open/create a new text file and write user input once user clicks 'Submit' button

How do I use the user input to write the output using Tkinter?

How do I write a shell script called myedit which asks the user to input a file name, and then starts up an editor to edit that file

In python, how do I call upon excel sheet column to match a user input?

How do i write to a database by taking user input from a GUI and storing that user input into a database in java?

How do i Hide excel while performing read and write into the file using xlwings or openpyxl package in python

How do I access a file in a sub-directory on user input without having to state the directory in Python 2.7.11?

How do I match an user input to username in my txt file in Python?

How do I write a number as a string to an Excel file?

How do i write a dictionary containing dictionaries to an excel file

How do I send input() to a file that can be accessed and changed by user?

How do I read a file as the default user input?

How do I write the fizzbuzz function in Python 3 with an input value?

write user input to a file

How do I get user input from discord chat in python?

How do I get the user to input a number in Python 3?

How do I gather user numerical input into a list in Python?

How do I make a loop for user input in python?

How do I check user input against multiple lists python?

How do I get Python to print from 1 to user input?

How do I run a python file that takes a text file as input?

How do I write/create a GeoTIFF RGB image file in python?

Python - How do I write an array to a text file?