翻譯|使用教程|編輯:李顯亮|2021-04-15 10:24:23.567|閱讀 618 次
概述:在處理電子表格時,可能經常需要在工作表中插入或刪除行和列。因此,本文將介紹如何以編程方式處理工作表中的行和列。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
在處理電子表格時,可能經常需要在工作表中插入或刪除行和列。因此,本文將介紹如何以編程方式處理工作表中的行和列。特別是,將學習如何使用Python在Excel工作表中插入或刪除單行或多行和多列。
為了在Excel工作表中插入或刪除行和列,我們將Aspose.Cells for Python via Java它是一個功能強大的電子表格處理API,可為Excel自動化提供多種功能。你可以點擊下方按鈕獲取使用。
點擊下載Aspose.Cells for Python via Java
以下是使用Python在Excel工作表中插入行的步驟。
下面的代碼示例演示如何使用Python在Excel工作表中插入行。
# Instantiate a Workbook object by excel file path workbook = self.Workbook("Book1.xls") # Access the first worksheet in the Excel file worksheet = workbook.getWorksheets().get(0) # Insert a row into the worksheet at 3rd position worksheet.getCells().insertRows(2,1) # Save the modified Excel file in default (that is Excel 2003) format workbook.save("Insert Row.xls") print "Insert Row Successfully."
以下是使用Python在Excel工作表中插入列的步驟。
下面的代碼示例演示如何使用Python在Excel工作表中插入列。
# Instantiate a Workbook object by excel file path workbook = self.Workbook('Book1.xls') # Access the first worksheet in the Excel file worksheet = workbook.getWorksheets().get(0) # Insert a column into the worksheet at 2nd position worksheet.getCells().insertColumns(1,1) # Save the modified Excel file in default (that is Excel 2003) format workbook.save("Insert Column.xls") print "Insert Column Successfully."
以下是使用Python從Excel工作表中刪除行的步驟。
以下代碼示例顯示了如何從Python中的Excel工作表中刪除行。
# Instantiate a Workbook object by excel file path workbook = self.Workbook("Book1.xls") # Access the first worksheet in the Excel file worksheet = workbook.getWorksheets().get(0) # Delete 10 rows from the worksheet starting from 3rd row worksheet.getCells().deleteRows(2,10,True) # Save the modified Excel file in default (that is Excel 2003) format workbook.save("Insert Row.xls") print "Insert Row Successfully."
以下是使用Python從Excel工作表中刪除列的步驟。
下面的代碼示例演示如何使用Python從Excel工作表中刪除列。
# Instantiate a Workbook object by excel file path workbook = self.Workbook('Book1.xls') # Access the first worksheet in the Excel file worksheet = workbook.getWorksheets().get(0) # Delete a column from the worksheet at 2nd position worksheet.getCells().deleteColumns(1,1,True) # Save the modified Excel file in default (that is Excel 2003) format workbook.save("Insert Column.xls") print "Insert Column Successfully."
如果你想試用Aspose的全部完整功能,可聯系在線客服獲取30天臨時授權體驗。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn