我正在使用 xlsxwriter 工具将一些数据从用户输入写入 .xlsx。(总的来说,我对编程很陌生,如果我的代码很糟糕,我很抱歉,如果您建议/纠正我犯的任何错误,我们将不胜感激!对不起!)
以下是执行此操作的当前代码:
但是,我在将数据写入新行而不是替换前一行时遇到了一些问题,因此 .xlsx 最终成为用户数据的集合。
import getpass
import os
import xlsxwriter
print('Hello, please answer the follow questions to complete your registration.')
userfirstname = input('Please enter your FIRST name.\n')
print('Thank you, %s' % userfirstname, )
userlastname = input('Please enter your LAST name.\n')
print('Thank you %s' % userfirstname, '%s' % userlastname)
userage = input('Please enter your AGE.\n')
print('Thank you %s' % userfirstname, '%s' % userlastname)
username = input('Please enter your desired USER NAME.\n')
print('Thank you %s' % userfirstname, '%s' % userlastname, 'Your chosen username is %s' % username)
#Within this section, a database scan must take place to check current used usernames and text match
userpwd = getpass.getpass('Please enter your desired PASSWORD.\n')
print('Thank you %s' % userfirstname, '%s' % userlastname)
#within this section, a application password authentication must take place to fit password criteria
usermailid = input('Please enter the email address you wish to register with.\n')
print('Your chosen registration email address is: %s' % usermailid)
#Within this section, a database scan must take place to check current registered mail addresses and text match
#User Database .xlsx
workbook =xlsxwriter.Workbook('UserDatabase.xlsx')
worksheet = workbook.add_worksheet()
worksheet.set_column('A:A',20)
worksheet.set_column('B:B',20)
worksheet.set_column('C:C',20)
worksheet.set_column('D:D',20)
worksheet.set_column('E:E',20)
worksheet.set_column('F:F',20)
worksheet.write('A1', 'First Name')
worksheet.write('B1', 'Last Name')
worksheet.write('C1', 'Age')
worksheet.write('D1', 'User Name')
worksheet.write('E1', 'Password')
worksheet.write('F1', 'Email ID')
worksheet.write_string( , userfirstname)
worksheet.write_string('', userlastname)
worksheet.write_string('', userage)
worksheet.write_string('', username)
worksheet.write_string('', userpwd)
worksheet.write_string('', usermailid)
workbook.close()
因此,从这里开始,使用列标题创建了一个可爱的 .xlsx,并且用户数据对第二行进行了很好的处理,但是在 worksheet.write_string( 部分我需要知道如何指定如何将字符串写入新行或者可能是一些条件格式,比如“如果该行已经包含文本,则写入下一个空闲行”等。
如果您知道比 xlsxwriter 更好的工具,请随时告诉我!
谢谢 :)