Python Excel操作模块XlsxWriter之添加文本框 worksheet.insert_textbox()
worksheet.insert_textbox()
insert_textbox(row, col, textbox[, options])
向工作表单元格添加文本框。
参数:
- row(int) - 单元格所在的行(索引从0开始计数)。
- col(int) - 单元格所在的列(索引从0开始计数)。
- text(string) - 文本框里的文本。
- options(dict) - 可选的文本框位置,缩放参数。
这个方法用于向工作表插入文本框:
worksheet.insert_textbox('B2', 'A simple textbox with some text')
文本框的大小和格式可以通过options字典操控:
# 大小和位置
width
height
x_scale
y_scale
x_offset
y_offset# 格式
line
border
fill
gradient
font
align
注意
由于字体大于默认字体大小或打开了文本换行,则文本框的缩放可能会受到影响,因为它的默认高度已更改。如果它与插入的图表交叉,你应该使用set_row()显式的设置行高来避免此问题。
例:向工作表插入文本框
下面是一个如何向工作表插入和格式化文本框的例子。
#######################################################################
#
# An example of inserting textboxes into an Excel worksheet using
# Python and XlsxWriter.
#
# Copyright 2013-2017, John McNamara, jmcnamara@cpan.org
#
import xlsxwriterworkbook = xlsxwriter.Workbook('textbox.xlsx')
worksheet = workbook.add_worksheet()
row = 4
col = 1# 下面的例子展示了不同的文本框选项和格式。 # 例子
text = 'A simple textbox with some text'
worksheet.insert_textbox(row, col, text)
row += 10# 例子
text = 'A textbox with changed dimensions'
options = {'width': 256,'height': 100,
}
worksheet.insert_textbox(row, col, text, options)
row += 10# 例子
text = 'A textbox with an offset in the cell'
options = {'x_offset': 10,'y_offset': 10,
}
worksheet.insert_textbox(row, col, text, options)
row += 10# 例子
text = 'A textbox with scaling'
options = {'x_scale': 1.5,'y_scale': 0.8,
}
worksheet.insert_textbox(row, col, text, options)
row += 10# 例子
text = 'A textbox with some long text that wraps around onto several lines'
worksheet.insert_textbox(row, col, text)
row += 10# 例子
text = 'A textbox\nwith some\nnewlines\n\nand paragraphs'
worksheet.insert_textbox(row, col, text)
row += 10# Example
text = 'A textbox with a solid fill background'
options = {'fill': {'color': 'red'},
}
worksheet.insert_textbox(row, col, text, options)
row += 10# 例子
text = 'A textbox with a no fill background'
options = {'fill': {'none': True},
}
worksheet.insert_textbox(row, col, text, options)
row += 10# 例子
text = 'A textbox with a gradient fill background'
options = {'gradient': {'colors': ['#DDEBCF','#9CB86E','#156B13']},
}
worksheet.insert_textbox(row, col, text, options)
row += 10# 例子
text = 'A textbox with a user defined border line'
options = {'border': {'color': 'red','width': 3,'dash_type': 'round_dot'},
}
worksheet.insert_textbox(row, col, text, options)
row += 10# 例子
text = 'A textbox with no border line'
options = {'border': {'none': True},
}
worksheet.insert_textbox(row, col, text, options)
row += 10# 例子
text = 'Default alignment: top - left'
worksheet.insert_textbox(row, col, text)
row += 10# 例子
text = 'Alignment: top - center'
options = {'align': {'horizontal': 'center'},
}
worksheet.insert_textbox(row, col, text)
row += 10# 例子
text = 'Alignment: top - center'
options = {'align': {'horizontal': 'center'},
}
worksheet.insert_textbox(row, col, text, options)
row += 10# 例子
text = 'Alignment: middle - center'
options = {'align': {'vertical': 'middle','horizontal': 'center'},
}
worksheet.insert_textbox(row, col, text, options)
row += 10# 例子
text = 'Font properties: bold'
options = {'font': {'bold': True},
}
worksheet.insert_textbox(row, col, text, options)
row += 10# 例子
text = 'Font properties: various'
options = {'font': {'bold': True},
}
worksheet.insert_textbox(row, col, text, options)
row += 10# 例子
text = 'Font properties: various'
options = {'font': {'bold': True,'italic': True,'underline': True,'name': 'Arial','color': 'red','size': 12}
}
worksheet.insert_textbox(row, col, text, options)
row += 10# 例子
text = 'Some text in a textbox with formatting'
options = {'font': {'color': 'white'},'align': {'vertical': 'middle','horizontal': 'center'},'gradient': {'colors': ['red', 'blue']},
}
worksheet.insert_textbox(row, col, text, options)
row += 10workbook.close()
Python Excel操作模块XlsxWriter之添加文本框 worksheet.insert_textbox()相关推荐
- Python Excel操作模块XlsxWriter之写入数组公式worksheet.write_array_formula()
worksheet.write_array_formula() write_array_formula(first_row, first_col, last_row, last_col, formul ...
- Python Excel操作模块XlsxWriter之写入worksheet.write()
worksheet.write() wirte(row, col, *args) 向工作表单元格写入普通的数据. 参数: row - 单元格所在的行(索引从0开始计数) col - 单元格所在的列(索 ...
- Python Excel操作模块XlsxWriter之插入图片worksheet.insert_image
worksheet.insert_image() insert_image(row, col, image[, options]) 在工作表单元格中插入一张图片. 参数: row(int) - 单元格 ...
- 3.1 数据报表之Excel操作模块 XlsxWriter
Excel是当前最流行的电子表格处理软件,支持丰富的计算函数及图表,在系统运营方面广泛用于运营数据报表,比如业务质量,资源利用,安全扫描等报表,同时也是应用系统常见的文件导出格式,以便数据使用人员做进 ...
- python在excel中写入公式_Python Excel操作模块XlsxWriter之写入公式write_formula()
worksheet.write_formula() write_formula(row, col, formula[, cell_formula[, value]]) 向工作表单元格写入公式. 参数: ...
- python添加excel模块,Python Excel操作——xlrd、xlwd,,读取1、导入模块 i
Python Excel操作--xlrd.xlwd,,读取1.导入模块 i 读取 1.导入模块 import xlrd 2.打开Excel文件读取数据 data = xlrd.open_workboo ...
- python数据分析报告的格式_Python数据报表之Excel操作模块用法分析
本文实例讲述了Python数据报表之Excel操作模块用法.分享给大家供大家参考,具体如下: 一 点睛 Excel是当今最流行的电子表格处理软件,支持丰富的计算函数及图表,在系统运营方面广泛用于运营数 ...
- Fintech系列(三) -- python对excel操作模块汇总||推荐指数||用法示例
python对excel操作模块汇总||推荐指数||用法示例 Working with Excel Files in Python 总览 读写Excel的python第三方开源模块 Excel写操作插 ...
- python处理excel表格实例-通过实例学习Python Excel操作
这篇文章主要介绍了通过实例学习Python Excel操作,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 1.python 读取Excel # -* ...
最新文章
- linux系统下top命令的详细用法、参数详解、以及模式配置
- python pandas 行数_Python Pandas:增加最大行数
- 每日一题(33)——用两个栈实现一个队列的功能?要求给出算法和思路
- 徐海学院计算机专业好吗,2019中国矿业大学徐海学院专业排名
- Nginx之location详解
- 对项目的总结以及对这种教学方式的看法
- python获取图片大小_Python实现获取本地及远程图片大小的方法示例_python_脚本中心...
- 车牌识别sdk android,Android车牌识别sdk
- 克拉默法则(Cramer's Rule)的证明
- 多张图片怎么合成一个pdf?
- stm32霍尔编码器电机测速原理
- 12306UserScript
- 计算机专业技术职务评审表怎么填,专业技术职务怎么填
- MAC使用Charles,代理后,部分网页无法打开解决方法
- android开发之Android 5.0 Lollipop新特性介绍
- The Preliminary Contest for ICPC Asia Xuzhou 2019
- 不会查看GIT版本历史?快收藏这个工具
- 成功中标 荣联为中国检科院打造一站式生信服务平台
- Windows6.1-KB2661332-x64 远程桌面服务当前正忙,因此无法完成您尝试执行的任务
- 【转】视频分割器的工作原理及异常解决
热门文章
- 计算机专业双一流排名大专,计算机专业双一流高校名单-双一流大学计算机专业排名...
- ,实则非常坚硬。岩石表面像被精心打磨
- 「天猫代运营」精准标签玩法,引爆新品手淘搜索流量
- latex假装插入参考文献(不用bibtex)
- web后端实现验证码思路
- 智能控制方法与应用大作业
- jedispool(Jedispool支持 自动重连)
- fallguy服务器维护,糖豆人fallguys
- 怎么将PDF水印删除掉
- Effective C++(编写new和delete时需固守常规)