python - create a copy of xlsx file having all formula's within removed -


can't copy xlsx , xlsm files xlrd says "formatting info= true" not yet implemented , openpyxl runs out of memory when doing following:

import xlrd xlutils.copy import copy openpyxl import load_workbook  if file_format == 'xls':         input_file=xlrd.open_workbook(input_file_location,formatting_info=true)         wb = copy(input_file)         wb.save(destination_file) if file_format == 'xlsx' or file_format == 'xlsm' :         input_file  =  load_workbook(input_file_location,data_only=true)         input_file.save(destination_file) 

if want copy file using shutil. there still several things openpyxl doesn't support such images , charts lost. and, you're seeing, memory issue. each cell uses 45 kb of memory.

the openpyxl documentation pretty clear different options used when opening workbooks: data_only read results of formulae , ignore formulae.

see https://bitbucket.org/openpyxl/openpyxl/issue/171/copy-worksheet-function if want copy worksheets.

otherwise can use 2 workbooks, 1 in read-only mode , other in write-only mode. if want copy, best done in file system.

if want copy values 1 workbook can combine read-only , write-only modes reduce memory footprint. following pseudo-code should give basis.

wb1 = load_workbook("file.xlsx", read_only=true, data_only=true) wb2 = workbook(write_only=true) ws1 in wb1:     ws2 = wb2.create_sheet(ws1.title)     r1 in ws1:         ws2.append(r1) # might need unpacking use values wb2.save("copy.xlsx") 

Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -