After processing the spreadsheet in Python, OnlyOffice macros disappear

I work with Nextcloud files via WebDAV. After writing data to an XLSX spreadsheet using Python and uploading the file back to Nextcloud, all OnlyOffice macros disappear. Can you help solve this problem?

Hello @Ars,
Could you describe the step-by-step action scenario? We would like to understand in more detail how exactly you are writing data to the file.
Also, please specify the version of OnlyOffice, the version of Nextcloud, and the version of the connector.

Hello, @Roman ,
Here is part of Python script:
def copy_data_between_excel_files(source_file_obj, source_sheet, target_file_obj, target_sheet):
# Open source file (read formulas as values)
source_wb = openpyxl.load_workbook(source_file_obj, data_only=True) # data_only=True reads only values
source_ws = source_wb[source_sheet] # Get source sheet

# Open target file or create a new one if it doesn't exist
try:
    target_wb = openpyxl.load_workbook(target_file_obj)  # Load target file
except:
    target_wb = openpyxl.Workbook()  # Create new workbook if file not found

# Remove target sheet if exists, else create a new one
if target_sheet in target_wb.sheetnames:
    target_wb.remove(target_wb[target_sheet])  # Remove old sheet
target_ws = target_wb.create_sheet(title=target_sheet)  # Create new sheet

# Copy data (values only) from source to target sheet
for row in source_ws.iter_rows():  # Iterate over rows in source sheet
    for cell in row:  # Iterate over each cell in row
        new_cell = target_ws.cell(row=cell.row, column=cell.column, value=cell.value)  # Copy cell value

# Save updated file to memory buffer
updated_target_buffer = BytesIO()  # Create buffer for updated file
target_wb.save(updated_target_buffer)  # Save workbook to buffer
updated_target_buffer.seek(0)  # Reset buffer pointer

return updated_target_buffer  # Return buffer containing updated file

Define file paths and sheet names

source_file = download_file_from_nextcloud(‘file1.xlsx’) # Download source file
source_sheet = ‘sheet1’ # Source sheet name
target_file = download_file_from_nextcloud(‘file2.xlsx’) # Download target file
target_sheet = ‘sheet2’ # Target sheet name

Perform the copy

updated_target = copy_data_between_excel_files(source_file, source_sheet, target_file, target_sheet)

Upload updated file back to Nextcloud

upload_file_to_nextcloud(updated_target, ‘file2.xlsx’) # Upload updated file

Onlyoffice ver. 8.0.1.31, NC ver. 30.0.5