翻譯|使用教程|編輯:李顯亮|2021-07-09 15:40:32.177|閱讀 252 次
概述:為了以編程方式執行上述任務,本文展示了 如何使用 Java 在 Excel 工作簿中復制工作表。此外,它還介紹了如何在 Excel 工作簿中移動工作表。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
經常需要將 Excel 工作簿中的工作表或從一個工作簿復制到另一個工作簿。此外,在某些情況下還需要更改工作表的位置。為了以編程方式執行上述任務,本文展示了 如何使用 Java 在 Excel 工作簿中復制工作表。此外,它還介紹了如何在 Excel 工作簿中移動工作表。文檔管理開發Aspose都可以解決。
為了復制或移動 Excel 文件中的工作表,我們將使用Aspose.Cells for Java,它是一個功能豐富的 API,可讓您輕松創建或修改電子表格文檔。點擊下方按鈕可下載試用。
以下是使用 Java 在 Excel 工作簿中復制工作表的步驟。
以下代碼示例演示如何復制或克隆 Excel 工作簿中的工作表。
// Load the Excel file using its path Workbook wb = new Workbook("book1.xls"); // Access the worksheets in the workbook WorksheetCollection sheets = wb.getWorksheets(); // Create a copy of the worksheet sheets.addCopy("Sheet1"); // Save the updated Excel file wb.save("updated.xls");
還可以將工作表從一個 Excel 工作簿復制到另一個。以下是在一個工作簿中復制工作表并將其添加到另一個工作簿的步驟。
以下代碼示例展示了如何在 Java 中將工作表從一個 Excel 工作簿克隆到另一個 Excel 工作簿。
// Load the source Excel workbook Workbook source = new Workbook("source.xls"); // Load the destination Excel workbook Workbook destination = new Workbook("destination.xls"); // Copy the first sheet of the source workbook into second workbook destination.getWorksheets().get(0).copy(source.getWorksheets().get(0)); // Save the file. destination.save("updated.xls", FileFormatType.EXCEL_97_TO_2003);
以下是在 Java 中將工作表從一個位置移動到另一個位置的步驟。
以下代碼示例展示了如何在 Java 中將工作表從一個位置移動到另一個位置。
// Load the Excel file Workbook wb = new Workbook("workbook.xls"); // Get the first worksheet in the workbook Worksheet sheet = wb.getWorksheets().get(0); // Move the first sheet to the third position in the workbook sheet.moveTo(2); // Save the updated Excel file wb.save("updated.xls");
如果你想試用Aspose的全部完整功能,可聯系在線客服獲取30天臨時授權體驗。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn