Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88081

How to refresh excel file on a machine which doesn't have Microsoft excel installed (Python)

$
0
0

I have this excel file which is of around 37MB. I am reading the file pd.read_excel() and update specific sheets of the excel with openpyxl and write back. Once it is written, the file size reduces to 16MB. The file contains functions in some of the sheets. But, when the file is updated once, I am unable to read the values from the sheets which I read values earlier. I think, this is because the functions do not get updated after the write. If, I open the file and save the file again, the values are readable.

I have been looking for methods to refresh the excel file after write. But, all the methods found requires excel installed in the machine. Would like to know whether there is a way we can refresh an excel file without opening the file with python.

I am updating the file as follows:

        # new dataframe with same columns
        df = data_frame
        writer = pd.ExcelWriter(folder_path, engine='openpyxl')
        # try to open an existing workbook
        writer.book = op.load_workbook(folder_path)
        # copy existing sheets
        writer.sheets = dict((ws.title, ws) for ws in writer.book.worksheets)
        # read existing file
        reader = pd.read_excel(folder_path, sheet_name=sheet_name)
        reader = reader.dropna(axis=0, how='all', thresh=None, subset=None, inplace=False)
        # write out to the sheet
        df.to_excel(writer, sheet_name=sheet_name, index=False, header=False, startrow=len(reader) + 2)
        writer.save()

Viewing all articles
Browse latest Browse all 88081

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>