Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Save and Close Excel File
#1
Hello,

I'm not an expert in regards to coding but I've been coding for a bit and leverage that skillset in my day to day work.

Recently started learning python and currently using it to automate some word and pdf documents that need to be updated several times throughout the year.

I've managed to get all of my code and it is working beautifully. However, because most of the people in my area are not really tech savvy I'm building this tool so it can be controlled through an excel document.

I implemented that change successfully but as I plan on calling the code through a macro from the excel document I need to add code that saves and closes the workbook before the rest of the code starts creating the word and pdf files.

Found save and close modules within the openpyxl library but haven't been able to implement those. Here is the first section of my code where I need to save and close the file:

import os, sys
from docxtpl import DocxTemplate
from docx2pdf import convert
import openpyxl
from openpyxl import Workbook
import pandas as pd

os.chdir(sys.path[0])

 
xls = pd.ExcelFile("test.xlsx")
wb = Workbook("test.xlsx")

#Save and Close the excel file.
wb.save()
wb.close()

#Tried the syntax below and it didn't work either.
#Workbook.save(wb)
#Workbook.close(wb)
I've looked for a solution online but I seem to come across more elaborated examples tailored to specific needs. I just need to figure out the simplest way to save and close the file. Any help or guidance would be appreciated.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python openyxl not updating Excel file MrBean12 1 342 Mar-03-2024, 12:16 AM
Last Post: MrBean12
  Copy Paste excel files based on the first letters of the file name Viento 2 454 Feb-07-2024, 12:24 PM
Last Post: Viento
  Open/save file on Android frohr 0 337 Jan-24-2024, 06:28 PM
Last Post: frohr
  Search Excel File with a list of values huzzug 4 1,263 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Updating sharepoint excel file odd results cubangt 1 854 Nov-03-2023, 05:13 PM
Last Post: noisefloor
  how to save to multiple locations during save cubangt 1 560 Oct-23-2023, 10:16 PM
Last Post: deanhystad
  save values permanently in python (perhaps not in a text file)? flash77 8 1,249 Jul-07-2023, 05:44 PM
Last Post: flash77
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,115 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  Trying to access excel file on our sharepoint server but getting errors cubangt 0 822 Feb-16-2023, 08:11 PM
Last Post: cubangt
  Import XML file directly into Excel spreadsheet demdej 0 859 Jan-24-2023, 02:48 PM
Last Post: demdej

Forum Jump:

User Panel Messages

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