import json def rgb(h): h=h.lstrip('#'); return {"red":int(h[0:2],16)/255,"green":int(h[2:4],16)/255,"blue":int(h[4:6],16)/255} def gr(s,r0,r1,c0,c1): d={"sheetId":s,"startColumnIndex":c0,"endColumnIndex":c1,"startRowIndex":r0} if r1 is not None: d["endRowIndex"]=r1 return d R=[] def hdr(s,r0,r1,c1): R.append({"repeatCell":{"range":gr(s,r0,r1,0,c1),"cell":{"userEnteredFormat":{"backgroundColorStyle":{"rgbColor":rgb("#333333")},"textFormat":{"bold":True,"foregroundColorStyle":{"rgbColor":rgb("#FFFFFF")}},"wrapStrategy":"WRAP","verticalAlignment":"MIDDLE","horizontalAlignment":"CENTER"}},"fields":"userEnteredFormat.backgroundColorStyle,userEnteredFormat.textFormat,userEnteredFormat.wrapStrategy,userEnteredFormat.verticalAlignment,userEnteredFormat.horizontalAlignment"}}) def numfmt(s,r0,c0,c1,typ,pat): R.append({"repeatCell":{"range":gr(s,r0,None,c0,c1),"cell":{"userEnteredFormat":{"numberFormat":{"type":typ,"pattern":pat}}},"fields":"userEnteredFormat.numberFormat"}}) def width(s,c0,c1,px): R.append({"updateDimensionProperties":{"range":{"sheetId":s,"dimension":"COLUMNS","startIndex":c0,"endIndex":c1},"properties":{"pixelSize":px},"fields":"pixelSize"}}) def freeze(s,r,c): R.append({"updateSheetProperties":{"properties":{"sheetId":s,"gridProperties":{"frozenRowCount":r,"frozenColumnCount":c}},"fields":"gridProperties.frozenRowCount,gridProperties.frozenColumnCount"}}) def wrap(s,r0,c0,c1): R.append({"repeatCell":{"range":gr(s,r0,None,c0,c1),"cell":{"userEnteredFormat":{"wrapStrategy":"WRAP","verticalAlignment":"TOP"}},"fields":"userEnteredFormat.wrapStrategy,userEnteredFormat.verticalAlignment"}}) # 読み方 R.append({"repeatCell":{"range":gr(0,0,1,0,1),"cell":{"userEnteredFormat":{"textFormat":{"bold":True,"fontSize":14}}},"fields":"userEnteredFormat.textFormat"}}) for r in (2,8,14): R.append({"repeatCell":{"range":gr(0,r,r+1,0,2),"cell":{"userEnteredFormat":{"textFormat":{"bold":True},"backgroundColorStyle":{"rgbColor":rgb("#EEEEEE")}}},"fields":"userEnteredFormat.textFormat,userEnteredFormat.backgroundColorStyle"}}) width(0,0,1,170); width(0,1,2,760); wrap(0,0,1,2) # 週ごと hdr(1,0,1,19); freeze(1,1,1); R.append({"updateDimensionProperties":{"range":{"sheetId":1,"dimension":"ROWS","startIndex":0,"endIndex":1},"properties":{"pixelSize":54},"fields":"pixelSize"}}) numfmt(1,1,0,1,"DATE","yyyy-mm-dd"); numfmt(1,1,3,4,"PERCENT","0.0%"); numfmt(1,1,5,6,"PERCENT","0%"); numfmt(1,1,17,18,"PERCENT","0.0%") width(1,0,1,110); width(1,1,18,96); width(1,18,19,380) R.append({"addChart":{"chart":{"spec":{"title":"人の表示と AI の依頼読み(週ごと)","basicChart":{"chartType":"LINE","legendPosition":"BOTTOM_LEGEND","headerCount":1, "domains":[{"domain":{"sourceRange":{"sources":[gr(1,0,60,0,1)]}}}], "series":[{"series":{"sourceRange":{"sources":[gr(1,0,60,1,2)]}},"targetAxis":"LEFT_AXIS"},{"series":{"sourceRange":{"sources":[gr(1,0,60,8,9)]}},"targetAxis":"LEFT_AXIS"}]}}, "position":{"overlayPosition":{"anchorCell":{"sheetId":1,"rowIndex":8,"columnIndex":1},"widthPixels":720,"heightPixels":340}}}}}) # 日ごと hdr(2,0,1,10); freeze(2,1,1); numfmt(2,1,0,1,"DATE","yyyy-mm-dd"); width(2,0,1,110); width(2,1,9,110); width(2,9,10,420) R.append({"updateDimensionProperties":{"range":{"sheetId":2,"dimension":"ROWS","startIndex":0,"endIndex":1},"properties":{"pixelSize":54},"fields":"pixelSize"}}) # ガイドSEO hdr(3,0,2,32); freeze(3,2,1) for c0 in (8,14,20,26): R.append({"mergeCells":{"range":gr(3,0,1,c0,c0+6),"mergeType":"MERGE_ALL"}}) for c in range(8): R.append({"mergeCells":{"range":gr(3,0,2,c,c+1),"mergeType":"MERGE_ALL"}}) numfmt(3,2,3,4,"DATE","yyyy-mm-dd"); numfmt(3,2,7,8,"DATE","yyyy-mm-dd"); numfmt(3,2,8,14,"NUMBER","0.0"); numfmt(3,2,26,32,"PERCENT","0.0%") width(3,0,1,190); width(3,1,2,260); width(3,2,3,300); width(3,3,5,96); width(3,5,6,300); width(3,6,8,110); width(3,8,32,78) wrap(3,2,0,8) R.append({"setDataValidation":{"range":gr(3,2,100,4,5),"rule":{"condition":{"type":"ONE_OF_LIST","values":[{"userEnteredValue":v} for v in ["未確認","登録済み","登録依頼中","未登録"]]},"showCustomUi":True,"strict":False}}}) # キーワード hdr(4,0,1,7); freeze(4,1,1); numfmt(4,1,5,6,"DATE","yyyy-mm-dd") width(4,0,1,230); width(4,1,4,100); width(4,4,5,320); width(4,5,6,100); width(4,6,7,380) R.append({"setBasicFilter":{"filter":{"range":gr(4,0,300,0,7)}}}) print(json.dumps(R,ensure_ascii=False))