翻譯|使用教程|編輯:李顯亮|2021-07-09 15:40:32.177|閱讀 252 次
概述:為了以編程方式執(zhí)行上述任務(wù),本文展示了 如何使用 Java 在 Excel 工作簿中復(fù)制工作表。此外,它還介紹了如何在 Excel 工作簿中移動(dòng)工作表。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
經(jīng)常需要將 Excel 工作簿中的工作表或從一個(gè)工作簿復(fù)制到另一個(gè)工作簿。此外,在某些情況下還需要更改工作表的位置。為了以編程方式執(zhí)行上述任務(wù),本文展示了 如何使用 Java 在 Excel 工作簿中復(fù)制工作表。此外,它還介紹了如何在 Excel 工作簿中移動(dòng)工作表。文檔管理開(kāi)發(fā)Aspose都可以解決。
為了復(fù)制或移動(dòng) Excel 文件中的工作表,我們將使用Aspose.Cells for Java,它是一個(gè)功能豐富的 API,可讓您輕松創(chuàng)建或修改電子表格文檔。點(diǎn)擊下方按鈕可下載試用。
以下是使用 Java 在 Excel 工作簿中復(fù)制工作表的步驟。
以下代碼示例演示如何復(fù)制或克隆 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");
還可以將工作表從一個(gè) Excel 工作簿復(fù)制到另一個(gè)。以下是在一個(gè)工作簿中復(fù)制工作表并將其添加到另一個(gè)工作簿的步驟。
以下代碼示例展示了如何在 Java 中將工作表從一個(gè) Excel 工作簿克隆到另一個(gè) 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 中將工作表從一個(gè)位置移動(dòng)到另一個(gè)位置的步驟。
以下代碼示例展示了如何在 Java 中將工作表從一個(gè)位置移動(dòng)到另一個(gè)位置。
// 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的全部完整功能,可聯(liá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