IronXL for Python 提供程式化插入單個或多個行和列的能力,無需使用 Office Interop。
插入行
InsertRow 和 InsertRows 方法會添加新行到工作表。 行會插入到指定索引位置之前。
插入列
使用 InsertColumn 和 InsertColumns 方法在指定的索引位置之前添加一個或多個欄。
所有索引位置均使用從零開始的索引。
學習如何使用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")IronXL for Python 提供程式化插入單個或多個行和列的能力,無需使用 Office Interop。
InsertRow 和 InsertRows 方法會添加新行到工作表。 行會插入到指定索引位置之前。
使用 InsertColumn 和 InsertColumns 方法在指定的索引位置之前添加一個或多個欄。
所有索引位置均使用從零開始的索引。
學習如何使用Python在Excel中添加行和列