如何使用python 2.7锁定gspread中的单元格

时间:2018-10-02 17:17:57

标签: python gspread

我试图弄清楚如何使用python编程地锁定Google表格单元格。我的目标是在单元达到400后锁定该单元。应该发生的事情是,每当一项活动中有400个发生时,都应重写html代码,从而执行finalForm.write(l)finalForm.write(l)停止将原始html写入新文件。如果"<option value = 'Games'>Game</option>" not in l:会这样。如果你们需要全部236行代码(整个程序),我很乐意上传它,但我希望这是一个好的起点。以下是我的代码的一部分。

for y in sheet.col_values(9):
            if y == '':
                pass
            if y >= "400":  #Change number for cap
                cell = sheet.find(str(y))
                row_num = cell.row
                col_num = cell.col - 1
                nextCellOver = sheet.cell(row_num, col_num).value
                # print nextCellOver
                if nextCellOver == "Games":
                    print "got to if"
                    with open('templates/form.html', 'r') as myForm:
                        lines = myForm.readlines()
                        myForm.close()
                    with open('templates/form.html', 'w') as finalForm:
                        for l in lines:
                            if "<option value = 'Games'>Game</option>" not in l:
                                finalForm.write(l)
                                rowplus = 1
                            else:
                                print "deletion complete: Games"
                        cap = 1
                        finalForm.close()
                        pass
                if nextCellOver == "Sports":
                    print "got to if"
                    with open('templates/form.html', 'r') as myForm:
                        lines = myForm.readlines()
                        myForm.close()
                    with open('templates/form.html', 'w') as finalForm:
                        for l in lines:
                            if "<option value = 'Sports'>Sports</option>" not in l:
                                finalForm.write(l)
                                rowplus = 1
                            else:
                                print "deletion complete: Sports"
                        cap = 1
                        finalForm.close()
                        pass
                if nextCellOver == "Creativity":
                    print "got to if"
                    with open('templates/form.html', 'r') as myForm:
                        lines = myForm.readlines()
                        myForm.close()
                    with open('templates/form.html', 'w') as finalForm:
                        for l in lines:
                            if "<option value = 'Creativity'>Creativity</option>" not in l:
                                finalForm.write(l)
                                rowplus = 1
                            else:
                                print "deletion complete: Creativity"
                        cap = 1
                        finalForm.close()
                        pass
                if nextCellOver == "Arts":
                    print "got to if"
                    with open('templates/form.html', 'r') as myForm:
                        lines = myForm.readlines()
                        myForm.close()
                    with open('templates/form.html', 'w') as finalForm:
                        for l in lines:
                            if "<option value = 'Arts'>Arts</option>" not in l:
                                finalForm.write(l)
                                rowplus = 1
                            else:
                                print "deletion complete: Arts"
                        finalForm.close()
                        pass
                if nextCellOver == "Relaxation":
                    print "got to if"
                    with open('templates/form.html', 'r') as myForm:
                        lines = myForm.readlines()
                        myForm.close()
                    with open('templates/form.html', 'w') as finalForm:
                        for l in lines:
                            if "<option value = 'Relaxation'>Relaxation</option>" not in l:
                                finalForm.write(l)
                                rowplus = 1
                            else:
                                print "deletion complete: Relaxation"
                        cap = 1
                        finalForm.close()
                        pass
                if nextCellOver == "Mad fun":
                    print "got to if"
                    with open('templates/form.html', 'r') as myForm:
                        lines = myForm.readlines()
                        myForm.close()
                    with open('templates/form.html', 'w') as finalForm:
                        for l in lines:
                            if "<option value = 'Mad Fun'>Mad Fun</option>" not in l:
                                finalForm.write(l)
                                rowplus = 1
                            else:
                                print "deletion complete: Mad Fun"
                        cap = 1
                        finalForm.close()
                        pass

我的电子表格基本上如下所示: Spreadsheet             `

以红色突出显示的数字在达到400时应停止计数。

0 个答案:

没有答案