xlsxwriter:如何插入新行 [英] xlsxwriter: How to insert a new row

查看:109
本文介绍了xlsxwriter:如何插入新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 xlsxwriter,如何在 Excel 工作表中插入新行?例如,在 Excel 工作表的单元格区域 A1:G10 处有一个现有数据表,我想插入一行 (A:A) 为报告标题留出一些空间.

Using xlsxwriter, how do I insert a new row to an Excel worksheet? For instance, there is an existing data table at the cell range A1:G10 of the Excel worksheet, and I want to insert a row (A:A) to give it some space for the title of the report.

我浏览了此处的文档 http://xlsxwriter.readthedocs.io/worksheet.html,但是找不到这样的方法.

I looked through the documentation here http://xlsxwriter.readthedocs.io/worksheet.html, but couldn't find such method.

import xlsxwriter

# Create a workbook and add a worksheet.
workbook = xlsxwriter.Workbook('Expenses01.xlsx')
worksheet = workbook.add_worksheet()
worksheet.insert_row(1)  # This method doesn't exist

推荐答案

通过使用 openpyxl 你可以插入 iew 行和列

By using openpyxl you can insert iew rows and columns

import openpyxl

file = "xyz.xlsx"
#loading XL sheet bassed on file name provided by user
book = openpyxl.load_workbook(file)
#opening sheet whose index no is 0
sheet = book.worksheets[0]

#insert_rows(idx, amount=1) Insert row or rows before row==idx, amount will be no of 
#rows you want to add and it's optional
sheet.insert_rows(13)

希望能帮到你

这篇关于xlsxwriter:如何插入新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆