翻譯|使用教程|編輯:胡濤|2023-05-10 11:20:50.203|閱讀 149 次
概述:本文將向大家展示如何實現Excel的另一個功能,即插入和刪除行和列,歡迎查閱~
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Aspose.Cells 是Excel電子表格編程API,可加快電子表格的管理和處理任務,支持構建能夠生成,修改,轉換,呈現和打印電子表格的跨平臺應用程序。同時不依賴于Microsoft Excel或任何Microsoft Office Interop組件,
Aspose API 支持旗下產品覆蓋文檔、圖表、PDF、條碼、OCR、CAD、HTML、電子郵件等各個文檔管理領域,為全球.NET 、Java、C ++等10余種平臺開發人員提供豐富的開發選擇。
作為一名程序員,您可能會遇到必須處理 Excel 電子表格的場景。此外,您可能需要生成并填充 Excel 文件,我已在本文中介紹過這些文件。今天,我將向大家展示如何實現Excel的另一個功能,即插入和刪除行和列。當您必須動態添加/刪除 Excel 行/列時,這可能很有用。那么讓我們看看如何在 Java 中插入或刪除 Excel 工作表中的行和列。
Aspose.Cells for Java是一個流行的電子表格操作庫,它提供了一組驚人的功能來生成和操作 Excel 文件。我們將使用此庫來操作 Excel 工作表的行和列。您可以下載其 JAR 或使用以下 Maven 配置安裝它。
<repository> <id>AsposeJavaAPI</id> <name>Aspose Java API</name> <url>//repository.aspose.com/repo/</url> </repository> <dependency> <groupId>com.aspose</groupId> <artifactId>aspose-cells</artifactId> <version>22.10</version> </dependency>
以下是使用 Java 在 Excel 工作表中插入行的步驟。
以下代碼示例顯示了如何在 Java 中的 Excel 工作表中插入行。
// Load Excel file Workbook workbook = new Workbook("Book1.xls"); // Access the first worksheet in the Excel file Worksheet 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 format workbook.save("Insert Rows.xls");
將列添加到 Excel 工作表的過程類似于添加行。以下是在 Java 工作表中插入列的步驟。
以下代碼示例顯示了如何在 Java 中的 Excel 工作表中插入列。
// Load Excel file Workbook workbook = new Workbook("Book1.xls"); // Access the first worksheet in the Excel file Worksheet 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 format workbook.save("Insert Column.xls");
現在讓我們看看如何使用 Java 刪除 Excel 工作表中的行和列。首先,我們將討論行的刪除。
以下是使用 Java 從 Excel 工作表中刪除行的步驟。
以下代碼示例顯示了如何使用 Java 從 Excel 工作表中刪除行。
// Load Excel file Workbook workbook = new Workbook("Book1.xls"); // Access the first worksheet in the Excel file Worksheet 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 format workbook.save("Delete Rows.xls");
以下是使用 Java 從 Excel 工作表中刪除列的步驟。
以下代碼示例顯示如何使用 Java 從 Excel 工作表中刪除列。
// Load Excel file Workbook workbook = new Workbook("Book1.xls"); // Access the first worksheet in the Excel file Worksheet 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 format workbook.save("Delete Columns.xls");
以上便是如何在Java 在 Excel 中插入和刪除行和列,如果您還有其他問題,歡迎咨詢 我們,或者加入我們的技術交流群獲取幫助
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn