在 Python 中向 Excel 插入行和列
IronXL for Python提供了以编程方式插入单个或多个行和列的能力,无需Office Interop。
插入行
InsertRow 和 InsertRows 方法向工作表添加新行。 行插入在指定的索引位置之前。
插入列
使用InsertColumn 和 InsertColumns 方法在指定的索引位置之前添加一个或多个列。
所有索引位置均使用从零开始的索引。
from ironxl import *
# Load existing spreadsheet
workbook = WorkBook.Load("sample.xlsx")
worksheet = workbook.DefaultWorkSheet
# Add a row before row 1
worksheet.InsertRow(0)
# Insert multiple rows before row 4
worksheet.InsertRows(3, 3)
# Add a column before column A
worksheet.InsertColumn(0)
# Insert multiple columns before column F
worksheet.InsertColumns(5, 2)
# Save changes with added rows and columns
workbook.SaveAs("addRowAndColumn.xlsx")IronXL for Python提供了以编程方式插入单个或多个行和列的能力,无需Office Interop。
InsertRow 和 InsertRows 方法向工作表添加新行。 行插入在指定的索引位置之前。
使用InsertColumn 和 InsertColumns 方法在指定的索引位置之前添加一个或多个列。
所有索引位置均使用从零开始的索引。