write to an open exceldocument

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 16:11:08

问题


I'm working on a project which I am going to write values to a exceldocument. I can write values to excel but I want to write the values to excel with the document open. If i have the doc open when trying to write to it i get an error message.

Here is my code I'm currently using.

#Write to excel
from openpyxl import Workbook

import datetime

wb = Workbook()

ws = wb.active

ws['C3'] = 1337

ws['A1'] = datetime.datetime.now()

ws['B5'] = CIRCLES
ws['B4'] = "Red puck"
wb.save("sample.xlsx")

And the error message when i have the doc. opened when trying to write to it.

Traceback (most recent call last):
  File "C:\Users\RU21\Desktop\Röda puckar\Förbindelse med RR.py", line 302, in <module>
    wb.save("sample.xlsx")
  File "C:\Python27\lib\site-packages\openpyxl\workbook\workbook.py", line 280, in save
    save_workbook(self, filename)
  File "C:\Python27\lib\site-packages\openpyxl\writer\excel.py", line 211, in save_workbook
    writer.save(filename)
  File "C:\Python27\lib\site-packages\openpyxl\writer\excel.py", line 193, in save
    archive = ZipFile(filename, 'w', ZIP_DEFLATED)
  File "C:\Python27\lib\zipfile.py", line 756, in __init__
    self.fp = open(file, modeDict[mode])
IOError: [Errno 13] Permission denied: 'sample.xlsx'

来源:https://stackoverflow.com/questions/26141114/write-to-an-open-exceldocument

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!