Python: how to check a checkbox in excel?
1 answer
You cannot do this with xlsxwriter
. The only way to check a checkbox in Excel is win32com
.
Try it:
import win32com.client as win32
import os
excel = win32.gencache.EnsureDispatch('Excel.Application')
path = os.getcwd()
try:
path = path + "\\Book1.xlsx";
wb = excel.Workbooks.Open(path)
ws = wb.Worksheets("aaaa")
row = 5
column = 7
cb = ws.CheckBoxes().Add(Left=ws.Cells(row, column).Left,Top=ws.Cells(row, column).Top,Width=ws.Cells(row, column).Width,Height=ws.Cells(row, column).Height)
wb.Save()
excel.Application.Quit()
except Exception as e:
print(e)
0
source to share