[英]How write text on an existing xlsx file with the help of openpyxl on python?
Most of the tutorials are outdated and I am unsuccessful at writing on an xlsx file with the help of python.大多数教程已经过时,我在 python 的帮助下无法成功编写 xlsx 文件。
Here is some code I used:这是我使用的一些代码:
import openpyxl
wb = openpyxl.load_workbook('C:/Users/user/Desktop/pytranslate.xlsx')
path = 'C:/Users/user/Desktop/pytranslate.xlsx'
ws = wb['Sheet1']
ws.cell(row = 1,column = 1,value = 'need for meas')
val1 = ws['A1'].value
print(val1)
wb.save(path)
The program ends with no error but I cannot see any output on the xlsx file.程序结束时没有错误,但我在 xlsx 文件上看不到任何输出。
I used this code to test.我用这段代码来测试。 I created an empty excel document first.
我首先创建了一个空的 excel 文档。 It updated correctly.
它正确更新。
import openpyxl
path = 'pytranslate.xlsx'
wb = openpyxl.load_workbook(path)
ws = wb['Sheet1']
ws.cell(row = 1,column = 1,value = 'need for meas')
val1 = ws['A1'].value
print(val1)
wb.save(path)
Output (excel)输出(excel)
If your document is not updating, confirm you have correct permissions to the file and folder.如果您的文档没有更新,请确认您对该文件和文件夹具有正确的权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.