中国建设银行对公网站网页在线生成app
news/
2025/9/24 2:16:12/
文章来源:
中国建设银行对公网站,网页在线生成app,京东网的公司全称是,东莞营销网站建设多少钱1、表格插入
方法一#xff1a;直接创建表添加
#导入库
from docx import Document
#创建文档对象
document Document()#创建5行7列表格
table document.add_table(rows5, cols7)#修改第2行第3列单元格的内容为中国
table.cell(1,2).text中国
#修改第3行第4列单元格的内容…1、表格插入
方法一直接创建表添加
#导入库
from docx import Document
#创建文档对象
document Document()#创建5行7列表格
table document.add_table(rows5, cols7)#修改第2行第3列单元格的内容为中国
table.cell(1,2).text中国
#修改第3行第4列单元格的内容为人民
table.rows[2].cells[3].text人民#在表格底部新增一行
row_cells table.add_row().cells
#新增行的第二列添加内容
row_cells[1].text 加油#保存文档
document.save(D:/demo.docx)方法二以dataframe形式添加
dataframe pd.DataFrame({企业: [round(random.random(), 2) for _ in range(3)],数量: [round(random.random(), 2) for _ in range(3)],金额: [round(random.random(), 2) for _ in range(3)]})
document Document()# 2. 插入表格
table convert_df_to_table(document, dataframe, column_listdataframe.columns.tolist())
table set_table_singleBoard(table) # 表格添加边框
base_paragraphs document.add_paragraph(下面插入表格)
base_paragraphs._p.addnext(table._tbl)2、将表格插入到文档指定段落后面
doc docx.Document(模板docx路径)
dataframe pd.DataFrame({企业: [round(random.random(), 2) for _ in range(3)],数量: [round(random.random(), 2) for _ in range(3)],金额: [round(random.random(), 2) for _ in range(3)]})
# 创建临时doc
doc1 docx.Document()
# 生成table
table convert_df_to_table(doc1, dataframe, column_listdataframe.columns.tolist())
table set_table_singleBoard(table) # 表格添加边框
# 选择模板指定段落
base_paragraphs doc.paragraphs[6]
# 将table插入到制定段落后面
base_paragraphs._p.addnext(table._tbl)
# 保存文件
doc.save(r.\test1.docx)
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/914576.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!