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 方法會添加新行到工作表。 行會插入到指定索引位置之前。

插入列

使用 InsertColumn 和 InsertColumns 方法在指定的索引位置之前添加一個或多個欄。

所有索引位置均使用從零開始的索引。

學習如何使用Python在Excel中添加行和列

準備好開始了嗎?

版本:2026.11剛剛發布