- В столбце «Клиенты» у меня уже есть список клиентов
- В столбце «Товар» я хочу, чтобы код добавлял 5 строк под каждым клиентом с названиями нужных мне товаров, например
* Customer * * ITEM *
строка 2 Магазин
строка 3 Логистика
строка 4 Постройки
строка 5 Картография
строка 6 Мультфильм
строка 7 Офис 2
строка 8 Магазин
строка 9 Логистика
строка 10 Конструкций
строка 11 Сопоставление
строка 12 Мультфильм
Однако, когда я запускаю свой код, он говорит, что строки успешно добавлены для всех клиентов с указанными элементами. Но по какой-то причине в smartsheet мои данные не отображаются?
# 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.")
Подробнее здесь: https://stackoverflow.com/questions/792 ... ot-working
Мобильная версия