Python Forum
Read and write active Excel file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Read and write active Excel file
#2
You can, and save in place, but that's not the proper way to do it because if you make a mistake, you will have overwritten you original spreadsheet.
Instead save to a new spreadsheet and when satisfied, you can rename it.

Example:
from openpyxl import load_workbook

excelfile = 'runways.xlsx'                # modify to your spreadsheet name
excelout = 'ModifiedRunways.xlsx'   # ditto

wb = load_workbook(excelfile)
sheet_ranges = wb['runways']        # modify to your sheet name
print(sheet_ranges['F2'].value)

sheet_ranges['F2'] = 'New Guy'

wb.save(excelout)
Reply


Messages In This Thread
Read and write active Excel file - by euras - Jun-27-2021, 07:58 PM
RE: Read and write active Excel file - by Larz60+ - Jun-28-2021, 09:42 AM
RE: Read and write active Excel file - by Larz60+ - Jun-29-2021, 03:42 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Connecting to Remote Server to read contents of a file ChaitanyaSharma 1 210 May-03-2024, 07:23 AM
Last Post: Pedroski55
  What does .flush do? How can I change this to write to the file? Pedroski55 3 286 Apr-22-2024, 01:15 PM
Last Post: snippsat
  Python openyxl not updating Excel file MrBean12 1 374 Mar-03-2024, 12:16 AM
Last Post: MrBean12
  Copy Paste excel files based on the first letters of the file name Viento 2 478 Feb-07-2024, 12:24 PM
Last Post: Viento
  Last record in file doesn't write to newline gonksoup 3 479 Jan-22-2024, 12:56 PM
Last Post: deanhystad
  Recommended way to read/create PDF file? Winfried 3 2,945 Nov-26-2023, 07:51 AM
Last Post: Pedroski55
  write to csv file problem jacksfrustration 11 1,618 Nov-09-2023, 01:56 PM
Last Post: deanhystad
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 1,549 Nov-09-2023, 10:56 AM
Last Post: mg24
  Search Excel File with a list of values huzzug 4 1,300 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Updating sharepoint excel file odd results cubangt 1 899 Nov-03-2023, 05:13 PM
Last Post: noisefloor

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020