我正在使用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更好的工具,请随时告诉我!
谢谢:)