簡體   English   中英

使用openpyxl寫入數據后如何忽略excel中的“啟用編輯”

[英]How to ignore “Enable Editing” in excel after writing data using openpyxl

我正在使用一個 Excel 模板,它有 6 個選項卡(全部不受保護),並使用 openpyxl 模塊在每個工作表上寫入數據。 創建 excel 文件后,當嘗試打開生成的文件時,它不會顯示所有數據,除非我單擊“啟用編輯”彈出窗口。

在 openpyxl 中是否有任何要禁用的屬性。

這聽起來像 Windows 已隔離通過網絡接收的文件。 由於這是在收到文件時完成的,因此在創建文件時無法避免這種情況。

我為我解決了這個問題。

我在這里找到了答案: https://codereview.stackexchange.com/questions/240136/python-script-for-refreshing-and-preprocessing-data-in-excel-report-files

我只使用了刷新function,它基本上打開了excel文件,單擊/刷新,然后關閉/保存。 您會看到 Excel 文件短暫出現在屏幕上。 我將通過我正在創建的所有文件將其插入到 go 的循環中。 運行數百個可能需要一點時間,但比打開點擊保存要快得多。

這是我使用的所有代碼:

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()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM