M
M
mrk_sn2021-07-08 19:27:15
Python
mrk_sn, 2021-07-08 19:27:15

How can I change the text color to white only for duplicate values?

I have a two-dimensional text array and I need the resulting table to have only the first elements of those that are repeated. But it is also necessary that the filter by column works. I came up with the idea of ​​painting them white so they can't be seen, but the filter worked (weird solution, but working). How can I implement this if I cannot know the end cell numbers of these elements?

import httplib2
import apiclient
from oauth2client.service_account import ServiceAccountCredentials

def tableCreate(used, noUsed, maximum):
    resUsed = []
    for line in used:
        for i in range(len(line)):
            if line[i] != line[-1]:
                if line[i] not in resUsed:
                    resUsed.append(line[i])
                    print(line[i])
                else:
                    if line[i] in resUsed:
                        line[i] = "white" #эти элементы должны быть белыми
                        print(line[i])
        while len(line) < maximum:
            line.insert(-1, "")
                

    
    
    CREDENTIALS_FILE = 'used-ui-interface-12832559428d.json'  

    credentials = ServiceAccountCredentials.from_json_keyfile_name(CREDENTIALS_FILE, ['https://www.googleapis.com/auth/spreadsheets', 'https://www.googleapis.com/auth/drive'])

    httpAuth = credentials.authorize(httplib2.Http()) # Авторизуемся в системе
    service = apiclient.discovery.build('sheets', 'v4', http = httpAuth) 

    spreadsheet = service.spreadsheets().create(body = {
        'properties': {'title': 'Выгрузка', 'locale': 'ru_RU'},
        'sheets': [{'properties': {'sheetType': 'GRID',
                                   'sheetId': 0,
                                   'title': 'Используемые',
                                   'gridProperties': {'rowCount': len(used), "columnCount": maximum}}}]
    }).execute()
    spreadsheetId = spreadsheet['spreadsheetId'] 
    print('https://docs.google.com/spreadsheets/d/' + spreadsheetId)

    driveService = apiclient.discovery.build('drive', 'v3', http = httpAuth) 
    access = driveService.permissions().create(
        fileId = spreadsheetId,
        body = {'type': 'user', 'role': 'writer', 'emailAddress': '[email protected]'}, 
        fields = 'id'
    ).execute()


    results = service.spreadsheets().values().batchUpdate(spreadsheetId = spreadsheetId, body = {
        "valueInputOption": "USER_ENTERED", 
        "data": [
            {"range": "Используемые!A1",
             "majorDimension": "ROWS",    
             "values": used}
        ]
    }).execute()

    results = service.spreadsheets().batchUpdate(
        spreadsheetId=spreadsheetId,
        body=
        {
            "requests": [
                {
                    "addSheet": {
                        "properties": {
                            "title": "Не используемые",
                            "gridProperties": {
                                "rowCount": len(noUsed),
                                "columnCount": 1
                            }
                        }
                    }
                }
            ]
        }).execute()

    results = service.spreadsheets().values().batchUpdate(spreadsheetId=spreadsheetId, body={
        "valueInputOption": "USER_ENTERED",
        "data": [
            {"range": "Не используемые!A1",
             "majorDimension": "COLUMNS",  
             "values": noUsed}
        ]
    }).execute()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question