Update an Excel sheet in real time using Python

0 votes

Is it possible to update a spreadsheet open in Excel in real-time? I have the following Python code that tries to update cell B1 with the text "ID" in an Excel worksheet called Example.xlsx:

import openpyxl

wb = openpyxl.load_workbook('Example.xlsx')
sheet = wb['Sheet']
sheet['B1'] = 'ID'

wb.save('Example.xlsx')

On running the script I get this error:

PermissionError: [Errno 13] Permission denied: 'Example.xlsx'. I'm aware that this is the case because Excel is currently opening the file, but I was wondering if there was another method or module I could use to update a sheet while it is open.

Nov 13 in Others by Kithuzzz
• 20,660 points
51 views

1 answer to this question.

0 votes

Using xlwings, I have really discovered how to do this, and it is very straightforward. The code that follows accesses Example.xlsx, an existing Excel file, and updates it in real-time. In this case, it immediately enters the number 45 in cell B2 when you run the script.

import xlwings as xw

wb = xw.Book('Example.xlsx')
sht1 = wb.sheets['Sheet']
sht1.range('B2').value = 45
answered Nov 13 by narikkadan
• 37,660 points

Related Questions In Others

0 votes
1 answer

Calculate Birthdate from an age using y,m,d in Excel

Hello, yes u can find your birthdate using ...READ MORE

answered Feb 16 in Others by Edureka
• 13,640 points
140 views
0 votes
1 answer

Calculate Birthdate from an age using y,m,d in Excel

Hi To Calculate the date, we can ...READ MORE

answered Feb 16 in Others by Edureka
• 13,640 points
238 views
0 votes
1 answer

Removing specific rows in an Excel file using Azure Data Factory

Under the 'Source' tab, choose the number ...READ MORE

answered Sep 23 in Others by narikkadan
• 37,660 points
213 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 3,136 views
0 votes
1 answer
0 votes
1 answer

How to print an Excel Sheet using VBA with Nitro PDF Creator in Excel 2016

you can use the built-in excel facilities ...READ MORE

answered Sep 24 in Others by narikkadan
• 37,660 points
117 views
0 votes
1 answer

Format an Excel Sheet in Python

The below code will help you refer ...READ MORE

answered Nov 6 in Others by narikkadan
• 37,660 points
39 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP