翻譯|使用教程|編輯:李顯亮|2021-04-15 10:24:23.567|閱讀 618 次
概述:在處理電子表格時(shí),可能經(jīng)常需要在工作表中插入或刪除行和列。因此,本文將介紹如何以編程方式處理工作表中的行和列。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷(xiāo)售中 >>
相關(guān)鏈接:
在處理電子表格時(shí),可能經(jīng)常需要在工作表中插入或刪除行和列。因此,本文將介紹如何以編程方式處理工作表中的行和列。特別是,將學(xué)習(xí)如何使用Python在Excel工作表中插入或刪除單行或多行和多列。
為了在Excel工作表中插入或刪除行和列,我們將Aspose.Cells for Python via Java它是一個(gè)功能強(qiáng)大的電子表格處理API,可為Excel自動(dòng)化提供多種功能。你可以點(diǎn)擊下方按鈕獲取使用。
點(diǎn)擊下載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的全部完整功能,可聯(lián)系在線(xiàn)客服獲取30天臨時(shí)授權(quán)體驗(yàn)。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn