I have a sheet where i have 2 columns. I have Customer and Item.
In Customer Column I have a list of customers already
In Item column I want the code to add 5 rows under each customer with item names that i want for example
* Customer * * ITEM *
row 1 Office
row 2 Shop
row 3 Logistics
row 4 Constructions
row 5 Mapping
row 6 Cartoon
row 7 Office 2
row 8 Shop
row 9 Logistics
row 10 Constructions
row 11 Mapping
row 12 Cartoon
However, when ever I am running my code it says Rows added successfully for all customers with the specified items. But for some reason in smartsheet my data doesn't show up?
# Specify the sheet ID
sheet_id = ''
# Define column IDs
CUSTOMER_COLUMN_ID = ''
ITEM_COLUMN_ID = ''
# Define the specific items to add under each customer
specific_items = [
"Shop",
"Construction",
"Manager",
"Logistics",
"Load"
]
# Fetch the existing sheet
sheet = ss_client.Sheets.get_sheet(sheet_id)
# Collect unique customers from the current data
unique_customers = set()
for row in sheet.rows:
for cell in row.cells:
if cell.column_id == CUSTOMER_COLUMN_ID and cell.value:
unique_customers.add(cell.value)
# Prepare new rows to add for each customer
rows_to_add = []
for customer in unique_customers:
for item in specific_items:
new_row = ss_client.models.Row()
new_row.to_bottom = True # Add to the bottom of the sheet
# Create cells for each column
new_row.cells.append({
'column_id': CUSTOMER_COLUMN_ID,
'value': customer
})
new_row.cells.append({
'column_id': ITEM_COLUMN_ID,
'value': item
})
rows_to_add.append(new_row)
# Add the new rows in chunks
chunk_size = 300
for start in range(0, len(rows_to_add), chunk_size):
response = ss_client.Sheets.add_rows(sheet_id, rows_to_add[start:start + chunk_size])
if response.message:
print(response.message) # Print the response message
print("Rows added successfully for all customers with the specified items.")