Smartsheet Python API Apply Wrap Text and Center Alignment from Column 1 to column 40 in a series of sheets

  Kiến thức lập trình

I have approximately 75 sheets distributed in different folders and subfolders inside a folder. I’ve built a script that iterates in each sheet successfully, but i’m failing at achieving that in each sheet, from column 1 to column 40, the “wrap text” format is applied and the center alignment is applied.

i’ve written this code trying to achieve my requirements. I’ve already tested that my credentials are working fine.

import smartsheet

access_token = '12345678' 
client = smartsheet.Smartsheet(access_token)

def update_columns(sheet_id):
    try:
        sheet = client.Sheets.get_sheet(sheet_id)
        columns_to_update = []

        for column in sheet.columns[:40]:  # iterates from col 1 to col 38
            # Create a new Column object with the necessary fields
            updated_column = smartsheet.models.Column({
                'id': column.id,
                'wrap': True  # Activa el formato wrap text
            })
            columns_to_update.append(updated_column)

        if columns_to_update:
            # Print the payload for debugging
            print(f"Updating columns in sheet {sheet_id}: {columns_to_update}")
            response = client.Sheets.update_column(sheet_id, columns_to_update)
            if response.message == 'SUCCESS':
                print(f"Wrapped text in columns 1 to 38 in sheet {sheet.name}")
            else:
                print(f"Failed to wrap text in columns in sheet {sheet.name}: {response}")
        else:
            print(f"No columns to update found in sheet {sheet.name}")

    except Exception as e:
        print(f"An error occurred while trying to update columns in sheet {sheet_id}: {e}")

def process_folder(folder_id):
    folder = client.Folders.get_folder(folder_id)
    sheets = folder.sheets

    # Itera sobre cada hoja y actualiza las columnas
    for sheet in sheets:
        sheet_id = sheet.id
        update_columns(sheet_id)

    # Itera sobre cada subcarpeta y procesa sus hojas
    subfolders = folder.folders
    for subfolder in subfolders:
        process_folder(subfolder.id)

def wrapTextInColumns(folder_id):
    print("WELCOME TO THE SHEET FORMATTING SCRIPT IN SMARTSHEET")
    process_folder(folder_id)
    print("Columns wrapped successfully.")

wrapTextInColumns('6539073457284996') #the id of my folder.

the error i’m getting in python is as follows
An error occurred while trying to update columns in sheet 7993024508284804: Sheets.update_column() missing 1 required positional argument: 'column_obj' .

the detailed error log is as follows:

Updating columns in sheet 123456: [<smartsheet.models.column.Column object at 0x00000252ED6E61E0>, <smartsheet.models.column.Column object at 0x00000252ED75DB50>, <smartsheet.models.column.Column object at 0x00000252ED75E000>, <smartsheet.models.column.Column object at 0x00000252ED75E4B0>, <smartsheet.models.column.Column object at 0x00000252ED75E960>, <smartsheet.models.column.Column object at 0x00000252ED75EE10>]
An error occurred while trying to update columns in sheet 123456: Sheets.update_column() missing 1 required positional argument: 'column_obj'
Updating columns in sheet 654789: [<smartsheet.models.column.Column object at 0x00000252ED63D0D0>, <smartsheet.models.column.Column object at 0x00000252ED73E480>, <smartsheet.models.column.Column object at 0x00000252ED73E930>, <smartsheet.models.column.Column object at 0x00000252ED73EDE0>, <smartsheet.models.column.Column object at 0x00000252ED73F290>, <smartsheet.models.column.Column object at 0x00000252ED73F740>]
An error occurred while trying to update columns in sheet 654789: Sheets.update_column() missing 1 required positional argument: 'column_obj'
Columns wrapped successfully.

2

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT