简体   繁体   中英

Python Editing and Updating Excel/Csv File

So I am trying to create a program that will give me the next value in a sequence for a certain letter. For instance, A4 or B8 or C23. I believe the easiest way to do this would be to create a CSV file and reference that file in Python and update it. But I am having troubles doing it. Can I get some help? I am using Spyder/anaconda. the program will ask what letter the user wants and it will give the next value in that letter's sequence.

I'd recommend using the openpyxl library. You can use this to get and edit values in a csv or spreadsheet. You can use it like this:

from openpyxl import load_workbook
wb = load_workbook(filename = 'yourSpreadsheet.xlsx') #select file
ws = wb.active #select worksheet
a4 = ws['A4'] #get contents of cell A4
ws['A5'] = a4 + 1 #set cell A5 to the value of cell A4+1
wb.save('resultSheet.xlsx')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM