using 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
using Python 在 Excel 中插入列與行

using Python 在 Excel 中插入列與行

IronXL for Python 提供程式方式插入個別或多個列和欄的能力,無需使用 Office Interop。

插入列

InsertRow 和 InsertRows 方法會將新列新增到工作表中。 列會插入在指定索引位置的之前。

插入欄

using InsertColumn 和 InsertColumns 方法在指定索引位置之前新增一個或多個欄。

所有索引位置都是以零為基數的索引。

學習如何在 Excel 中使用 Python 新增列和欄

準備好開始了嗎?

版本:2026.10剛剛發布