IRONSOFTWAREHOME
在 Python 中向 Excel 插入行和列
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")
pip install ironxl
在 Python 中向 Excel 插入行和列

在 Python 中向 Excel 插入行和列

IronXL for Python提供了以编程方式插入单个或多个行和列的能力,无需Office Interop。

插入行

InsertRows方法将新行添加到工作表中。 行插入在指定的索引位置之前

插入列

使用InsertColumns方法在指定索引位置前添加一个或多个列。

所有索引位置均使用从零开始的索引。

学习如何在Excel中使用Python添加行和列

准备开始了吗?

版本:2026.9刚刚发布

Key in blue circle

立即获取免费的 30 天试用版密钥

Your trial license will be sent to your email address

无任何限制。100% 解锁。无需信用卡。

bullet_checked无需信用卡或创建账户无任何限制。100% 解锁。无需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
预约您的免费现场演示
Booking Badge

深受全球数百万工程师信赖

Iron Software 的客户徽标
获取您的无义务咨询
填写下面的表格或通过sales@ironsoftware.com
您的资料将始终保密。
深受全球数百万工程师信赖
Iron Software 的客户徽标
立即获取您的免费30 天试用密钥
无需信用卡或创建账户