Python Excel操作模块XlsxWriter之插入按钮 worksheet.insert_button()
2018-02-10 15:19
1626 查看
worksheet.insert_button()
insert_button(row, col[, options])向工作表插入一个VBA按钮控件。
参数:
row(int) - 单元格所在的行(索引从0开始计数)。
col(int) - 单元格所在的列(索引从0开始计数)。
options(dict) - 可选的按钮位置,缩放参数。
insert_button()方法可以用于向工作表插入Excel表单按钮。
这个方法通常仅在与工作簿add_vab_project()方法一起使用时才有用,以便将该按钮与嵌入VBA项目中的宏关联起来:# 添加二进制VBA项目。
workbook.add_vba_project('./vbaProject.bin')
# 在VBA项目中添加按钮并与宏关联起来。
worksheet.insert_button('B3',{'macro': 'say_hello',
'caption': 'Press Me'})
insert_button()方法接收字典形式的可选参数来定位和缩放按钮。可用的参数和它们的默认值有:{
'macro': None,
'caption': 'Button 1',
'width': 64,
'height': 20.
'x_offset': 0,
'y_offset': 0,
'x_scale': 1,
'y_scale': 1,
}marco选项是用于设置当用户点击时调用的宏。宏应当通过上面演示的工作簿的add_vba_project()方法来添加。
caption用于设置按钮的说明。默认是值是Button n,n代表按钮的数量。
默认的按钮width是64像素,height是20像素,也就是单元格的默认宽度和高度。
offset和scale选项和insert_chart()的一样。
相关文章推荐
- Python Excel操作模块XlsxWriter之添加图表 worksheet.insert_chart()
- Python Excel操作模块XlsxWriter之添加文本框 worksheet.insert_textbox()
- Python Excel操作模块XlsxWriter之写入数组公式worksheet.write_array_formula()
- Python Excel操作模块XlsxWriter之写入空格worksheet.write_blank()
- Python Excel操作模块XlsxWriter之写入worksheet.write()
- Python Excel操作模块XlsxWriter之写入行worksheet.write_row()
- Python Excel操作模块XlsxWriter之写入字符串worksheet.write_string()
- Python Excel操作模块XlsxWriter之写入日期worksheet.write_datetime()
- Python Excel操作模块XlsxWriter之写入布尔值worksheet.write_boolean()
- Python Excel操作模块XlsxWriter之写入数字worksheet.write_number()
- Python自动化运维笔记(七):XlsxWriter模块实现Excel操作(上)
- Python Excel操作模块XlsxWriter之 The Worksheet Class 工作表类
- Python3.x 操作Excel(写)——XlsxWriter 模块
- python笔记系列:数据报表之Excel操作模块:XlsxWriter
- Python操作Excel文件中多WorkSheet模拟数据库内连接查询
- 【Python】 更棒的Excel操作模块xlwings
- python操作excel的包(openpyxl、xlsxwriter)
- python使用xlwt和xlrd模块操作excel
- Python使用xlrd模块操作Excel数据导入的方法
- Python--操作excel之xlsxwriter