简体   繁体   English

Python 编辑和更新 Excel/Csv 文件

[英]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.例如,A4 或 B8 或 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.我相信最简单的方法是创建一个 CSV 文件并在 Python 中引用该文件并更新它。 But I am having troubles doing it.但我在做这件事时遇到了麻烦。 Can I get some help?我能得到一些帮助吗? I am using Spyder/anaconda.我正在使用 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.我建议使用openpyxl库。 You can use this to get and edit values in a csv or spreadsheet.您可以使用它来获取和编辑 csv 或电子表格中的值。 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')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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