KKL
KKL

Reputation: 85

How to ignore "Enable Editing" in excel after writing data using openpyxl

I am using a Excel template which have 6 tabs (All unprotected) and writing the data on each worksheet using openpyxl module. Once the excel file is created and when tried to open the generated file, its not showing all data untill and unless I click "Enable editing" pop up.

Is there any attribute to disable in openpyxl.

Upvotes: 1

Views: 2446

Answers (2)

james wilson
james wilson

Reputation: 21

I solved this for me.

I found the answer here: https://codereview.stackexchange.com/questions/240136/python-script-for-refreshing-and-preprocessing-data-in-excel-report-files

I only used the refresh function and it basically opened the excel file, click/refreshed, and closed/saved. You see an Excel file appear briefly on the screen. I'll insert this in a loop to go through all the files I am creating. It might take a little while to run hundreds, but much faster than open-click-save.

Here is all the code I used:

import win32com.client as win32

def refresh(directory, file_name):
    xlapp = win32.DispatchEx('Excel.Application')
    xlapp.DisplayAlerts = False
    xlapp.Visible = True
    xlbook = xlapp.Workbooks.Open(directory + '\\' + file_name)
    xlbook.RefreshAll()
    xlbook.Save()
    xlbook.Close()
    xlapp.Quit()

    return()

Upvotes: 2

Charlie Clark
Charlie Clark

Reputation: 19527

This sounds like Windows has quarantined files received over a network. As this is done when the files are received, there is no way to avoid this when creating the files.

Upvotes: 1

Related Questions